Bug 534312 - Wrong constraint DistributedProperty
- check stereotype on property owner
- add quick fixes to offer stereotype application for missing
stereotypes
Change-Id: Icca8091c35427a8e800611733121dc4271c7fd69
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
diff --git a/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/quickfix/SysMLMarkerResolutionGenerator.java b/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/quickfix/SysMLMarkerResolutionGenerator.java
index e6c237a..af34c41 100644
--- a/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/quickfix/SysMLMarkerResolutionGenerator.java
+++ b/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/quickfix/SysMLMarkerResolutionGenerator.java
@@ -12,12 +12,17 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml14.validation.quickfix;
+import java.util.Optional;
+
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.Property;
/**
* Provide the list of specific solutions for problems related to SysML 1.4
@@ -26,7 +31,7 @@
public IMarkerResolution[] getResolutions(IMarker mk) {
try {
- //mk.getAttributes().forEach((k,v)->System.out.println("(" + k + " , " + v+")"));
+
Object source = mk.getAttribute("source");
if (source instanceof String) {
switch ((String)source) {
@@ -50,10 +55,28 @@
case "org.eclipse.papyrus.sysml14.validation.constraint.block.specialization":
return new IMarkerResolution[] {
new ConsumerElementMarkerResolution<Element>("Apply Block stereotype", element -> element.applyStereotype(element.getApplicableStereotype("SysML::Blocks::Block"))),
- };
-
-
+ };
+ case "org.eclipse.papyrus.sysml14.validation.constraint.propertyspecifictype.missingname":
+ return new IMarkerResolution[] {
+ new ConsumerElementMarkerResolution<Classifier>("Empty classifier name", classifier -> classifier.setName(null)),
+ };
+ case "org.eclipse.papyrus.sysml14.validation.constraint.requirement.nogeneralization":
+ return new IMarkerResolution[] {
+ new ConsumerElementMarkerResolution<Class>("Destroy the generalisation", clazz -> clazz.getGeneralizations().forEach(Element::destroy)),
+ };
+ case "org.eclipse.papyrus.sysml14.validation.constraint.connectorproperty.onlyonblock":
+ return new IMarkerResolution[] {
+ new ConsumerElementMarkerResolution<Property>("Apply Block stereotype on owner", property -> property.getOwner().applyStereotype(property.getOwner().getApplicableStereotype("SysML::Blocks::Block"))),
+ };
+ case "org.eclipse.papyrus.sysml14.validation.constraint.distributedproperty.typedby":
+ return new IMarkerResolution[] {
+ new ConsumerElementMarkerResolution<Property>("Apply Block stereotype on owner",
+ property -> Optional.ofNullable(property.getOwner().getApplicableStereotype("SysML::Blocks::Block")).ifPresent(applicableStereotype -> property.getOwner().applyStereotype(applicableStereotype))),
+ new ConsumerElementMarkerResolution<Property>("Apply ValueType stereotype on owner",
+ property -> Optional.ofNullable(property.getOwner().getApplicableStereotype("SysML::Blocks::ValueType")).ifPresent(applicableStereotype -> property.getOwner().applyStereotype(applicableStereotype))),
+ };
default:
+ // mk.getAttributes().forEach((k, v) -> System.out.println("(" + k + " , " + v + ")"));
break;
}
}
diff --git a/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/rules/blocks/DistributedPropertyTypedByModelConstraint.java b/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/rules/blocks/DistributedPropertyTypedByModelConstraint.java
index 3aea60b..053cd98 100644
--- a/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/rules/blocks/DistributedPropertyTypedByModelConstraint.java
+++ b/core/org.eclipse.papyrus.sysml14.validation/src/org/eclipse/papyrus/sysml14/validation/rules/blocks/DistributedPropertyTypedByModelConstraint.java
@@ -18,8 +18,8 @@
import org.eclipse.papyrus.sysml14.blocks.Block;
import org.eclipse.papyrus.sysml14.blocks.DistributedProperty;
import org.eclipse.papyrus.sysml14.blocks.ValueType;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.util.UMLUtil;
/**
@@ -40,10 +40,10 @@
DistributedProperty distributedProperty = (DistributedProperty) context.getTarget();
Property property = distributedProperty.getBase_Property();
if (property != null) {
- Type type = property.getType();
- if (type != null) {
- if (UMLUtil.getStereotypeApplication(type, ValueType.class) == null
- && UMLUtil.getStereotypeApplication(type, Block.class) == null) {
+ Element owner = property.getOwner();
+ if (owner != null) {
+ if (UMLUtil.getStereotypeApplication(owner, ValueType.class) == null
+ && UMLUtil.getStereotypeApplication(owner, Block.class) == null) {
return context.createFailureStatus(context.getTarget());
}
}