Skip to content

Commit 9c3e4aa

Browse files
committed
KERML_-119 Added new validation checks for Annotations.
1 parent 57c4019 commit 9c3e4aa

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

org.omg.kerml.xtext/src/org/omg/kerml/xtext/validation/KerMLValidator.xtend

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import org.omg.sysml.lang.sysml.VisibilityKind
9393
import org.omg.sysml.lang.sysml.Structure
9494
import org.omg.sysml.lang.sysml.CrossSubsetting
9595
import java.util.Set
96+
import org.omg.sysml.lang.sysml.Annotation
9697

9798
/**
9899
* This class contains custom validation rules.
@@ -105,6 +106,13 @@ class KerMLValidator extends AbstractKerMLValidator {
105106

106107
public static val INVALID_ELEMENT_IS_IMPLIED_INCLUDED = "validateElementIsImpliedIncluded"
107108
public static val INVALID_ELEMENT_IS_IMPLIED_INCLUDED_MSG = "Element cannot have implied relationships included"
109+
110+
public static val INVALID_ANNOTATION_ANNOTATING_ELEMENT = "validateAnnotationAnnotatingElement"
111+
public static val INVALID_ANNOTATION_ANNOTATING_ELEMENT_MSG = "Must either own or be owned by its annotating element"
112+
113+
public static val INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP = "validateAnnotationAnnotatedElementOwnership"
114+
public static val INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP_MSG_1 = "Must own its annotating element"
115+
public static val INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP_MSG_2 = "Must be owned by its annotated element"
108116

109117
public static val INVALID_NAMESPACE_DISTINGUISHABILITY = "validateNamespaceDistinguishablity"
110118
public static val INVALID_NAMESPACE_DISTINGUISHABILITY_MSG = "Duplicate of other owned member name"
@@ -315,6 +323,26 @@ class KerMLValidator extends AbstractKerMLValidator {
315323
}
316324
}
317325

326+
@Check
327+
def checkAnnotation(Annotation ann) {
328+
// validateAnnotationAnnotatingElement
329+
val ownedAnnotatingElement = ann.ownedAnnotatingElement
330+
val owningAnnotatingElement = ann.owningAnnotatingElement
331+
if (ownedAnnotatingElement === null && owningAnnotatingElement === null ||
332+
ownedAnnotatingElement !== null && owningAnnotatingElement !== null) {
333+
error(INVALID_ANNOTATION_ANNOTATING_ELEMENT_MSG, ann, null, INVALID_ANNOTATION_ANNOTATING_ELEMENT)
334+
}
335+
336+
// validateAnnotationAnnotatedElementOwnership
337+
val owningAnnotatedElement = ann.owningAnnotatedElement
338+
if (owningAnnotatedElement !== null && ownedAnnotatingElement === null) {
339+
error(INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP_MSG_1, ann, null, INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP)
340+
}
341+
if (owningAnnotatedElement === null && ownedAnnotatingElement !== null) {
342+
error(INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP_MSG_2, ann, null, INVALID_ANNOTATION_ANNOTATED_ELEMNT_OWNERSHIP)
343+
}
344+
}
345+
318346
@Check
319347
def checkNamespace(Namespace namesp) {
320348
// validateNamespaceDistinguishability

0 commit comments

Comments
 (0)