Skip to content
Snippets Groups Projects
Commit 64bfdee6 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

new constraint system

refs 2334
parent 96f98fb2
No related branches found
No related tags found
No related merge requests found
......@@ -133,7 +133,7 @@
<details key="documentation" value="Constraint. Can be anything as long as there is a corresponding ConstraintVerifier."/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="constrainedsWithChecksum"
upperBound="-1" eType="#//constraints/ConstrainedWithChecksum"/>
upperBound="-1" eType="#//constraints/ConstrainedWithChecksum" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="verificationStatus" eType="#//constraints/IConstraintVerificationStatus"
containment="true"/>
</eClassifiers>
......
......@@ -12,7 +12,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
......@@ -154,6 +156,7 @@ public final class ConstraintVerificationService extends
/**
* @param constrained
* @param constraint
* @return The object to be used to compute the check sum.
* Generally, all verification statuses and checksums are removed. Each verifier can
* also provide per-constraint adaptations.
......@@ -211,4 +214,25 @@ public final class ConstraintVerificationService extends
protected String getClassConfigurationElement() {
return "constraint";
}
/** {@inheritDoc} */
@Override
public void setConstrained(IConstraint constraint, IConstrained constrained, int index) {
EList<ConstrainedWithChecksum> cwcs = constraint.getConstrainedsWithChecksum();
if(cwcs.size() <= index) {
for(int i = cwcs.size(); i <= index; i++) {
cwcs.add(i, ConstraintsFactory.eINSTANCE.createConstrainedWithChecksum());
}
}
ConstrainedWithChecksum cwc = cwcs.get(index);
cwc.setConstrained(constrained);
cwc.setChecksum(computeCheckSum(constrained, constraint));
}
/** {@inheritDoc} */
@Override
public void
removeMatchingConstraints(IConstrained constrained, Predicate<IConstraint> predicate) {
constrained.getConstraints().removeIf(predicate);
}
}
......@@ -2,8 +2,11 @@ package org.fortiss.tooling.kernel.service;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import org.fortiss.tooling.kernel.internal.ConstraintVerificationService;
import org.fortiss.tooling.kernel.model.constraints.ErrorVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
import org.fortiss.tooling.kernel.model.constraints.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus;
......@@ -49,6 +52,8 @@ public interface IConstraintVerificationService {
public void runFix(IConstraintVerificationStatus status);
}
/** Utils. We store them to avoid having again thousands of different classes for one topic. */
/** Base for fixes. */
public static class FixBase implements IFix {
/** The description. */
......@@ -75,4 +80,37 @@ public interface IConstraintVerificationService {
fix.accept(status);
}
}
/**
* @param constraint
* @param constrained
* @param index
* Sets the constrained number <code>index</code> of <code>constraint</code> to
* <code>constrained</code>.
* Leaves the other elements as they are if they exist, fill them with
* <code>null</code> till <code>index</code> otherwise.
*/
public void setConstrained(IConstraint constraint, IConstrained constrained, int index);
/** Exception which embeds an error. */
public static class ErrorEmbeddingException extends RuntimeException {
/** The embedded error. */
public ErrorVerificationStatus error;
/** Constructor. */
public ErrorEmbeddingException(ErrorVerificationStatus error) {
super();
this.error = error;
}
}
/**
* @param constrained
* @param predicate
* Removes any constraint matching <code>predicate</code> from
* <code>constrained</code>.
*/
public void
removeMatchingConstraints(IConstrained constrained, Predicate<IConstraint> predicate);
}
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