Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauricio Alferez2015-11-18 19:51:01 +0000
committerGerrit Code Review @ Eclipse.org2015-11-20 10:18:57 +0000
commita80edfdfbea7c97bd9c41bfdd76dc55cde0f7561 (patch)
tree98785cdad2eeb71a9a27163067de531c9d9c5b32 /extraplugins
parent1300c520ff6174e3a135b793f3feaf5d8ab24ac2 (diff)
downloadorg.eclipse.papyrus-a80edfdfbea7c97bd9c41bfdd76dc55cde0f7561.tar.gz
org.eclipse.papyrus-a80edfdfbea7c97bd9c41bfdd76dc55cde0f7561.tar.xz
org.eclipse.papyrus-a80edfdfbea7c97bd9c41bfdd76dc55cde0f7561.zip
[Extra plugins][Req] Improving generator
Change-Id: I9bcdaa07949efebd9b12801ee3a3f50e961ba2ba Signed-off-by: Mauricio Alferez <mauricio.alferez@cea.fr>
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/generator/ProfileGenerator.java74
-rw-r--r--extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/utils/Utils.java97
-rw-r--r--extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceConstants.java8
-rw-r--r--extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceInitializer.java10
-rw-r--r--extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferencePage.java14
5 files changed, 185 insertions, 18 deletions
diff --git a/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/generator/ProfileGenerator.java b/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/generator/ProfileGenerator.java
index 8b7a3dcdaa1..d62176716db 100644
--- a/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/generator/ProfileGenerator.java
+++ b/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/generator/ProfileGenerator.java
@@ -33,6 +33,7 @@ import org.eclipse.papyrus.req.domainModel2Profile.utils.Utils;
import org.eclipse.papyrus.req.sysml.preferences.Activator;
import org.eclipse.papyrus.req.sysml.preferences.PreferenceConstants;
import org.eclipse.uml2.uml.Abstraction;
+import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Association;
//import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Class;
@@ -70,8 +71,9 @@ public class ProfileGenerator {
private static String NSURI_PREFIX = "https://www.eclipse.org/papyrus/";
private static boolean GENERATE_ABSTRACTIONS_MODEL = false;
private static boolean FROM_ASSOCIATIONS_TO_STEREOTYPES = false;
- private static String METACLASS_EXTENDED_BY_NODES = UMLPackage.Literals.CLASS.getName();
- private static String METACLASS_EXTENDED_BY_EDGES = UMLPackage.Literals.ASSOCIATION.getName();
+ private static boolean FROM_ASSOCIATIONS_TO_ASSOCIATIONS = false;
+ private static String METACLASS_EXTENDED_BY_NODES = "none"; //UMLPackage.Literals.CLASS.getName();
+ private static String METACLASS_EXTENDED_BY_EDGES = "none";//= UMLPackage.Literals.ASSOCIATION.getName();
// Debug=true will automatically refresh the project to show the output
// files.
private static boolean DEBUG = true;
@@ -79,20 +81,22 @@ public class ProfileGenerator {
protected Stereotype baseEdgeStereotype;
protected Map<Element, Element> mapClassNodes = new HashMap<Element, Element>();
protected Map<Element, Element> mapAssociationsEdges = new HashMap<Element, Element>();
+ protected Map<Element, Element> mapProfileAssociations2MMAssociations = new HashMap<Element, Element>();
protected Map<Element, Element> mapPrimitiveTypesNodes = new HashMap<Element, Element>();
protected Map<Element, Element> mapEnumerationsNodes = new HashMap<Element, Element>();
protected Map<Element, Element> mapPackagesNodes = new HashMap<Element, Element>();
protected List<PrimitiveType> listStandardPrimitiveTypes = new ArrayList<PrimitiveType>();
protected String outputDirectoryPath;
protected List<Generalization> listInternalGeneralizations = new ArrayList<Generalization>();
+ protected List<Association> listAssociations = new ArrayList<Association>();
protected Model abstractionsModel;
+
/**
* Constructor to be called by Eclipse, takes into account generation
- * preferences
+ * preferences in the Papyrus Req preference page.
*
- * @param selectedPackage
- * uml domain model
+ * @param selectedPackage The UML domain model
*/
public ProfileGenerator(Package selectedPackage) {
DEBUG = false;
@@ -100,6 +104,7 @@ public class ProfileGenerator {
NSURI_PREFIX = store.getString(PreferenceConstants.NSURI_PREFIX);
GENERATE_ABSTRACTIONS_MODEL = store.getBoolean(PreferenceConstants.GENERATE_ABSTRACTIONS_MODEL);
FROM_ASSOCIATIONS_TO_STEREOTYPES = store.getBoolean(PreferenceConstants.FROM_ASSOCIATIONS_TO_STEREOTYPES);
+ FROM_ASSOCIATIONS_TO_ASSOCIATIONS =store.getBoolean(PreferenceConstants.FROM_ASSOCIATIONS_TO_ASSOCIATIONS);
// METACLASS_EXTENDED_BY_NODES =
// store.getString(PreferenceConstants.METACLASS_EXTENDED_BY_NODES);
// //by default "none"
@@ -114,10 +119,12 @@ public class ProfileGenerator {
}
/**
- * Constructor to be used in an standalone Java application, takes into
- * account
+ * Constructor to be used in an standalone Java application. It does not takes
+ * into account preferences in the Papyrus Req preference page.
*
- * @param selectedPackage
+ * @param _inputModelPath The path of the input model
+ * @param _outputDirectoryPath The path to save the profile and if the abstractions model
+ * @param _prefix the NSURI prefix used in the profile
*/
public ProfileGenerator(String _inputModelPath, String _outputDirectoryPath, String _prefix) {
DEBUG = true;
@@ -143,9 +150,11 @@ public class ProfileGenerator {
setProfile(Utils.createProfile(nameOfProfile, NSURI_PREFIX + sourcePackage.getName()));
if (!METACLASS_EXTENDED_BY_NODES.contentEquals("none")) {
+ METACLASS_EXTENDED_BY_NODES= UMLPackage.Literals.CLASS.getName();
baseNodeStereotype = Utils.createStereotype(profile, "baseNodeStereotype", true);
}
if (!METACLASS_EXTENDED_BY_EDGES.contentEquals("none")) {
+ METACLASS_EXTENDED_BY_EDGES= UMLPackage.Literals.ASSOCIATION.getName();
baseEdgeStereotype = Utils.createStereotype(profile, "baseEdgeStereotype", true);
}
@@ -160,6 +169,9 @@ public class ProfileGenerator {
if (FROM_ASSOCIATIONS_TO_STEREOTYPES) {
createProfiles(mapAssociationsEdges);
}
+ if (FROM_ASSOCIATIONS_TO_ASSOCIATIONS) {
+ createAssociations();
+ }
createEnumerationLiterals();
createTagDefinitions();
createInternalGeneralizations();
@@ -188,6 +200,7 @@ public class ProfileGenerator {
if (GENERATE_ABSTRACTIONS_MODEL) {
abstractionsModel = Utils.createModel(nameOfAbstractionsModel);
createAbstractionsModel(mapClassNodes);
+ createAbstractionsModel(mapProfileAssociations2MMAssociations);
abstractionsModel.setURI(NSURI_PREFIX + nameOfAbstractionsModel);
save(abstractionsModel, outputDirectoryPath, nameOfAbstractionsModel, UMLResource.FILE_EXTENSION);
}
@@ -199,6 +212,50 @@ public class ProfileGenerator {
}
/**
+ * Creates associations between stereotypes in a profile, based on the
+ * associations in a domain model
+ */
+ protected void createAssociations() {
+ Stereotype targetEndInProfile = null;
+ Stereotype sourceEndInProfile = null;
+ for (Association assocInMM : listAssociations) {
+ Property targetEndInMM = Utils.getTargetEnd(assocInMM);
+ // Property sourceEndInMM = targetEndInMM.getOtherEnd();
+ Property sourceEndInMM = Utils.getSourceEnd(assocInMM);
+ targetEndInProfile = getStereotypeByName(targetEndInMM.getType().getName());
+ sourceEndInProfile = getStereotypeByName(sourceEndInMM.getType().getName());
+ if (targetEndInProfile != null) {
+ Association assocInProfile = Utils.createAssociation(sourceEndInProfile, true,
+ AggregationKind.NONE_LITERAL, targetEndInMM.getName(), targetEndInMM.getLower(),
+ targetEndInMM.getUpper(), targetEndInProfile, true, AggregationKind.NONE_LITERAL,
+ sourceEndInMM.getName(), sourceEndInMM.getLower(), sourceEndInMM.getUpper());
+ assocInProfile.setName(assocInMM.getName());
+ mapProfileAssociations2MMAssociations.put(assocInProfile, assocInMM);
+ }
+ }
+ }
+
+ /**
+ * @param stereotypeName
+ * The not qualified name of a stereotype
+ * @return stereotype The stereotype with the stereotypeName in the
+ * Stereotypes - Class map (ex. key: Stereotype named Focus, value:
+ * Class named Focus).
+ */
+ protected Stereotype getStereotypeByName(String stereotypeName) {
+ Stereotype stereotype=null;
+ for (Map.Entry<Element, Element> entry : mapClassNodes.entrySet()) {
+ if (entry.getKey() instanceof Stereotype && entry.getValue() instanceof Class) {
+ stereotype = (Stereotype) entry.getKey();
+ if (stereotype.getName().contentEquals(stereotypeName)){
+ return stereotype;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Generates the mapping model between source elements and produced
* elements. Each abstraction relationship can have many sources and many
* targets which is ideal to allow N 2 M mappings.
@@ -244,6 +301,7 @@ public class ProfileGenerator {
mapAssociationsEdges.put(
(Element) Utils.createStereotype(profile, ((NamedElement) element).getName(), false), element);
}
+ listAssociations.add((Association)element);
}
}
diff --git a/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/utils/Utils.java b/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/utils/Utils.java
index 211b146d706..9df23151798 100644
--- a/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/utils/Utils.java
+++ b/extraplugins/req/org.eclipse.papyrus.req.domainModel2Profile/src/org/eclipse/papyrus/req/domainModel2Profile/utils/Utils.java
@@ -15,6 +15,7 @@
package org.eclipse.papyrus.req.domainModel2Profile.utils;
import java.io.File;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -26,7 +27,11 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Extension;
@@ -34,6 +39,7 @@ import org.eclipse.uml2.uml.Generalization;
import org.eclipse.uml2.uml.InstanceValue;
import org.eclipse.uml2.uml.LiteralBoolean;
import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Profile;
@@ -47,6 +53,10 @@ import org.eclipse.uml2.uml.UMLPackage;
* Utility methods to create a profile
*
*/
+/**
+ * @author MA244259
+ *
+ */
public class Utils {
/**
* Creates a new UML model with a specific name
@@ -279,4 +289,91 @@ public class Utils {
}
return null;
}
+
+ /**
+ * Creates an interface to call the createAssociation method of Type.class.
+ * In other words, it creates a(n) (binary) association between this type
+ * and the specified other type, with the specified navigabilities,
+ * aggregations, names, lower bounds, and upper bounds, and owned by this
+ * type's nearest package.
+ *
+ * @param end1IsNavigable The navigability for the first end of the new
+ * association.
+ *
+ * @param end1Aggregation The aggregation for the first end of the new
+ * association.
+ *
+ * @param end1Name The name for the first end of the new association.
+ *
+ * @param end1Lower The lower bound for the first end of the new
+ * association.
+ *
+ * @param end1Upper The upper bound for the first end of the new
+ * association.
+ *
+ * @param end1Type The type for the first end of the new association.
+ *
+ * @param end2IsNavigable The navigability for the second end of the new
+ * association.
+ *
+ * @param end2Aggregation The aggregation for the second end of the new
+ * association.
+ *
+ * @param end2Name The name for the second end of the new association.
+ *
+ * @param end2Lower The lower bound for the second end of the new
+ * association.
+ *
+ * @param end2Upper The upper bound for the second end of the new
+ * association.
+ */
+ public static Association createAssociation(Type type1,
+ boolean end1IsNavigable, AggregationKind end1Aggregation,
+ String end1Name, int end1LowerBound, int end1UpperBound,
+ Type type2, boolean end2IsNavigable,
+ AggregationKind end2Aggregation, String end2Name,
+ int end2LowerBound, int end2UpperBound) {
+ Association association = type1.createAssociation(end1IsNavigable,
+ end1Aggregation, end1Name, end1LowerBound, end1UpperBound, type2,
+ end2IsNavigable, end2Aggregation, end2Name, end2LowerBound,
+ end2UpperBound);
+ return association;
+ }
+
+
+
+ /**
+ * Obtains the source end of an association
+ * @param association
+ * @return The member end
+ */
+ public static Property getSourceEnd(Association association) {
+ return getMemberEnd(association, true);
+ }
+
+ /**
+ * Obtains the target end of an association
+ * @param association
+ * @return The member end
+ */
+ public static Property getTargetEnd(Association association) {
+ return getMemberEnd(association, false);
+ }
+
+ /**
+ * Obtains the source or target ends of an association
+ * @param association
+ * @param sourceNotTarget
+ * @return
+ */
+ public static Property getMemberEnd(Association association, boolean sourceNotTarget) {
+ if (sourceNotTarget && association.getMemberEnds().size() > 0) {
+ return (Property) association.getMemberEnds().get(0);
+ }
+ if (!sourceNotTarget && association.getMemberEnds().size() > 1) {
+ return (Property) association.getMemberEnds().get(1);
+ }
+ return null;
+ }
+
} \ No newline at end of file
diff --git a/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceConstants.java b/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceConstants.java
index 7431f4ece27..9b7791ff992 100644
--- a/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceConstants.java
+++ b/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceConstants.java
@@ -18,13 +18,15 @@ package org.eclipse.papyrus.req.sysml.preferences;
* Constant definitions for plug-in preferences
*/
public class PreferenceConstants {
+ //Options for requirements creation
public static final String REQUIREMENT_ID_PREFIX = "REQUIREMENT_ID_PREFIX";
public static final String REQUIREMENT_ID_DIGIT = "REQUIREMENT_ID_DIGIT";
public static final String CHILD_REQUIREMENTS_SEPARATOR = "CHILD_REQUIREMENTS_SEPARATOR";
-
+ //Options for the generation of a profile based on a domain model
public static final String NSURI_PREFIX = "NSURI_PREFIX";
public static final String GENERATE_ABSTRACTIONS_MODEL = "GENERATE_ABSTRACTIONS_MODEL";
public static final String FROM_ASSOCIATIONS_TO_STEREOTYPES = "FROM_ASSOCIATIONS_TO_STEREOTYPES";
-// public static final String METACLASS_EXTENDED_BY_NODES = "METACLASS_EXTENDED_BY_NODES";
-// public static final String METACLASS_EXTENDED_BY_EDGES = "METACLASS_EXTENDED_BY_EDGES";
+ public static final String FROM_ASSOCIATIONS_TO_ASSOCIATIONS="FROM_ASSOCIATIONS_TO_ASSOCIATIONS";
+ //public static final String METACLASS_EXTENDED_BY_NODES = "METACLASS_EXTENDED_BY_NODES";
+ //public static final String METACLASS_EXTENDED_BY_EDGES = "METACLASS_EXTENDED_BY_EDGES";
} \ No newline at end of file
diff --git a/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceInitializer.java b/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceInitializer.java
index ae77ee1b2eb..da573b04cd9 100644
--- a/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceInitializer.java
+++ b/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferenceInitializer.java
@@ -9,7 +9,7 @@
*
* Contributors:
* CEA LIST. - initial API and implementation
- * Mauricio Alferez (mauricio.alferez@cea.fr) CEA LIST - Bugs 477726, 478595, 481377
+ * Mauricio Alferez (mauricio.alferez@cea.fr) CEA LIST - Bugs 477726, 478595, 481377, ...
*
******************************************************************************/
package org.eclipse.papyrus.req.sysml.preferences;
@@ -27,12 +27,20 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ // Options for requirements creation
store.setDefault(PreferenceConstants.REQUIREMENT_ID_PREFIX, "REQ_");
store.setDefault(PreferenceConstants.REQUIREMENT_ID_DIGIT, 3);
store.setDefault(PreferenceConstants.CHILD_REQUIREMENTS_SEPARATOR, "_");
+ // Options for the generation of a profile based on a domain model
store.setDefault(PreferenceConstants.NSURI_PREFIX, "https://www.eclipse.org/papyrus/");
store.setDefault(PreferenceConstants.GENERATE_ABSTRACTIONS_MODEL, false);
store.setDefault(PreferenceConstants.FROM_ASSOCIATIONS_TO_STEREOTYPES, false);
+ store.setDefault(PreferenceConstants.FROM_ASSOCIATIONS_TO_ASSOCIATIONS, false);
+ // store.setDefault(PreferenceConstants.METACLASS_EXTENDED_BY_NODES,
+ // "none");
+ // store.setDefault(PreferenceConstants.METACLASS_EXTENDED_BY_EDGES,
+ // "none");
}
}
diff --git a/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferencePage.java b/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferencePage.java
index 1f9884442ad..f33798a0cc2 100644
--- a/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferencePage.java
+++ b/extraplugins/req/org.eclipse.papyrus.req.sysml.preferences/src/org/eclipse/papyrus/req/sysml/preferences/PreferencePage.java
@@ -9,7 +9,7 @@
*
* Contributors:
* CEA LIST. - initial API and implementation
- * Mauricio Alferez (mauricio.alferez@cea.fr) CEA LIST - Bugs 477726, 478595,
+ * Mauricio Alferez (mauricio.alferez@cea.fr) CEA LIST - Bugs 477726, 478595, 481377,...
*
*******************************************************************************/
@@ -45,21 +45,23 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe
*/
@Override
public void createFieldEditors() {
- Group reqCreationOptions = createGroup("Requirement");
+ Group reqCreationOptions = createGroup("Requirements creation");
addField(new StringFieldEditor(PreferenceConstants.REQUIREMENT_ID_PREFIX, "Prefix for requirement ID",
reqCreationOptions));
addField(new IntegerFieldEditor(PreferenceConstants.REQUIREMENT_ID_DIGIT, "Number of digits for requirement ID",
reqCreationOptions));
addField(new StringFieldEditor(PreferenceConstants.CHILD_REQUIREMENTS_SEPARATOR,
"Separator between parent and child requirements IDs", reqCreationOptions));
-
- Group profileCreationOptions = createGroup("Profile Creation");
+
+ Group profileCreationOptions = createGroup("Generation of a profile based on a domain model");
+ addField(new StringFieldEditor(PreferenceConstants.NSURI_PREFIX, "Ns URI prefix for new profile",
+ profileCreationOptions));
addField(new BooleanFieldEditor(PreferenceConstants.GENERATE_ABSTRACTIONS_MODEL,
"Generate an abstraction model?", profileCreationOptions));
addField(new BooleanFieldEditor(PreferenceConstants.FROM_ASSOCIATIONS_TO_STEREOTYPES,
"Transform from associations to stereotypes?", profileCreationOptions));
- addField(new StringFieldEditor(PreferenceConstants.NSURI_PREFIX, "Ns URI prefix for new profile",
- profileCreationOptions));
+ addField(new BooleanFieldEditor(PreferenceConstants.FROM_ASSOCIATIONS_TO_ASSOCIATIONS,
+ "Transform from associations to associations?", profileCreationOptions));
}
/*

Back to the top