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

RED

refs 2490
parent 912d7147
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ import org.fortiss.tooling.kernel.service.IConstraintVerificationService.IFix;
/**
* Utility methods for dealing with constraints.
* TODO(VA): @Flo can you review this?
*
* @author aravantinos
* @author $Author$
......@@ -40,21 +41,8 @@ import org.fortiss.tooling.kernel.service.IConstraintVerificationService.IFix;
* @ConQAT.Rating YELLOW Hash: 24089C9BFEF4DA99D78CDE0C2DCE2996
*/
public class ConstraintsUtils {
/**
* @param c
* @param id
* @return <code>true</code> if <code>c</code> contains a constraint of constraint type ID
* <code>id</code>.
*/
public static boolean containsConstraintOfType(IConstrained c, String id) {
return getConstraintOfType(c, id) != null;
}
/**
* @param c
* @param id
* @return the first constraint of <code>c</code> of constraint type ID <code>id</code>.
*/
/** @return the first constraint of <code>c</code> of constraint type ID <code>id</code>. */
public static ConstraintInstance getConstraintOfType(IConstrained c, String id) {
try {
return c.getConstraints().stream().filter(x -> x.getConstraintID().equals(id))
......@@ -64,7 +52,7 @@ public class ConstraintsUtils {
}
}
/** Exception which embeds an error. */
/** Exception which embeds a constraint error status. */
public static class ErrorEmbeddingException extends RuntimeException {
/** The embedded error. */
......@@ -77,10 +65,7 @@ public class ConstraintsUtils {
}
}
/**
* @param c
* @return A "success" verification status for <code>c</code>.
*/
/** @return A "success" verification status for <code>c</code>. */
public static SuccessVerificationStatus createSuccessVerificationStatus(ConstraintInstance c) {
SuccessVerificationStatus s =
ConstraintsFactory.eINSTANCE.createSuccessVerificationStatus();
......@@ -88,10 +73,7 @@ public class ConstraintsUtils {
return s;
}
/**
* @param c
* @return A "outdated" verification status for <code>c</code>.
*/
/** @return A "outdated" verification status for <code>c</code>. */
public static OutdatedVerificationStatus createOutdatedVerificationStatus(ConstraintInstance c) {
OutdatedVerificationStatus status;
if(c.getVerificationStatus() instanceof OutdatedVerificationStatus) {
......@@ -103,20 +85,14 @@ public class ConstraintsUtils {
return status;
}
/**
* @param c
* @return A "fail" verification status for <code>c</code>.
*/
/** @return A "fail" verification status for <code>c</code>. */
public static FailVerificationStatus createFailVerificationStatus(ConstraintInstance c) {
FailVerificationStatus status = ConstraintsFactory.eINSTANCE.createFailVerificationStatus();
c.setVerificationStatus(status);
return status;
}
/**
* @param c
* @return An "error" verification status for <code>c</code>.
*/
/** @return An "error" verification status for <code>c</code>. */
public static ErrorVerificationStatus createErrorVerificationStatus(ConstraintInstance c) {
ErrorVerificationStatus status =
ConstraintsFactory.eINSTANCE.createErrorVerificationStatus();
......@@ -124,41 +100,27 @@ public class ConstraintsUtils {
return status;
}
/**
* @param c
* @return the first element constrained by <code>c</code>
*/
/** @return the first element constrained by <code>c</code> */
public static IConstrained getFirstConstrained(ConstraintInstance c) {
// get(0) because the constraint shall contain at least one constrained element
// (responsibility of the caller!) and because we want the first element
return c.getConstrainedsWithChecksum().get(0).getConstrained();
}
/**
* @param constraint
* @param constrained
* Sets the constrained element of <code>constraint</code>
*/
/** Sets the first constrained element of <code>constraint</code> to <code>constrained</code>. */
public static void setFirstConstrained(ConstraintInstance constraint, IConstrained constrained) {
IConstraintVerificationService.getInstance().setConstrainedElement(constraint, constrained,
0);
}
/**
* @param c
* @return the second element constrained by <code>c</code>
*/
/** @return the second element constrained by <code>c</code> */
public static IConstrained getSecondConstrained(ConstraintInstance c) {
// get(1) because the constraint shall contain at least one constrained element
// (responsibility of the caller!) and because we want the first element
return c.getConstrainedsWithChecksum().get(1).getConstrained();
}
/**
* @param constraint
* @param constrained
* Sets the constrained element of <code>constraint</code>
*/
/** Sets the second constrained element of <code>constraint</code> to <code>constrained</code>. */
public static void
setSecondConstrained(ConstraintInstance constraint, IConstrained constrained) {
IConstraintVerificationService.getInstance().setConstrainedElement(constraint, constrained,
......@@ -166,7 +128,6 @@ public class ConstraintsUtils {
}
/**
* @param c
* @return the element constrained by <code>constraint</code>.
* Use this function if your constraint constrains only one element!
*/
......@@ -175,21 +136,15 @@ public class ConstraintsUtils {
}
/**
* @param constraint
* @param constrained
* Sets the constrained element of <code>constraint</code>.
* Use this function if your constraint constrains only one element!
* Sets the constrained element of <code>constraint</code> to <code>constrained</code>.
* Use this function if your constraint constrains only one element!
*/
public static void setConstrained(ConstraintInstance constraint, IConstrained constrained) {
IConstraintVerificationService.getInstance().setConstrainedElement(constraint, constrained,
0);
}
/**
* @param id
* @param constrained
* @return a constraint of ID <code>id</code> constraining <code>constrained</code>
*/
/** @return a constraint of ID <code>id</code> constraining <code>constrained</code> */
public static ConstraintInstance createConstraint(String id, IConstrained constrained) {
ConstraintInstance c = ConstraintsFactory.eINSTANCE.createConstraintInstance();
c.setConstraintID(id);
......@@ -199,9 +154,6 @@ public class ConstraintsUtils {
}
/**
* @param id
* @param constrained1
* @param constrained2
* @return a constraint of ID <code>id</code> constraining <code>constrained1</code> and
* <code>constrained2</code>.
*/
......
......@@ -70,21 +70,10 @@ public class EcoreUtils {
EVENT_TYPE_COUNT + 1, null, null);
/**
* <p>
* Converts an {@link EList} of a given type into an {@link EList} of one of its subtypes.
* </p>
* <p>
* Utility method to avoid unnecessary casts.
* </p>
*
* @param targetClass
* the class representing the subtype.
* @param sourceList
* the source list containing objects of type <code>S</code>, a supertype of
* <code>T</code>.
* @return a target EList containing elements of type <code>targetClazz</code>.
* Same as org.fortiss.tooling.kernel.utils.JavaUtils.convertList(Class<T>, List<S>) but with
* {@link EList} instead of {@link List}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "unused"})
public static <S, T extends S> EList<T> convertList(Class<T> targetClass, EList<S> sourceList) {
return (EList<T>)(EList<?>)sourceList;
}
......@@ -111,6 +100,9 @@ public class EcoreUtils {
}
/**
* TODO(VA) This method is a lot of copy-pasting to the next method, could be easily replaced by
* just a call to it.
*
* From a given {@link EList} with objects of type <code>S</code>, create another unmodifiable
* {@link EList} with objects of type <code>T</code>. The resulting {@link EList} is
* unmodifiable thereby it represents only a view over the source list.
......@@ -195,6 +187,8 @@ public class EcoreUtils {
}
/**
* TODO(VA) This method could easily (and should IMHO) make reuse of pickInstanceOf above.
*
* From a given {@link EList} with source objects of type <code>S</code> pick the first object
* with type <code>T</code>, whereby <code>T</code> is a sub-type of <code>S</code>.
*
......@@ -267,14 +261,14 @@ public class EcoreUtils {
}
/**
* Returns a list of all parent {@link EObject}s that have the type <code>T</code>. If none are
* found, an empty list is returned.
* Returns a list of all parent {@link EObject}s that have the type <code>type</code>. If none
* are found, an empty list is returned.
*
* @param startElement
* The {@link EObject} from which the "upwards" search shall begin.
* @param type
* The class type which is used to filter the search.
* @return List of parent {EObject}s of type <code>T</code>.
* @return List of parent {@link EObject}s of type <code>type</code>.
*/
@SuppressWarnings("unchecked")
public static <T extends EObject> EList<T> getParentsWithType(EObject startElement,
......@@ -293,6 +287,10 @@ public class EcoreUtils {
}
/**
* TODO(VA) This method is a lot of copy-pasting of the method above. It could instead make use
* of the method above, returning null if empty or the first element in the list.
* -> the method was written by Andreas so it should be forwarded to him
*
* Returns the first parent {@link EObject} that has the type <code>T</code>. If none are
* found, null is returned.
*
......@@ -506,7 +504,7 @@ public class EcoreUtils {
* </p>
*
* @param element
* The element for whom and its children the notifications shall be disabled.
* The element for which and its children the notifications shall be disabled.
*
* @return {@code true}, if the notifications can be disabled for the given {@link EObject}
*/
......@@ -518,7 +516,7 @@ public class EcoreUtils {
* Enables the notifications for the given {@link EObject} and its children.
*
* @param element
* The element for whom and its children the notifications shall be enabled.
* The element for which and its children the notifications shall be enabled.
*
* @return {@code true}, if the notifications can be disabled for the given {@link EObject}
*/
......@@ -530,7 +528,7 @@ public class EcoreUtils {
* Sets the notification state for the given {@link EObject} and its children.
*
* @param element
* The element for whom and its children the notification state should be.
* The element for which and its children the notification state should be.
*
* @param value
* Whether to enable or disable notifications of the given {@code element}.
......
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