Skip to content
Snippets Groups Projects
Commit be2e15a4 authored by Alberto Debiasi's avatar Alberto Debiasi
Browse files

Refactor EntityUtil to speed up stereotypes management.

Change-Id: I038cc504b05db18529dc26693e1ae6ff62dff568
parent 4621d4c1
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
//import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPage;
import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
......@@ -425,8 +426,7 @@ public class EntityUtil {
return null;
}
public Port getExistingUmlPort(String portName, String typeName,
EList<NamedElement> existingPorts) {
public Port getExistingUmlPort(String portName, String typeName, EList<NamedElement> existingPorts) {
for (Object object : existingPorts) {
final Port tmpPort = (Port) object;
if (tmpPort.getName().equals(portName) && tmpPort.getType().getName().equals(typeName)) {
......@@ -439,12 +439,33 @@ public class EntityUtil {
public Stereotype findStereotype(Package pkg, String stereotypeName) {
for (Stereotype sub : UMLUtil.findSubstereotypes(pkg, stereotypeName)) {
if (sub.getQualifiedName().equals(stereotypeName)) {
return sub;
logger.debug("findStereotype " + stereotypeName);
try {
if (stereotypeName.startsWith("CHESSContract")) {
return StereotypeUtil.getCHESSContractStereotype(stereotypeName, pkg);
} else if (stereotypeName.startsWith("CHESS")) {
return StereotypeUtil.getCHESSStereotype(stereotypeName, pkg);
} else if (stereotypeName.startsWith("SysML")) {
return StereotypeUtil.getSysMLStereotype(stereotypeName, pkg);
} else if (stereotypeName.startsWith("MARTE")) {
return StereotypeUtil.getMarteStereotype(stereotypeName, pkg);
} else {
for (Stereotype sub : UMLUtil.findSubstereotypes(pkg, stereotypeName)) {
if (sub.getQualifiedName().equals(stereotypeName)) {
return sub;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
/*
* for (Stereotype sub : UMLUtil.findSubstereotypes(pkg,
* stereotypeName)) { if (sub.getQualifiedName().equals(stereotypeName))
* { return sub; } } return null;
*/
}
public void updateUmlStaticPort(Port port, String[] newMultiplicityRange) {
......@@ -484,7 +505,7 @@ public class EntityUtil {
public Parameter createUmlFunctionBehaviorParameters(FunctionBehavior owner, EList<Type> inputTypes,
EList<String[]> inputMultiplicities, Type outputType, String[] outputMultiplicity) {
// Create the input parameters
for (int i = 0; i < inputTypes.size(); i++) {
Type parameterType = inputTypes.get(i);
......@@ -519,9 +540,9 @@ public class EntityUtil {
return newUMLConstraint;
}
public Connector createUmlConnector(Class owner, String constraintName,
Property partWithPortOfConstraint, Class portOwnerOfConstraint, String variableName,
Property partWithPortOfVariable, Class portOwnerOfVariable) {
public Connector createUmlConnector(Class owner, String constraintName, Property partWithPortOfConstraint,
Class portOwnerOfConstraint, String variableName, Property partWithPortOfVariable,
Class portOwnerOfVariable) {
// Create the source end
// Create the name using an incremental value
......@@ -603,8 +624,7 @@ public class EntityUtil {
int numInstantiatedArchitecures = getInstantiatedArchitecureConfigurations(owner).size();
Property property = owner
.createOwnedAttribute("InstantiateArc_" + (numInstantiatedArchitecures + 1), null);
Property property = owner.createOwnedAttribute("InstantiateArc_" + (numInstantiatedArchitecures + 1), null);
UMLUtils.applyStereotype(property, INSTANTIATED_ARCHITECTURE_CONFIGURATION);
InstantiatedArchitectureConfiguration instantiatedArchitecture = getInstantiatedArchitectureConfiguration(
property);
......@@ -616,8 +636,10 @@ public class EntityUtil {
}
public InstantiatedArchitectureConfiguration getInstantiatedArchitectureConfiguration(Property umlProperty) {
Stereotype instantiatedArchitectureStereotype = UMLUtil.getAppliedStereotype(umlProperty,
INSTANTIATED_ARCHITECTURE_CONFIGURATION, false);
Stereotype instantiatedArchitectureStereotype = // UMLUtil.getAppliedStereotype(umlProperty,
// INSTANTIATED_ARCHITECTURE_CONFIGURATION, false);
StereotypeUtil.getCHESSStereotype(INSTANTIATED_ARCHITECTURE_CONFIGURATION, umlProperty);
return (InstantiatedArchitectureConfiguration) umlProperty
.getStereotypeApplication(instantiatedArchitectureStereotype);
}
......@@ -760,9 +782,10 @@ public class EntityUtil {
* @return the Enumeration
*/
public Enumeration getEnumeration(Package pkg, String enumName, boolean ignoreCase) {
return (Enumeration) pkg.getOwnedMember(enumName, ignoreCase, UMLFactory.eINSTANCE.createEnumeration().eClass());
return (Enumeration) pkg.getOwnedMember(enumName, ignoreCase,
UMLFactory.eINSTANCE.createEnumeration().eClass());
}
public EList<Enumeration> getEnumerationsInOrder(Package pkg) {
final EList<Enumeration> enumerations = getEnumerations(pkg);
......@@ -986,10 +1009,10 @@ public class EntityUtil {
public Property getSubComponentInstance(Class owner, String componentName) {
// logger.debug("getSubComponentInstance");
for (Property umlProperty : (owner.getAttributes())) {
//FIXME stereotype
// logger.debug("umlProperty: " + umlProperty);
// logger.debug("umlProperty.getname: " + umlProperty.getName());
if (umlProperty.getName().equals(componentName)
&& isComponentInstance(umlProperty)) {
if (umlProperty.getName().equals(componentName) && isComponentInstance(umlProperty)) {
return umlProperty;
}
}
......@@ -1001,8 +1024,8 @@ public class EntityUtil {
if (model != null) {
TreeIterator<EObject> allElements = model.eResource().getAllContents();
if (allElements != null) {
Collection<Class> classes = EcoreUtil
.getObjectsByType(iterator2Collection(allElements), UMLPackage.eINSTANCE.getClass_());
Collection<Class> classes = EcoreUtil.getObjectsByType(iterator2Collection(allElements),
UMLPackage.eINSTANCE.getClass_());
for (Class c : classes) {
if (isSystem(c)) {
......@@ -1030,6 +1053,7 @@ public class EntityUtil {
.getObjectsByType(iterator2Collection(allElements), UMLPackage.eINSTANCE.getPackage());
for (Package p : packages) {
//FIXME stereotype
if (isSystemViewPackage(p)) {
return p;
}
......@@ -1133,8 +1157,9 @@ public class EntityUtil {
public EList<Property> getInstantiatedArchitecureElementsAsProperties(Class umlComponent) {
EList<Property> instantiatedArchitecureList = new BasicEList<Property>();
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(INSTANTIATED_ARCHITECTURE_CONFIGURATION, umlComponent);
for (Property umlProperty : ((Class) umlComponent).getAttributes()) {
if (isInstantiatedArchitecuture(umlProperty)) {
if (umlProperty.getAppliedStereotypes().contains(stereotype)) {
instantiatedArchitecureList.add(umlProperty);
}
}
......@@ -1143,8 +1168,9 @@ public class EntityUtil {
public EList<InstantiatedArchitectureConfiguration> getInstantiatedArchitecureConfigurations(Class umlComponent) {
EList<InstantiatedArchitectureConfiguration> instantiatedArchitecureList = new BasicEList<InstantiatedArchitectureConfiguration>();
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(INSTANTIATED_ARCHITECTURE_CONFIGURATION, umlComponent);
for (Property umlProperty : ((Class) umlComponent).getAttributes()) {
if (isInstantiatedArchitecuture(umlProperty)) {
if (umlProperty.getAppliedStereotypes().contains(stereotype)) {
instantiatedArchitecureList.add(getInstantiatedArchitectureConfiguration(umlProperty));
}
}
......@@ -1155,6 +1181,7 @@ public class EntityUtil {
List<Property> subComponents = new ArrayList<Property>();
EList<Property> umlProperties = ((Class) umlComponent).getAttributes();
if (umlProperties != null) {
//FIXME stereotype
for (Property umlProperty : umlProperties) {
if (isComponentInstance(umlProperty)) {
subComponents.add(umlProperty);
......@@ -1176,6 +1203,7 @@ public class EntityUtil {
public Property getUmlComponentInstance(Class umlComponent, String componentName) {
for (Property umlProperty : (umlComponent.getAttributes())) {
//FIXME stereotype
if (umlProperty.getName().equals(componentName) && isComponentInstance(umlProperty)) {
return umlProperty;
}
......@@ -1241,7 +1269,9 @@ public class EntityUtil {
/**
* Returns the blocks contained in the given package.
* @param umlSelectedPackage the package to browse
*
* @param umlSelectedPackage
* the package to browse
* @return the list of blocks
*/
public ArrayList<Class> getBlocks(Package umlSelectedPackage) {
......@@ -1250,11 +1280,12 @@ public class EntityUtil {
ArrayList<Class> blocksAsClasses = new ArrayList<Class>();
if (!packageChildren.isEmpty()) {
// logger.debug("getBlocks: "+packageChildren.size());
Stereotype stereotype = StereotypeUtil.getSysMLStereotype(BLOCK, umlSelectedPackage);
Stereotype stereotype2 = StereotypeUtil.getCHESSContractStereotype(ContractEntityUtil.CONTRACT, umlSelectedPackage);
blocksAsClasses = new ArrayList<Class>();
for (Element element : packageChildren) {
if (isBlock(element) && !ContractEntityUtil.getInstance().isContract(element)) {
if (element.getAppliedStereotypes().contains(stereotype) && !element.getAppliedStereotypes().contains(stereotype2)) {
blocksAsClasses.add((Class) element);
}
}
......@@ -1317,8 +1348,9 @@ public class EntityUtil {
private EList<Port> getUmlPortsFromClass(Class umlComponent, int portDirection, boolean isStatic) {
EList<Port> ports = new BasicEList<Port>();
Stereotype stereotype = StereotypeUtil.getSysMLStereotype(FLOW_Port, umlComponent);
for (Port umlPort : umlComponent.getOwnedPorts()) {
FlowPort fp = getFlowPort(umlPort);
FlowPort fp = (FlowPort) umlPort.getStereotypeApplication(stereotype);
if ((fp.getDirection().getValue() == portDirection) && (umlPort.isStatic() == isStatic)) {
ports.add(umlPort);
}
......@@ -1354,9 +1386,9 @@ public class EntityUtil {
private Set<Port> getUmlPortsFromComponent(Component umlComponent, int portDirection, boolean isStaticPort) {
Set<Port> ports = new HashSet<Port>();
Stereotype stereotype = StereotypeUtil.getMarteStereotype(FLOW_Port_MARTE, umlComponent);
for (Port umlPort : umlComponent.getOwnedPorts()) {
org.eclipse.papyrus.MARTE.MARTE_DesignModel.GCM.FlowPort fp = getFlowPortMarte(umlPort);
org.eclipse.papyrus.MARTE.MARTE_DesignModel.GCM.FlowPort fp = (org.eclipse.papyrus.MARTE.MARTE_DesignModel.GCM.FlowPort) umlPort.getStereotypeApplication(stereotype);
if ((fp.getDirection().getValue() == portDirection) && (umlPort.isStatic() == isStaticPort)) {
ports.add(umlPort);
}
......@@ -1401,23 +1433,28 @@ public class EntityUtil {
/**
* Returns the package containing the given element.
* @param umlElement the UML element
*
* @param umlElement
* the UML element
* @return the Package
*/
public Package getContainingPackage(Element umlElement) {
return umlElement.getNearestPackage();
}
private FlowPort getFlowPort(Port umlPort) {
Stereotype contrStereo = UMLUtil.getAppliedStereotype(umlPort, FLOW_Port, false);
return (FlowPort) umlPort.getStereotypeApplication(contrStereo);
Stereotype stereotype = StereotypeUtil.getSysMLStereotype(FLOW_Port, umlPort);
// Stereotype contrStereo = UMLUtil.getAppliedStereotype(umlPort,
// FLOW_Port, false);
return (FlowPort) umlPort.getStereotypeApplication(stereotype);
}
private org.eclipse.papyrus.MARTE.MARTE_DesignModel.GCM.FlowPort getFlowPortMarte(Port umlPort) {
Stereotype flowPortStereo = UMLUtil.getAppliedStereotype(umlPort, FLOW_Port_MARTE, false);
return (org.eclipse.papyrus.MARTE.MARTE_DesignModel.GCM.FlowPort) umlPort
.getStereotypeApplication(flowPortStereo);
Stereotype stereotype = StereotypeUtil.getMarteStereotype(FLOW_Port_MARTE, umlPort);
// Stereotype flowPortStereo = UMLUtil.getAppliedStereotype(umlPort,
// FLOW_Port_MARTE, false);
return (org.eclipse.papyrus.MARTE.MARTE_DesignModel.GCM.FlowPort) umlPort.getStereotypeApplication(stereotype);
}
public boolean isPort(Element umlElement) {
......@@ -1425,12 +1462,13 @@ public class EntityUtil {
}
private boolean isFlowPort(Element umlElement) {
return (umlElement instanceof Property && UMLUtil.getAppliedStereotype(umlElement, FLOW_Port, false) != null);
Stereotype stereotype = StereotypeUtil.getSysMLStereotype(FLOW_Port, umlElement);
return (umlElement instanceof Property && umlElement.getAppliedStereotypes().contains(stereotype));
}
private boolean isFlowPortMarte(Element umlElement) {
return (umlElement instanceof Property
&& UMLUtil.getAppliedStereotype(umlElement, FLOW_Port_MARTE, false) != null);
Stereotype stereotype = StereotypeUtil.getMarteStereotype(FLOW_Port_MARTE, umlElement);
return (umlElement instanceof Property && umlElement.getAppliedStereotypes().contains(stereotype));
}
public void deleteComponentContract(Class clazz) {
......@@ -1438,12 +1476,13 @@ public class EntityUtil {
}
public boolean isComponentImplementation(Element umlElement) {
return (umlElement instanceof Class && UMLUtil.getAppliedStereotype(umlElement, COMP_IMPL, false) != null);
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(COMP_IMPL, umlElement);
return (umlElement instanceof Class && umlElement.getAppliedStereotypes().contains(stereotype));
}
public boolean isInstantiatedArchitecuture(Element umlElement) {
return (umlElement instanceof Property
&& UMLUtil.getAppliedStereotype(umlElement, INSTANTIATED_ARCHITECTURE_CONFIGURATION, false) != null);
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(INSTANTIATED_ARCHITECTURE_CONFIGURATION, umlElement);
return (umlElement instanceof Property && umlElement.getAppliedStereotypes().contains(stereotype));
}
// modified method!!
......@@ -1509,17 +1548,20 @@ public class EntityUtil {
}
private BoundedSubtype getRangeAttribute(Type umlType) {
Stereotype boundedStereo = UMLUtil.getAppliedStereotype(umlType, BOUNDED_TYPE, false);
return (BoundedSubtype) umlType.getStereotypeApplication(boundedStereo);
// Stereotype boundedStereo = UMLUtil.getAppliedStereotype(umlType,
// BOUNDED_TYPE, false);
Stereotype stereotype = StereotypeUtil.getMarteStereotype(BOUNDED_TYPE, umlType);
return (BoundedSubtype) umlType.getStereotypeApplication(stereotype);
}
public boolean isRangeAttribute(Property umlProperty) {
return isRangeType(umlProperty.getType());
}
public boolean isRangeType(Type umlType) {
public boolean isRangeType(Type umlType) {
if (umlType != null) {
if (UMLUtil.getAppliedStereotype(umlType, BOUNDED_TYPE, false) != null) {
Stereotype stereotype = StereotypeUtil.getMarteStereotype(BOUNDED_TYPE, umlType);
if (umlType.getAppliedStereotypes().contains(stereotype)) {
return true;
}
}
......@@ -1607,30 +1649,51 @@ public class EntityUtil {
}
public boolean isBlock(Element umlClass) {
return (umlClass instanceof Class && UMLUtil.getAppliedStereotype(umlClass, BLOCK, false) != null);
}
if(umlClass instanceof Class){
Stereotype stereotype = StereotypeUtil.getSysMLStereotype(BLOCK, umlClass);
return umlClass.getAppliedStereotypes().contains(stereotype);
}
return false;
}
public boolean isCompType(Element umlComponent) {
return (umlComponent instanceof Class && UMLUtil.getAppliedStereotype(umlComponent, COMP_TYPE, false) != null);
if(umlComponent instanceof Class){
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(COMP_TYPE, umlComponent);
return umlComponent.getAppliedStereotypes().contains(stereotype);
}
return false;
}
public boolean isSystem(Element umlElement) {
return (umlElement instanceof Class && UMLUtil.getAppliedStereotype(umlElement, SYSTEM, false) != null);
if(umlElement instanceof Class){
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(SYSTEM, umlElement);
return umlElement.getAppliedStereotypes().contains(stereotype);
}
return false;
}
public boolean isFaultyStateMachine(Element umlElement) {
return (umlElement instanceof StateMachine
&& UMLUtil.getAppliedStereotype(umlElement, FAULTY_STATE_MACHINE, false) != null);
if(umlElement instanceof StateMachine){
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(FAULTY_STATE_MACHINE, umlElement);
return umlElement.getAppliedStereotypes().contains(stereotype);
}
return false;
}
public boolean isNominalStateMachine(Element umlElement) {
return (umlElement instanceof StateMachine
&& UMLUtil.getAppliedStereotype(umlElement, FAULTY_STATE_MACHINE, false) == null);
if(umlElement instanceof StateMachine){
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(FAULTY_STATE_MACHINE, umlElement);
return !umlElement.getAppliedStereotypes().contains(stereotype);
}
return false;
}
public boolean isPrioritizedTransition(Element umlElement) {
return (umlElement instanceof Transition
&& UMLUtil.getAppliedStereotype(umlElement, PRIORITIZED_TRANSITION, false) != null);
if(umlElement instanceof Transition){
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(PRIORITIZED_TRANSITION, umlElement);
return umlElement.getAppliedStereotypes().contains(stereotype);
}
return false;
}
/*
......@@ -1778,11 +1841,12 @@ public class EntityUtil {
if (umlModel != null) {
TreeIterator<EObject> allElements = umlModel.eResource().getAllContents();
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(FAULTY_STATE_MACHINE, umlModel);
if (allElements != null) {
Collection<org.eclipse.uml2.uml.Class> classes = EcoreUtil
.getObjectsByType(iterator2Collection(allElements), UMLPackage.eINSTANCE.getClass_());
for (Class c : classes) {
if (isNominalStateMachine(c)) {
if (!c.getAppliedStereotypes().contains(stereotype)) {
stateMachines.add((StateMachine) c);
}
}
......@@ -1791,7 +1855,7 @@ public class EntityUtil {
return stateMachines;
}
public Set<StateMachine> getNominalStateMachines(UmlModel umlModel) {
Set<StateMachine> stateMachines = new HashSet<StateMachine>();
......@@ -1802,6 +1866,7 @@ public class EntityUtil {
Collection<org.eclipse.uml2.uml.Class> classes = EcoreUtil
.getObjectsByType(iterator2Collection(allElements), UMLPackage.eINSTANCE.getClass_());
for (Class c : classes) {
//FIXME stereotype
if (isNominalStateMachine(c)) {
stateMachines.add((StateMachine) c);
}
......@@ -1837,9 +1902,10 @@ public class EntityUtil {
if (umlSelectedComponent != null) {
EList<Behavior> behaviours = umlSelectedComponent.getOwnedBehaviors();
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(FAULTY_STATE_MACHINE, umlSelectedComponent);
if (behaviours != null) {
for (Class c : behaviours) {
if (isNominalStateMachine(c)) {
if (!c.getAppliedStereotypes().contains(stereotype)) {
stateMachines.add((StateMachine) c);
}
}
......@@ -2036,8 +2102,10 @@ public class EntityUtil {
public Integer getTransitionPriority(Transition transition) {
if (isPrioritizedTransition(transition)) {
Stereotype prioritizedTransitionStereotype = UMLUtil.getAppliedStereotype(transition,
PRIORITIZED_TRANSITION, false);
Stereotype prioritizedTransitionStereotype =
// UMLUtil.getAppliedStereotype(transition,PRIORITIZED_TRANSITION,
// false);
StereotypeUtil.getCHESSStereotype(PRIORITIZED_TRANSITION, transition);
PrioritizedTransition prioritizedTransition = (PrioritizedTransition) transition
.getStereotypeApplication(prioritizedTransitionStereotype);
return prioritizedTransition.getPriority();
......@@ -2074,8 +2142,7 @@ public class EntityUtil {
return eventsPort;
}
public Constraint createTransitionGuard(Transition owner, String guardName, String guardText,
String language) {
public Constraint createTransitionGuard(Transition owner, String guardName, String guardText, String language) {
// Create an empty guard for the transition
final Constraint guard = owner.createGuard(guardName);
......@@ -2273,6 +2340,7 @@ public class EntityUtil {
} else {
EList<Package> owningPackages = pkg.allOwningPackages();
for (Package owningPackage : owningPackages) {
//FIXME stereotype
if (owningPackage.getAppliedStereotype(SYSVIEW) != null) {
return true;
}
......@@ -2341,8 +2409,9 @@ public class EntityUtil {
}
public boolean isFormalProperty(Element umlConstraint) {
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(FORMAL_PROP, umlConstraint);
if (umlConstraint instanceof Constraint) {
return UMLUtil.getAppliedStereotype(umlConstraint, FORMAL_PROP, false) != null;
return umlConstraint.getAppliedStereotypes().contains(stereotype);
}
return false;
}
......@@ -2369,8 +2438,9 @@ public class EntityUtil {
EList<Constraint> constraints = new BasicEList<Constraint>();
if (isBlock(umlElement) || isCompType(umlElement) || isComponentImplementation(umlElement)) {
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(MACRO_DEFINITION, umlElement);
for (Constraint umlConstraint : ((Class) umlElement).getOwnedRules()) {
if (isMacroDefinition(umlConstraint)) {
if (umlConstraint.getAppliedStereotypes().contains(stereotype)) {
constraints.add((Constraint) umlConstraint);
}
}
......@@ -2391,8 +2461,9 @@ public class EntityUtil {
* @return true if the given element is a Macro Definition
*/
public boolean isMacroDefinition(Element umlConstraint) {
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(MACRO_DEFINITION, umlConstraint);
if (umlConstraint instanceof Constraint) {
return UMLUtil.getAppliedStereotype(umlConstraint, MACRO_DEFINITION, false) != null;
return umlConstraint.getAppliedStereotypes().contains(stereotype);
}
return false;
}
......@@ -2412,21 +2483,24 @@ public class EntityUtil {
}
public FormalProperty getFormalProperty(Constraint umlConstraint) {
Stereotype formalPropertyStereotype = UMLUtil.getAppliedStereotype(umlConstraint, FORMAL_PROP, false);
return (FormalProperty) umlConstraint.getStereotypeApplication(formalPropertyStereotype);
// Stereotype formalPropertyStereotype =
// UMLUtil.getAppliedStereotype(umlConstraint, FORMAL_PROP, false);
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(FORMAL_PROP, umlConstraint);
return (FormalProperty) umlConstraint.getStereotypeApplication(stereotype);
}
public boolean isDelegationConstraint(Element umlProperty) {
return ((umlProperty instanceof Constraint)
&& (UMLUtil.getAppliedStereotype(umlProperty, DELEGATION_CONST, false) != null));
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(DELEGATION_CONST, umlProperty);
return ((umlProperty instanceof Constraint) && umlProperty.getAppliedStereotypes().contains(stereotype));
}
public EList<Constraint> getDelegationConstraintsAsUMLConstraints(Element umlElement) {
EList<Constraint> constraints = new BasicEList<Constraint>();
if (isBlock(umlElement) || isCompType(umlElement) || isComponentImplementation(umlElement)) {
for (Constraint umlConstraint : ((Class) umlElement).getOwnedRules()) {
if (isDelegationConstraint(umlConstraint)) {
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(DELEGATION_CONST, umlElement);
for (Constraint umlConstraint : ((Class) umlElement).getOwnedRules()) {
if (umlConstraint.getAppliedStereotypes().contains(stereotype)) {
constraints.add((Constraint) umlConstraint);
}
}
......@@ -2703,7 +2777,7 @@ public class EntityUtil {
* the Transition to be stereotyped
* @param priority
* the priority to assign
* @return
* @return
*/
public PrioritizedTransition createPrioritizedTransition(Transition transition, Integer priority) {
final Stereotype prioritizedTransitionStereotype = findStereotype(transition.getNearestPackage(),
......@@ -2755,8 +2829,8 @@ public class EntityUtil {
return createFunctionBehaviorParameter(owner, parameterName, parameterType, multiplicity, isInput);
}
public Port createNonStaticPort(Class owner, String portName, Type portType,
String[] multiplicityBounds, boolean isInput, Stereotype flowportStereotype) {
public Port createNonStaticPort(Class owner, String portName, Type portType, String[] multiplicityBounds,
boolean isInput, Stereotype flowportStereotype) {
Port umlPort = UMLFactory.eINSTANCE.createPort();
umlPort.setName(portName);
umlPort.setType(portType);
......@@ -2780,8 +2854,8 @@ public class EntityUtil {
return umlPort;
}
public Port createStaticPort(Class owner, String portName, Type portType,
String[] multiplicityBounds, Stereotype flowPortStereotype) {
public Port createStaticPort(Class owner, String portName, Type portType, String[] multiplicityBounds,
Stereotype flowPortStereotype) {
Port umlPort = UMLFactory.eINSTANCE.createPort();
umlPort.setName(portName);
......@@ -2848,9 +2922,9 @@ public class EntityUtil {
// the
// port
final Port sourcePort = (Port) ends.get(0).getRole(); // Should
// be
// the
// port
// be
// the
// port
if (sourcePort.getName().equals(constraintPortName)) {
if (sourceOwner != null && sourceOwner.getName().equals(constraintPortOwner)) {
......@@ -2871,9 +2945,9 @@ public class EntityUtil {
// the
// port
final Port targetPort = (Port) ends.get(1).getRole(); // Should
// be
// the
// port
// be
// the
// port
if (targetPort.getName().equals(variablePortName)) {
if (targetOwner != null && targetOwner.getName().equals(variablePortOwner)) {
......@@ -3435,8 +3509,9 @@ public class EntityUtil {
EList<Constraint> constraints = new BasicEList<Constraint>();
if (isBlock(umlElement) || isCompType(umlElement) || isComponentImplementation(umlElement)) {
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(PARAMETER_ASSUMPTIONS, umlElement);
for (Constraint umlConstraint : ((Class) umlElement).getOwnedRules()) {
if (isParameterAssumptions(umlConstraint)) {
if (umlConstraint.getAppliedStereotypes().contains(stereotype)) {
constraints.add((Constraint) umlConstraint);
}
}
......@@ -3456,15 +3531,17 @@ public class EntityUtil {
* the constraint
* @return true if the given element is a Parameter Assumptions.
*/
public boolean isParameterAssumptions(Element umlConstraint) {
public boolean isParameterAssumptions(Element umlConstraint) {
if (umlConstraint instanceof Constraint) {
return UMLUtil.getAppliedStereotype(umlConstraint, PARAMETER_ASSUMPTIONS, false) != null;
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(PARAMETER_ASSUMPTIONS, umlConstraint);
return umlConstraint.getAppliedStereotypes().contains(stereotype);
}
return false;
}
/**
* Creates a new Parameter Assumptions element.
*
* @param owner
* the owning element
* @param parameterAssumptionsExpression
......@@ -3523,8 +3600,9 @@ public class EntityUtil {
* @return the UML Constraint found
*/
public Constraint getParameterAssumptionsFromExpression(String parameterAssumptionsExpression, Class owner) {
Stereotype stereotype = StereotypeUtil.getCHESSStereotype(PARAMETER_ASSUMPTIONS, owner);
for (Constraint umlConstraint : ((Class) owner).getOwnedRules()) {
if (isParameterAssumptions(umlConstraint)
if (umlConstraint.getAppliedStereotypes().contains(stereotype)
&& getConstraintBodyStr(umlConstraint, null).equals(parameterAssumptionsExpression)) {
return umlConstraint;
}
......@@ -3573,6 +3651,7 @@ public class EntityUtil {
final Class umlClass = (Class) component;
final EList<Property> attributes = umlClass.getOwnedAttributes();
for (final Property umlProperty : attributes) {
//FIXME stereotype
if (umlProperty != null && !isComponentInstance(umlProperty) && !isPort(umlProperty)
&& !ContractEntityUtil.getInstance().isContractProperty(umlProperty)) {
localProperties.add(umlProperty);
......@@ -3641,6 +3720,7 @@ public class EntityUtil {
/**
* Creates a new Macro Definition element.
*
* @param owner
* the owning element
* @param macroDefinitionName
......@@ -3694,12 +3774,13 @@ public class EntityUtil {
if (model != null) {
TreeIterator<EObject> allElements = model.eResource().getAllContents();
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(SYSTEM, model);
if (allElements != null) {
Collection<org.eclipse.uml2.uml.Class> classes = EcoreUtil
.getObjectsByType(iterator2Collection(allElements), UMLPackage.eINSTANCE.getClass_());
for (Class c : classes) {
if (isSystem(c)) {
if (c.getAppliedStereotypes().contains(stereotype)) {
return c;
}
}
......@@ -3707,7 +3788,7 @@ public class EntityUtil {
}
return null;
}
/**
* Returns the System component of the given package, if any.
*
......@@ -3721,8 +3802,9 @@ public class EntityUtil {
if (pkg != null) {
final EList<Element> ownedElements = pkg.getOwnedElements();
Stereotype stereotype = StereotypeUtil.getCHESSContractStereotype(SYSTEM, pkg);
for (Element element : ownedElements) {
if (isSystem(element)) {
if (element.getAppliedStereotypes().contains(stereotype)) {
if (!found) {
systemElement = element;
found = true;
......@@ -4008,14 +4090,19 @@ public class EntityUtil {
/**
* Return the first block in the given package
* @param currPackage the package where to look for
* @param blockName the name of the block to retrieve
*
* @param currPackage
* the package where to look for
* @param blockName
* the name of the block to retrieve
* @param ignoreCase
* @return the block
*/
public Class getBlockType(Package currPackage, String blockName, boolean ignoreCase) {
// PackageableElement element = currPackage.getPackagedElement(blockName);
PackageableElement element = currPackage.getPackagedElement(blockName, ignoreCase, UMLPackage.eINSTANCE.getClass_(), false);
// PackageableElement element =
// currPackage.getPackagedElement(blockName);
PackageableElement element = currPackage.getPackagedElement(blockName, ignoreCase,
UMLPackage.eINSTANCE.getClass_(), false);
if (isBlock(element)) {
return (Class) element;
}
......@@ -4055,11 +4142,13 @@ public class EntityUtil {
}
/**
* Returns the first operation found with the given name.
* <br>
* Returns the first operation found with the given name. <br>
* This is a very trivial method, no additional checks are done.
* @param operationName the name of the Operation
* @param block the owner class
*
* @param operationName
* the name of the Operation
* @param block
* the owner class
* @return the Operation
*/
public Operation getOperation(String operationName, Class block) {
......@@ -4076,26 +4165,30 @@ public class EntityUtil {
}
/**
* Returns the first property found with the given name.
* <br>
* Returns the first property found with the given name. <br>
* This is a very trivial method, no additional checks are done.
* @param propertyName the name of the Property
* @param block the owner class
*
* @param propertyName
* the name of the Property
* @param block
* the owner class
* @return the Property
*/
public Property getProperty(String propertyName, Class block) {
return block.getOwnedAttribute(propertyName, null);
}
/**
* Returns the list of properties for the given class.
* @param block the owner class
*
* @param block
* the owner class
* @return the list of properties
*/
public EList<Property> getProperties(Class block) {
return block.getOwnedAttributes();
}
public boolean isAttribute(String attributeName, Class blockAsClass) {
if (blockAsClass != null) {
Property umlProperty = blockAsClass.getOwnedAttribute(attributeName, null);
......@@ -4258,34 +4351,30 @@ public class EntityUtil {
return null;
}
public List<String> getMethodArgumentNames(String methodName, Class retrieveBlockType) {
List<String> args = new ArrayList<String>();
Operation operation = getOperation(methodName, retrieveBlockType);
if ((operation != null)) {
if (operation.inputParameters() != null) {
for(Parameter par : operation.inputParameters()){
for (Parameter par : operation.inputParameters()) {
args.add(par.getName());
}
}
}
}
return args;
}
@SuppressWarnings("unchecked")
public Collection<Enumeration> getAllEnumeratives(Package packageElement) throws Exception {
return (Collection<Enumeration>) EObjectUtil.getAllElements(UMLPackage.eINSTANCE.getEnumeration(),
packageElement);
}
/**
* Returns all the classes in the model.
* <p> BEWARE: all the classes, not only the classes in the given package
* <p>
* BEWARE: all the classes, not only the classes in the given package
*
* @param packageElement
* @return
* @throws Exception
......@@ -4313,7 +4402,7 @@ public class EntityUtil {
}
}
return null;
}
}
public Collection<Operation> getAllOperations(Package packageElement) throws Exception {
if (packageElement != null) {
......@@ -4325,8 +4414,6 @@ public class EntityUtil {
throw new Exception("Element does not exist.");
}
public static <T> Collection<T> getClassObjects(Collection<EObject> objects) {
Collection<T> result = new ArrayList<T>();
for (EObject object : objects) {
......@@ -4338,12 +4425,15 @@ public class EntityUtil {
}
return result;
}
/**
* Returns true if the visibility of the given element is private.
* @param e the NamedElement
*
* @param e
* the NamedElement
* @return
* @throws Exception in case no visibility is set
* @throws Exception
* in case no visibility is set
*/
public boolean isVisibilityPrivate(NamedElement e) throws Exception {
if (e.isSetVisibility()) {
......@@ -4354,9 +4444,12 @@ public class EntityUtil {
/**
* Returns true if the visibility of the given element is priprotected.
* @param e the NamedElement
*
* @param e
* the NamedElement
* @return
* @throws Exception in case no visibility is set
* @throws Exception
* in case no visibility is set
*/
public boolean isVisibilityProtected(NamedElement e) throws Exception {
if (e.isSetVisibility()) {
......@@ -4367,9 +4460,12 @@ public class EntityUtil {
/**
* Returns true if the visibility of the given element is public.
* @param e the NamedElement
*
* @param e
* the NamedElement
* @return
* @throws Exception in case no visibility is set
* @throws Exception
* in case no visibility is set
*/
public boolean isVisibilityPublic(NamedElement e) throws Exception {
if (e.isSetVisibility()) {
......@@ -4380,11 +4476,13 @@ public class EntityUtil {
/**
* Returns all the direct and indirect elements of the given package.
* @param pkg the package to navigate
*
* @param pkg
* the package to navigate
* @return
*/
public EList<Element> getAllPackageElements(Package pkg) {
return pkg.allOwnedElements();
}
}
\ No newline at end of file
package org.polarsys.chess.contracts.profile.chesscontract.util;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
public class StereotypeUtil {
private static Profile chessProfile;
private static Profile chessContractProfile;
private static Profile sysMLProfile;
private static Profile marteProfile;
private static int modelHashCode;
public static Stereotype getCHESSStereotype(String name, Element element){
if (modelHashCode == 0) {
modelHashCode = element.getModel().hashCode();
}
//String projectName = element.getModel().eResource().getURI().segment(1);
String[] names = name.split("::");
if(!names[0].equals("CHESS")){
return null;
}
if (chessProfile == null || (modelHashCode != element.getModel().hashCode())) {
modelHashCode = element.getModel().hashCode();
chessProfile = element.getModel().getAppliedProfile(names[0]);
}
return getStereotype(names,chessProfile);
}
public static Stereotype getCHESSContractStereotype(String name, Element element){
if (modelHashCode == 0) {
modelHashCode = element.getModel().hashCode();
}
//String projectName = element.getModel().eResource().getURI().segment(1);
String[] names = name.split("::");
if(!names[0].equals("CHESSContract")){
return null;
}
if (chessContractProfile == null || (modelHashCode != element.getModel().hashCode())) {
modelHashCode = element.getModel().hashCode();
chessContractProfile = element.getModel().getAppliedProfile(names[0]);
}
return getStereotype(names,chessContractProfile);
}
public static Stereotype getMarteStereotype(String name, Element element){
if (modelHashCode == 0) {
modelHashCode = element.getModel().hashCode();
}
//String projectName = element.getModel().eResource().getURI().segment(1);
String[] names = name.split("::");
if(!names[0].equals("MARTE")){
return null;
}
if (marteProfile == null || (modelHashCode != element.getModel().hashCode())) {
modelHashCode = element.getModel().hashCode();
marteProfile = element.getModel().getAppliedProfile(names[0]);
}
return getStereotype(names,marteProfile);
}
public static Stereotype getSysMLStereotype(String name, Element element){
if (modelHashCode == 0) {
modelHashCode = element.getModel().hashCode();
}
//String projectName = element.getModel().eResource().getURI().segment(1);
String[] names = name.split("::");
if(!names[0].equals("SysML")){
return null;
}
if (sysMLProfile == null || (modelHashCode != element.getModel().hashCode())) {
modelHashCode = element.getModel().hashCode();
sysMLProfile = element.getModel().getAppliedProfile(names[0]);
}
return getStereotype(names,sysMLProfile);
}
private static Stereotype getStereotype(String[] names, Profile profile){
org.eclipse.uml2.uml.Package currPackage = profile;
if(names.length>2){
for(int i = 1; i<names.length-1;i++){
currPackage=currPackage.getNestedPackage(names[i]);
}
}
final String extrName = names[names.length-1];
System.out.println("extrName: "+extrName);
System.out.println("currPackage: "+currPackage);
final Stereotype stereotype = currPackage.getOwnedStereotype(extrName);
if (stereotype == null) {
return null;
}
return stereotype;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment