Class BasicAnnotationValidator
- All Implemented Interfaces:
AnnotationValidator
annotation validator
.
An implementation must specialize the getResourceLocator()
method in order for the getValidLocationDescription()
method to function correctly.
The most straight-forward way to implement an annotation validator is to model the supported keys,
specializing getPropertyClasses(ModelElement)
with one or more classes
that
can be instantiated
to represent the information in the annotation.
These classes are used to induce a mapping
of keys onto the underlying annotation model's features.
If the annotation model includes references,
validateReferenceDetailValueLiteral
and convertPropertyReferenceValueToLiteralItem(EObject, EReference, Object)
must also be specialized.
Alternatively an implementation can specialize validateDetail(Annotation, ModelElement, Map.Entry, DiagnosticChain, Map)
without providing a modeled representation.
The annotation validator's assistant
is especially useful for inducing a user interface based on the modeled annotation representation.
- Since:
- 4.22
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An assistant that is useful for inducing a user interface that represents the annotation information in a more structured way usingmodeled objects
that are created byBasicAnnotationValidator.Assistant.createInstance(EClass, Annotation)
.static class
Context data used byvalidateAttributeDetailValueLiteral
to pass contextual information that can be used when a data type's value isvalidated
.Nested classes/interfaces inherited from interface org.eclipse.emf.cdo.etypes.AnnotationValidator
AnnotationValidator.Registry
-
Field Summary
Modifier and TypeFieldDescriptionprotected final String
The name used in messages for this validator's annotations.protected final String
Theannotation source
validated by this annotation validator.protected final BasicAnnotationValidator.Assistant
Theassistant
used by the framework to induce a user interface.protected final String
Thesource
used in this validator's diagnostics.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionBasicAnnotationValidator
(String annotationSource, String annotationName, String diagnosticSource) Creates an instance for the givenannotation source
validated by this annotation validator. -
Method Summary
Modifier and TypeMethodDescriptionprotected String
convertPropertyAttributeValueToLiteralItem
(EObject eObject, EAttribute eAttribute, Object value) Returns the single value of the attribute'stype
for the modeled object converted to a literal representation as used indetail entry
.protected String
convertPropertyReferenceValueToLiteralItem
(EObject eObject, EReference eReference, Object value) Returns the single value of the references'stype
for the modeled object converted to a literal representation as used indetail entry
.protected String
convertPropertyValueToLiteral
(EObject eObject, EStructuralFeature eStructuralFeature, Object value) Returns the value of the feature of the modeled object converted to a literal representation as used indetail entry
.protected String
convertPropertyValueToLiteralItem
(EObject eObject, EStructuralFeature eStructuralFeature, Object value) Returns the single value of the feature'stype
for the modeled object converted to a literal representation as used indetail entry
.protected BasicAnnotationValidator.Assistant
Creates the assistant.protected BasicDiagnostic
createDiagnostic
(int severity, int code, String message, Object... data) Creates a diagnostic using the given parameters and theannotationSource
.protected EObject
createInstance
(EClass eClass, Annotation annotation) Creates an instance of the modeled representation for the given annotation.protected BasicDiagnostic
createValueDiagnostic
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature) Creates the placeholder diagnostic used byvalidateFeatureDetail
.protected Collection<? extends Annotation>
getAllValidAnnotations
(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> annotations) Returns the filtered collection of nested annotations that are valid for this annotation.Returns theannotation source
of the annotations validated by this annotation validator.Returns the assistant provided by this annotation validator which is generally useful to provide access to protected methods that are needed primarily for inducing a user interface that represents the annotations in a more structured form.protected ResourceLocator
Returns the resource locator for fetching messages supported directly by the base implementation.protected Map<String,
EStructuralFeature> getProperties
(ModelElement modelElement) Returns a map from key tofeature
.getPropertyClasses
(ModelElement modelElement) Returns the model classes used to represent annotations for the given model element.protected abstract ResourceLocator
Returns the resource locator for fetching implementation-specific messages.protected EValidator
getRootEValidator
(Map<Object, Object> context) Returns the root validator of the context.protected String
getString
(ResourceLocator resourceLocator, String key, Object... substitutions) Fetches a translated string from the resource locator using the message key and the give substitutions, if any.protected Collection<? extends Annotation>
getValidAnnotations
(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> annotations) Returns the filtered collection of nested annotations that are valid for this annotation.protected Collection<? extends EObject>
getValidContents
(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> contents) Returns the filtered collection of contents that are valid for this annotation.protected String
Returns a description of the valid locations supported for annotations of this annotation validator.protected Collection<?>
getValidReferences
(Annotation annotation, ModelElement modelElement, Collection<?> references) Returns the filtered collection of references that are valid for this annotation.protected EObject
initialize
(EObject eObject, Annotation annotation) Returns an initialized instance of the given object for the given annotation.protected boolean
isAnnotationsSupported
(Annotation annotation, ModelElement modelElement) Returns whethernested annotations
are meaningful for this annotation.protected boolean
isApplicable
(EObject eObject, EStructuralFeature eStructuralFeature) Returns whether the given feature of the given modeled representation is meaningful for the current state of the model.protected boolean
isContentsSupported
(Annotation annotation, ModelElement modelElement) Returns whethercontents
are meaningful for this annotation.protected boolean
isDuplicateValid
(ModelElement modelElement, Annotation primaryAnnotation, Annotation secondaryAnnotation) Returns whether the given two annotations, both with the annotation validator's annotation source, bothcontained
by the given model element, are valid.protected boolean
isIncludedProperty
(ModelElement modelElement, EClass eClass, EStructuralFeature eStructuralFeature) Returns whether the given structural feature of the given class for the given model element isincluded as a property
.protected boolean
isReferencesSupported
(Annotation annotation, ModelElement modelElement) Returns whetherreferences
are meaningful for this annotation.boolean
isValidLocation
(Annotation annotation) Returns whether this annotation with this annotation validator'sannotation source
is valid at itscurrent location
.protected boolean
isValidLocation
(Annotation annotation, ModelElement modelElement) Returns whether this annotationcontained
by this model element is valid at this location.protected String
join
(EObject eObject, EStructuralFeature eStructuralFeature, List<String> literalValues) Returns the joined list of values of this modeled object's feature.protected static EPackage
loadEPackage
(String uri) Returns the package loaded from the location specified by the given URI.protected void
reportDuplicate
(Annotation primaryAnnotation, Annotation secondaryAnnotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportIgnoredAnnotations
(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> ignoredAnnotations, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportIgnoredContents
(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> ignoredContents, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportIgnoredEntry
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportIgnoredReferences
(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> ignoredReferences, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportInvalidAnnotation
(Annotation annotation, ModelElement modelElement, Annotation nestedAnnotation, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportInvalidContent
(Annotation annotation, ModelElement modelElement, EObject content, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportInvalidLocation
(Annotation annotation, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportInvalidReference
(Annotation annotation, ModelElement modelElement, EObject reference, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportInvalidReferenceLiteral
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, String literalValue, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportInvalidValueLiteral
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, String literalValue, EDataType dataType, DiagnosticChain diagnostics, RuntimeException exception, Map<Object, Object> context) protected void
reportMissingEntry
(Annotation annotation, ModelElement modelElement, String key, EStructuralFeature property, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportMissingRequiredEntryValue
(Annotation annotation, ModelElement modelElement, EStructuralFeature feature, List<Object> values, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportTooFewValues
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, List<Object> values, int size, int lowerBound, DiagnosticChain diagnostics, Map<Object, Object> context) protected void
reportTooManyValues
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, List<Object> values, int size, int upperBound, DiagnosticChain diagnostics, Map<Object, Object> context) split
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, String literalValue, EStructuralFeature feature, DiagnosticChain diagnostics, Map<Object, Object> context) Splits the literal value into a list of literal values as appropriate for this feature.boolean
validate
(Annotation annotation, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation is valid.protected boolean
validateAnnotations
(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'snested annotations
are valid.protected boolean
validateAttributeDetailLiteralValue
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, List<Object> dataValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the literal value of this detail entry for the corresponding attribute is valid.protected boolean
validateAttributeDetailValueLiteral
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, String literalValue, List<Object> dataValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the given literal value is valid with respect to this detail entry's corresponding attribute'sdata type
.protected boolean
validateContents
(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'scontents
are valid.protected boolean
validateDetail
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this detail entry is valid.protected boolean
validateDetails
(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'sdetails
are valid.protected boolean
validateFeatureDetail
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the value of this detail entry for the corresponding feature is valid.protected boolean
validateFeatureDetailValue
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, List<Object> values, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the modeled values for this detail entry's corresponding feature are valid.protected boolean
validateReferenceDetailLiteralValue
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, List<Object> referenceValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the literal value of this detail entry for the corresponding reference is valid.protected boolean
validateReferenceDetailValueLiteral
(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, String literalValue, List<Object> referenceValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the given literal value is valid with respect to this detail entry's corresponding reference'sclass
.protected boolean
validateReferences
(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'sreferences
are valid.
-
Field Details
-
INVALID_LOCATION
public static final int INVALID_LOCATION -
INVALID_DUPLICATE
public static final int INVALID_DUPLICATE -
INVALID_REFERENCE_LITERAL
public static final int INVALID_REFERENCE_LITERAL -
INVALID_DETAIL_VALUE
public static final int INVALID_DETAIL_VALUE -
INVALID_VALUE_LITERAL
public static final int INVALID_VALUE_LITERAL -
IGNORED_ANNOTATIONS
public static final int IGNORED_ANNOTATIONS -
IGNORED_CONTENTS
public static final int IGNORED_CONTENTS -
IGNORED_REFERENCES
public static final int IGNORED_REFERENCES -
INVALID_REFERENCE
public static final int INVALID_REFERENCE -
INVALID_ANNOTATION
public static final int INVALID_ANNOTATION -
INVALID_CONTENT
public static final int INVALID_CONTENT -
IGNORED_ENTRY
public static final int IGNORED_ENTRY -
MISSING_ENTRY
public static final int MISSING_ENTRY -
MISSING_REQUIRED_ENTRY_VALUE
public static final int MISSING_REQUIRED_ENTRY_VALUE -
TOO_FEW_VALUES
public static final int TOO_FEW_VALUES -
TOO_MANY_VALUES
public static final int TOO_MANY_VALUES -
annotationSource
Theannotation source
validated by this annotation validator. -
annotationName
The name used in messages for this validator's annotations. -
diagnosticSource
Thesource
used in this validator's diagnostics. -
assistant
Theassistant
used by the framework to induce a user interface.
-
-
Constructor Details
-
BasicAnnotationValidator
public BasicAnnotationValidator(String annotationSource, String annotationName, String diagnosticSource) Creates an instance for the givenannotation source
validated by this annotation validator.- Parameters:
annotationSource
- the annotation source validated by this annotation validator.annotationName
- the name used in this validator's diagnosticsdiagnosticSource
- thediagnostic source
used in this validator's diagnostics.
-
-
Method Details
-
getAnnotationSource
Returns theannotation source
of the annotations validated by this annotation validator.- Specified by:
getAnnotationSource
in interfaceAnnotationValidator
- Returns:
- the annotation source.
-
getResourceLocator
Returns the resource locator for fetching implementation-specific messages.- Returns:
- the resource locator for fetching model-specific messages.
-
getPropertyClasses
Returns the model classes used to represent annotations for the given model element.Typically an annotation validator implementation will return a single class. An induced user interface will generally require the ability to
create instances
of the classes returned by this method. The annotation validator implementation itself does not require that ability.- Parameters:
modelElement
- the model element in question.- Returns:
- the model classes used to represent annotations for the given model element.
-
getAssistant
Returns the assistant provided by this annotation validator which is generally useful to provide access to protected methods that are needed primarily for inducing a user interface that represents the annotations in a more structured form.- Returns:
- the assistant provided by this annotation validator.
-
createAssistant
Creates the assistant.Generally derived classes will not need to specialize this method because all methods of the assistant delegate back to the annotation validator.
- Returns:
- the assistant.
-
isValidLocation
Returns whether this annotation with this annotation validator'sannotation source
is valid at itscurrent location
.This implementation returns
false
if the containingAnnotation.getModelElement()
isnull
, if theisValidLocation(Annotation, ModelElement)
returnsfalse
for the containing model element, or if this is not the first annotation with this annotation source in the model element andisDuplicateValue
returnsfalse
.- Specified by:
isValidLocation
in interfaceAnnotationValidator
- Parameters:
annotation
- the annotation in question.- Returns:
- whether this annotation with this annotation validator's annotation source is valid at its current location.
-
isValidLocation
Returns whether this annotationcontained
by this model element is valid at this location.This implementation returns
true
. It's typically the case that annotations on annotations aren't meaningful and valid.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.- Returns:
- whether this annotation contained by this model element is valid at this location.
- See Also:
-
isDuplicateValid
protected boolean isDuplicateValid(ModelElement modelElement, Annotation primaryAnnotation, Annotation secondaryAnnotation) Returns whether the given two annotations, both with the annotation validator's annotation source, bothcontained
by the given model element, are valid.This implementation returns
false
because it's typically the case that only the primary annotation is meaningful and valid.- Parameters:
modelElement
- the model element that contains both annotations in itsannotations
feature.primaryAnnotation
- the first annotation in the model element's details.secondaryAnnotation
- a subsequent annotation in the model element's details.- Returns:
- whether these two annotations, both of which have this annotation validator's annotation source, are valid.
- See Also:
-
validate
public boolean validate(Annotation annotation, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation is valid.This implementation checks if the
location is valid
andreports an invalid location
if it is not. Then checks forinvalid duplicates
andreports a duplicate
if it is an invalid duplicate. Then itvalidates the references
andvalidates the details
.- Specified by:
validate
in interfaceAnnotationValidator
- Parameters:
annotation
- the annotation in question.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether this annotation is valid.
- See Also:
-
validateReferences
protected boolean validateReferences(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'sreferences
are valid.This implementation checks whether
references are supported
. If not, it checks whether the references are empty and if notreports ignored references
. If references are supported, then for each reference, it tests whether that reference is among thevalid references
, passing in this annotation's references to determine the valid references, andreports an invalid reference
for each not present in the valid references.It's typically the case that annotations ignore references. If that's not the case, specialize
isReferencesSupported(Annotation, ModelElement)
andgetValidReferences(Annotation, ModelElement, Collection)
. An implementation may override this method to report missing required references.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether this annotation's references are valid.
- See Also:
-
isReferencesSupported
Returns whetherreferences
are meaningful for this annotation.This method used to determine how references should be
validated
. Also, an induced user interface should avoid providing the ability to specify references when this returnsfalse
. Implementations that override this to ever returntrue
should also overridegetValidReferences(Annotation, ModelElement, Collection)
to control the valid choices.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.- Returns:
- whether references are meaningful for this annotation.
- See Also:
-
getValidReferences
protected Collection<?> getValidReferences(Annotation annotation, ModelElement modelElement, Collection<?> references) Returns the filtered collection of references that are valid for this annotation.An induced user interface should provide the ability to specify only the references returned by this method. The references argument may contain all reachable objects, some subset there of, or none at all; an implementation may choose to filter from this collection or to provide its own result, including objects not in this collection. This implementation returns the references argument if
references are supported
, or an empty list otherwise. It is also used todetermine
which references are valid. An implementation that overrides this should also overrideisReferencesSupported(Annotation, ModelElement)
.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.references
- all reachable objects, some subset there of, or none at all.- Returns:
- the objects that are valid as references for this annotation.
- See Also:
-
validateContents
protected boolean validateContents(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'scontents
are valid.This implementation checks whether
contents are supported
. If not, it checks whether the contents are empty and if notreports ignored contents
. If contents are supported, then for each content, it tests whether that content is among thevalid contents
, passing in this annotation's contents to determine the valid contents, andreports an invalid content
for each not present in the valid contents.It's typically the case that annotations ignore contents. If that's not the case, specialize
isContentsSupported(Annotation, ModelElement)
andgetValidContents(Annotation, ModelElement, Collection)
. An implementation may override this method to report missing required contents.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether this annotation's contents are valid.
- See Also:
-
isContentsSupported
Returns whethercontents
are meaningful for this annotation.This method used to determine how contents should be
validated
. Also, an induced user interface should avoid providing the ability to specify contents when this returnsfalse
. Implementations that override this to ever returntrue
should also overridegetValidContents(Annotation, ModelElement, Collection)
to control the valid choices.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.- Returns:
- whether contents are meaningful for this annotation.
- See Also:
-
getValidContents
protected Collection<? extends EObject> getValidContents(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> contents) Returns the filtered collection of contents that are valid for this annotation.An induced user interface should provide the ability to specify only the contents returned by this method. The contents argument may contain nothing at all, or the
current contents
of the annotation; an implementation may choose to filter from this collection or to provide its own result, including objects not in this collection but it should not remove objects currently contained by the annotation that are valid. This implementation returns the contents argument ifcontents are supported
, or an empty list otherwise. It is also used todetermine
which contents are valid and should therefore not remove values from the provided contents argument if they are valid. An implementation that overrides this should also overrideisContentsSupported(Annotation, ModelElement)
.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.contents
- nothing at all, or thecurrent or potential contents
of the annotation.- Returns:
- the objects that are valid as contents for this annotation.
- See Also:
-
validateAnnotations
protected boolean validateAnnotations(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'snested annotations
are valid.This implementation iterates over the nested annotations, and if there is at least one for which there is no
registered annotation validator
or for which the registered annotation validator does not consider this nested annotationvalid at this location
, itreports ignored annotations
. It's typically the case that annotations ignore nested annotations. If that's not the case, you should override this method and specializeisAnnotationsSupported(Annotation, ModelElement)
and consider specializinggetValidAnnotations(Annotation, ModelElement, Collection)
This implementation checks whether
nested annotations are supported
. If not, it checks whether thevalid annotations
, passing in this annotation's nested annotations to determine the valid annotations, contain all the nested annotations; if not itreports ignored annotations
. If nested annotations are supported, then for each nested annotation, it tests whether that annotation is among thevalid annotations
andreports an invalid annotation
for each not present in the valid annotations.It's typically the case that annotations ignore nested annotations. If that's not the case, specialize
isAnnotationsSupported(Annotation, ModelElement)
andgetValidAnnotations(Annotation, ModelElement, Collection)
. An implementation may override this method to report missing required nested annotations.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether this annotation's nested annotations are valid.
- See Also:
-
isAnnotationsSupported
Returns whethernested annotations
are meaningful for this annotation.This method used to determine how nested annotations should be
validated
. Also, an induced user interface should avoid providing the ability to specify nested annotations when this returnsfalse
. Implementations that override this to ever returntrue
should also overridegetValidAnnotations(Annotation, ModelElement, Collection)
to control the valid choices.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.- Returns:
- whether nested annotations are meaningful for this annotation.
- See Also:
-
getValidAnnotations
protected Collection<? extends Annotation> getValidAnnotations(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> annotations) Returns the filtered collection of nested annotations that are valid for this annotation.The annotations argument typically contains the
current nested annotations
of the specified annotation; an implementation may choose to filter from this collection, but it should not remove nested annotations currently contained by the annotation that are valid. This implementation takes into account the fact that annotations may be specifically designed to annotate other annotations, i.e., that the nested annotation source might correspond to aregistered annotation validator
that considers its annotationsvalid
when contained by the specified annotation. As such, this implementation does not remove nested annotations for which there is a registered validator that considers its annotation valid in the specified annotation. Note that this method is used todetermine
which nested annotations are valid and that is why it should not remove values from the provided annotations argument if they are valid.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.annotations
- typically thecurrent nested annotations
of the annotation.- Returns:
- the nested annotations that are valid as annotations for this annotation.
- See Also:
-
getAllValidAnnotations
protected Collection<? extends Annotation> getAllValidAnnotations(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> annotations) Returns the filtered collection of nested annotations that are valid for this annotation.An induced user interface should provide the ability to specify only the nested annotations returned by this method. The annotations argument may contain nothing at all, or the
current nested annotations
of the specified annotation; an implementation may choose to filter from this collection or to provide its own result, including objects not in this collection, but it should not remove nested annotations currently contained by the annotation that are valid. This implementation takes into account the fact that annotations may be specifically designed to annotate other annotations, i.e., that the nested annotation source might correspond to aregistered annotation validator
that considers its annotationsvalid
when contained by the specified annotation. As such, this implementation does not remove nested annotations for which there is a registered validator that considers its annotation valid in the specified annotation. Also, this implementation's result will include an additional annotation for each registered annotation validator that considers its annotations valid when nested in this annotation. In fact, an override should only add values to those returned by this implementation. An implementation that overrides this method should also overrideisAnnotationsSupported(Annotation, ModelElement)
.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.annotations
- nothing at all, or thecurrent or potential nested annotations
of the annotation.- Returns:
- the nested annotations that are valid as annotations for this annotation.
- See Also:
-
validateDetails
protected boolean validateDetails(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'sdetails
are valid.This implementation uses the
properties of the model element
. For each detail, it determines whether there is a corresponding feature in the properties. If not, it validates the detailwithout a property feature
. If so, it validates the detailwith the property feature
. If all the details are valid, it will check whether anyrequired
property feature is absent from the details andreports it missing
.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether this annotation's details are valid.
-
getProperties
Returns a map from key tofeature
. These represents the keys that are considered valid and can be processed by this annotation validator.This implementation uses
getPropertyClasses(ModelElement)
, iterating over each class and each feature of each class, adding to the map eachincluded
feature. If that method returns an empty list, then implementation returns an empty map. In that case,validating the details
of any annotation will report all detail entries as being ignored. An annotation validator implement must override either this method, thegetPropertyClasses
method or thevalidateDetails
method.- Parameters:
modelElement
- the model element that is being annotated.- Returns:
- a map from key to feature.
- See Also:
-
isIncludedProperty
protected boolean isIncludedProperty(ModelElement modelElement, EClass eClass, EStructuralFeature eStructuralFeature) Returns whether the given structural feature of the given class for the given model element isincluded as a property
.- Parameters:
modelElement
- the model element.eClass
- the class used to model the annotation for the model element.eStructuralFeature
- a structural feature of the class.- Returns:
- whether the given structural feature of the given class for the given model element is included as a property.
-
createInstance
Creates an instance of the modeled representation for the given annotation.This implementation
creates
an instance andinitializes
it.- Parameters:
eClass
- the class to be instantiated.annotation
- the annotation with the information that needs to be represented.- Returns:
- creates an instance of the modeled representation for the given annotation.
-
initialize
Returns an initialized instance of the given object for the given annotation.This implementation handles only the case of modeled attributes. For each
detail entry
, it looks up the correspondingproperty
via the key. If it's not anEAttribute
it will throw anUnsupportedOperationException
. If the attribute property ismulti-valued
, itsplits
the detail entry value, andconverts
each literal item into a value of theattribute's data type
. If it's single-valued, the literal value is directly converted to the attributes data type. The resulting list value or single value isreflectively set
into the instance. If the model representation includes references, an annotation validator implementation must specialize this method for theassistant
to function correctly.- Parameters:
eObject
- the object to initialize.annotation
- the annotation used to initialize the object.- Returns:
- an initialized instance.
-
convertPropertyValueToLiteral
protected String convertPropertyValueToLiteral(EObject eObject, EStructuralFeature eStructuralFeature, Object value) Returns the value of the feature of the modeled object converted to a literal representation as used indetail entry
.This implementation handles both
EAttribute
andEReference
. For amulti-valued
feature, itconverts
for each item in the list, andjoins
them into a single string. For a single-valued feature, it returns theconverted
value. This method is not used by the validator but is useful for specializing theBasicAnnotationValidator.Assistant.convertPropertyValueToLiteral(EObject, EStructuralFeature, Object)
.- Parameters:
eObject
- the modeled object.eStructuralFeature
- a feature of that object.value
- the value to converted to a literal representation.- Returns:
- the value of the feature of the modeled object converted to a literal representation.
- See Also:
-
convertPropertyValueToLiteralItem
protected String convertPropertyValueToLiteralItem(EObject eObject, EStructuralFeature eStructuralFeature, Object value) Returns the single value of the feature'stype
for the modeled object converted to a literal representation as used indetail entry
.This implementation delegates to
convertPropertyAttributeValueToLiteralItem(EObject, EAttribute, Object)
orconvertPropertyReferenceValueToLiteralItem(EObject, EReference, Object)
as appropriate.- Parameters:
eObject
- the modeled object.eStructuralFeature
- a feature of that object.value
- the value of the feature's type to converted to a literal representation.- Returns:
- a value of the feature's type converted to a literal representation.
- See Also:
-
convertPropertyAttributeValueToLiteralItem
protected String convertPropertyAttributeValueToLiteralItem(EObject eObject, EAttribute eAttribute, Object value) Returns the single value of the attribute'stype
for the modeled object converted to a literal representation as used indetail entry
.This implementation simple uses
EcoreUtil.convertToString(EDataType, Object)
.- Parameters:
eObject
- the modeled object.eAttribute
- an attribute feature of that object.value
- the value of the feature's type to converted to a literal representation.- Returns:
- a value of the feature's type converted to a literal representation.
- See Also:
-
convertPropertyReferenceValueToLiteralItem
protected String convertPropertyReferenceValueToLiteralItem(EObject eObject, EReference eReference, Object value) Returns the single value of the references'stype
for the modeled object converted to a literal representation as used indetail entry
.This implementation is incomplete. It can't generally be known how to represent a reference to an object. This implementation looks for a feature called "name",
gets
the value, and if it's a string returns it. Failing that, it throws anUnsupportedOperationException
.- Parameters:
eObject
- the modeled object.eReference
- a reference feature of that object.value
- the value of the reference's type to converted to a literal representation.- Returns:
- a value of the references's type converted to a literal representation.
- See Also:
-
join
protected String join(EObject eObject, EStructuralFeature eStructuralFeature, List<String> literalValues) Returns the joined list of values of this modeled object's feature.This implementation simply separates the individual literal value items with a " ".
- Parameters:
eObject
- the modeled object.eStructuralFeature
- a feature of that object.literalValues
- the literal value to join into a single value.
-
isApplicable
Returns whether the given feature of the given modeled representation is meaningful for the current state of the model.This method is used to induce the
applicable properties
by the assistant. It is not directly used by the annotation validator itself. This implementation always returnstrue
.- Parameters:
eObject
- the modeled object in question.eStructuralFeature
- a feature of that object.- Returns:
- whether the given feature of the given modeled representation is meaningful for the current state of the model.
-
validateDetail
protected boolean validateDetail(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this detail entry is valid.This method is only called when there is no
property
associated with this entry'skey
. This implementation alwaysreports an ignored entry
. An annotation validator implementation may choose to support validation by specializing this method, rather thanproviding a modeled representation
, but theassistant
will not provide any useful support.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether this detail entry is valid.
-
validateFeatureDetail
protected boolean validateFeatureDetail(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the value of this detail entry for the corresponding feature is valid.This implementation delegates to
validateAttributeDetail
or tovalidateReferenceDetail
depending on whether the feature is anEAttribute
or anEReference
. Itcreates
a place holder diagnostic that it passed to those methods, so all diagnostics gathered by those methods are grouped aschildren
of the placeholder. Both those methods build the corresponding modeled values as a side-effect. If the detail entry is otherwise valid, the modeled valueis validated
.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.feature
- theproperty
associated with entry.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether the value of this detail entry for the corresponding feature is valid.
-
validateFeatureDetailValue
protected boolean validateFeatureDetailValue(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, List<Object> values, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the modeled values for this detail entry's corresponding feature are valid.For a
many-valued
feature, it validates that thelower
andupper
bounds are respected. For a singled valued feature that isrequired
, it validates that the value is present; in the single-valued case, the values list should contain a single value.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.feature
- theproperty
associated with entry.values
- the list of instance values for this entry.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether the modeled values for this detail entry's corresponding feature are valid.
-
validateAttributeDetailLiteralValue
protected boolean validateAttributeDetailLiteralValue(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, List<Object> dataValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the literal value of this detail entry for the corresponding attribute is valid.This implementation, for a
many-valued
attribute,splits
the detail value, if present, into a list of literal values andvalidates each literal value
. For a single-valued attribute, itdirectly validates
the literal value. As a side-effect, each literal value of a many-valued attribute, or the literal value of a single-valued attribute, is converted to an instance of the attribute'sdata type
and is added to the data values list.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.attribute
- feature theattribute
property
associated with entry.dataValues
- the list in which to accumulate valid instance values.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether the literal value of this detail entry for the corresponding attribute is valid.
- See Also:
-
validateAttributeDetailValueLiteral
protected boolean validateAttributeDetailValueLiteral(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, String literalValue, List<Object> dataValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the given literal value is valid with respect to this detail entry's corresponding attribute'sdata type
. As a side-effect, if the literal value can be converted to an instance value, the corresponding instance value is added to the list of data values.This implementation first tries to
convert
the literal value to an instance value of the data type. If that fails, it creates a diagnostic that includes the exceptionmessage
. Otherwise, it adds the instance value to the list of values andvalidates
the instance value.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.attribute
- feature theattribute
property
associated with entry.literalValue
- the literal value of the data type.dataValues
- the list in which to accumulate a valid instance value.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether the given literal value is valid with respect to this detail entry's corresponding attribute's data type.
-
validateReferenceDetailLiteralValue
protected boolean validateReferenceDetailLiteralValue(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, List<Object> referenceValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the literal value of this detail entry for the corresponding reference is valid.This implementation, for a
many-valued
reference,splits
the detail value, if present, into a list of literal values andvalidates each literal value
. For a single-valued attribute, itdirectly validates
the literal value. As a side-effect, each literal value of a many-valued reference, or the literal value of a single-valued reference, is converted to an instance of the references'sclass
and added to the reference values list.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.reference
- thereference
property
associated with entry.referenceValues
- the list in which to accumulate valid instance values.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether the literal value of this detail entry for the corresponding reference is valid.
-
validateReferenceDetailValueLiteral
protected boolean validateReferenceDetailValueLiteral(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, String literalValue, List<Object> referenceValues, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether the given literal value is valid with respect to this detail entry's corresponding reference'sclass
. As a side-effect, if the literal value can be converted to an instance value, the corresponding instance value is added to the list of reference values.This implementation always returns
false
andreports an invalid reference literal
. An annotation validator implementation that supports reference literals must specialize this method.- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.reference
- thereference
property
associated with entry.literalValue
- the literal value of the class.referenceValues
- the list in which to accumulate valid instance values.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- whether the given literal value is valid with respect to this detail entry's corresponding references's class.
-
split
protected List<String> split(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, String literalValue, EStructuralFeature feature, DiagnosticChain diagnostics, Map<Object, Object> context) Splits the literal value into a list of literal values as appropriate for this feature.This implementation splits the values at whitespace boundaries for all features..
- Parameters:
annotation
- the annotation in question.modelElement
- the annotation'scontaining
model element.entry
- the annotationdetail
in question.literalValue
- a literal value of this feature'stype
.feature
- theproperty
associated with entry.diagnostics
- a place to accumulate diagnostics; if it'snull
, no diagnostics should be produced.context
- a place to cache information, if it'snull
, no cache is supported.- Returns:
- splits the literal value into a list of literal values as appropriate for this feature.
- See Also:
-
reportInvalidReferenceLiteral
protected void reportInvalidReferenceLiteral(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, String literalValue, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportInvalidValueLiteral
protected void reportInvalidValueLiteral(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, String literalValue, EDataType dataType, DiagnosticChain diagnostics, RuntimeException exception, Map<Object, Object> context) - See Also:
-
reportMissingRequiredEntryValue
protected void reportMissingRequiredEntryValue(Annotation annotation, ModelElement modelElement, EStructuralFeature feature, List<Object> values, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportTooFewValues
protected void reportTooFewValues(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, List<Object> values, int size, int lowerBound, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportTooManyValues
protected void reportTooManyValues(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature, List<Object> values, int size, int upperBound, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportInvalidLocation
protected void reportInvalidLocation(Annotation annotation, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportDuplicate
protected void reportDuplicate(Annotation primaryAnnotation, Annotation secondaryAnnotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportIgnoredEntry
protected void reportIgnoredEntry(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportMissingEntry
protected void reportMissingEntry(Annotation annotation, ModelElement modelElement, String key, EStructuralFeature property, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportIgnoredReferences
protected void reportIgnoredReferences(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> ignoredReferences, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportInvalidReference
protected void reportInvalidReference(Annotation annotation, ModelElement modelElement, EObject reference, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportIgnoredContents
protected void reportIgnoredContents(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> ignoredContents, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportInvalidContent
protected void reportInvalidContent(Annotation annotation, ModelElement modelElement, EObject content, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportIgnoredAnnotations
protected void reportIgnoredAnnotations(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> ignoredAnnotations, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
reportInvalidAnnotation
protected void reportInvalidAnnotation(Annotation annotation, ModelElement modelElement, Annotation nestedAnnotation, DiagnosticChain diagnostics, Map<Object, Object> context) - See Also:
-
getValidLocationDescription
Returns a description of the valid locations supported for annotations of this annotation validator.A annotation validator implementation must provide the key
"_UI_Valid" +
in itsannotationName
+ "AnnotationLocation_substitution"resource locator
with a very short description of the valid locations of annotations.- Returns:
- a description of the valid locations supported for annotations of this annotation validator.
- See Also:
-
createValueDiagnostic
protected BasicDiagnostic createValueDiagnostic(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EStructuralFeature feature) Creates the placeholder diagnostic used byvalidateFeatureDetail
. Diagnostics about problems with the value of adetail entry
will be nested aschildren
of this annotation.- Parameters:
annotation
- the annotation.modelElement
- the model element of that annotation.entry
- the entry.feature
- the feature.- Returns:
- Creates a placeholder diagnostic.
-
getEcoreResourceLocator
Returns the resource locator for fetching messages supported directly by the base implementation.- Returns:
- the resource locator for fetching messages supported directly by the base implementation.
-
createDiagnostic
Creates a diagnostic using the given parameters and theannotationSource
.- Parameters:
severity
-code
-message
-data
-- Returns:
- a diagnostic.
-
getString
Fetches a translated string from the resource locator using the message key and the give substitutions, if any.- Parameters:
resourceLocator
-key
-substitutions
-- Returns:
- the translated string for the message key.
-
getRootEValidator
Returns the root validator of the context.- Parameters:
context
- the context.- Returns:
- the root validator
-
loadEPackage
Returns the package loaded from the location specified by the given URI. If the resource loads successfully---the org.eclipse.ecore.xmi jar must be on the class---and it contains anEPackage
, that package is registered in theEPackage.Registry.INSTANCE
.- Parameters:
uri
- the location of a resource containing an EPackage.- Returns:
- the loaded package registered package.
-