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
Nested ClassesModifier and TypeClassDescriptionstatic classAn assistant that is useful for inducing a user interface that represents the annotation information in a more structured way usingmodeled objectsthat are created byBasicAnnotationValidator.Assistant.createInstance(EClass, Annotation).static classContext data used byvalidateAttributeDetailValueLiteralto 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
FieldsModifier and TypeFieldDescriptionprotected final StringThe name used in messages for this validator's annotations.protected final StringTheannotation sourcevalidated by this annotation validator.protected final BasicAnnotationValidator.AssistantTheassistantused by the framework to induce a user interface.protected final StringThesourceused in this validator's diagnostics.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionBasicAnnotationValidator(String annotationSource, String annotationName, String diagnosticSource) Creates an instance for the givenannotation sourcevalidated by this annotation validator. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringconvertPropertyAttributeValueToLiteralItem(EObject eObject, EAttribute eAttribute, Object value) Returns the single value of the attribute'stypefor the modeled object converted to a literal representation as used indetail entry.protected StringconvertPropertyReferenceValueToLiteralItem(EObject eObject, EReference eReference, Object value) Returns the single value of the references'stypefor the modeled object converted to a literal representation as used indetail entry.protected StringconvertPropertyValueToLiteral(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 StringconvertPropertyValueToLiteralItem(EObject eObject, EStructuralFeature eStructuralFeature, Object value) Returns the single value of the feature'stypefor the modeled object converted to a literal representation as used indetail entry.protected BasicAnnotationValidator.AssistantCreates the assistant.protected BasicDiagnosticcreateDiagnostic(int severity, int code, String message, Object... data) Creates a diagnostic using the given parameters and theannotationSource.protected EObjectcreateInstance(EClass eClass, Annotation annotation) Creates an instance of the modeled representation for the given annotation.protected BasicDiagnosticcreateValueDiagnostic(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 sourceof 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 ResourceLocatorReturns 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 ResourceLocatorReturns the resource locator for fetching implementation-specific messages.protected EValidatorgetRootEValidator(Map<Object, Object> context) Returns the root validator of the context.protected StringgetString(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 StringReturns 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 EObjectinitialize(EObject eObject, Annotation annotation) Returns an initialized instance of the given object for the given annotation.protected booleanisAnnotationsSupported(Annotation annotation, ModelElement modelElement) Returns whethernested annotationsare meaningful for this annotation.protected booleanisApplicable(EObject eObject, EStructuralFeature eStructuralFeature) Returns whether the given feature of the given modeled representation is meaningful for the current state of the model.protected booleanisContentsSupported(Annotation annotation, ModelElement modelElement) Returns whethercontentsare meaningful for this annotation.protected booleanisDuplicateValid(ModelElement modelElement, Annotation primaryAnnotation, Annotation secondaryAnnotation) Returns whether the given two annotations, both with the annotation validator's annotation source, bothcontainedby the given model element, are valid.protected booleanisIncludedProperty(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 booleanisReferencesSupported(Annotation annotation, ModelElement modelElement) Returns whetherreferencesare meaningful for this annotation.booleanisValidLocation(Annotation annotation) Returns whether this annotation with this annotation validator'sannotation sourceis valid at itscurrent location.protected booleanisValidLocation(Annotation annotation, ModelElement modelElement) Returns whether this annotationcontainedby this model element is valid at this location.protected Stringjoin(EObject eObject, EStructuralFeature eStructuralFeature, List<String> literalValues) Returns the joined list of values of this modeled object's feature.protected static EPackageloadEPackage(String uri) Returns the package loaded from the location specified by the given URI.protected voidreportDuplicate(Annotation primaryAnnotation, Annotation secondaryAnnotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportIgnoredAnnotations(Annotation annotation, ModelElement modelElement, Collection<? extends Annotation> ignoredAnnotations, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportIgnoredContents(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> ignoredContents, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportIgnoredEntry(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportIgnoredReferences(Annotation annotation, ModelElement modelElement, Collection<? extends EObject> ignoredReferences, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportInvalidAnnotation(Annotation annotation, ModelElement modelElement, Annotation nestedAnnotation, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportInvalidContent(Annotation annotation, ModelElement modelElement, EObject content, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportInvalidLocation(Annotation annotation, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportInvalidReference(Annotation annotation, ModelElement modelElement, EObject reference, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportInvalidReferenceLiteral(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EReference reference, String literalValue, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportInvalidValueLiteral(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, EAttribute attribute, String literalValue, EDataType dataType, DiagnosticChain diagnostics, RuntimeException exception, Map<Object, Object> context) protected voidreportMissingEntry(Annotation annotation, ModelElement modelElement, String key, EStructuralFeature property, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportMissingRequiredEntryValue(Annotation annotation, ModelElement modelElement, EStructuralFeature feature, List<Object> values, DiagnosticChain diagnostics, Map<Object, Object> context) protected voidreportTooFewValues(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 voidreportTooManyValues(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.booleanvalidate(Annotation annotation, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation is valid.protected booleanvalidateAnnotations(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'snested annotationsare valid.protected booleanvalidateAttributeDetailLiteralValue(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 booleanvalidateAttributeDetailValueLiteral(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 booleanvalidateContents(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'scontentsare valid.protected booleanvalidateDetail(Annotation annotation, ModelElement modelElement, Map.Entry<String, String> entry, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this detail entry is valid.protected booleanvalidateDetails(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'sdetailsare valid.protected booleanvalidateFeatureDetail(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 booleanvalidateFeatureDetailValue(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 booleanvalidateReferenceDetailLiteralValue(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 booleanvalidateReferenceDetailValueLiteral(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 booleanvalidateReferences(Annotation annotation, ModelElement modelElement, DiagnosticChain diagnostics, Map<Object, Object> context) Returns whether this annotation'sreferencesare 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 sourcevalidated by this annotation validator. -
annotationName
The name used in messages for this validator's annotations. -
diagnosticSource
Thesourceused in this validator's diagnostics. -
assistant
Theassistantused 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 sourcevalidated by this annotation validator.- Parameters:
annotationSource- the annotation source validated by this annotation validator.annotationName- the name used in this validator's diagnosticsdiagnosticSource- thediagnostic sourceused in this validator's diagnostics.
-
-
Method Details
-
getAnnotationSource
Returns theannotation sourceof the annotations validated by this annotation validator.- Specified by:
getAnnotationSourcein 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 instancesof 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 sourceis valid at itscurrent location.This implementation returns
falseif the containingAnnotation.getModelElement()isnull, if theisValidLocation(Annotation, ModelElement)returnsfalsefor the containing model element, or if this is not the first annotation with this annotation source in the model element andisDuplicateValuereturnsfalse.- Specified by:
isValidLocationin 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 annotationcontainedby 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'scontainingmodel 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, bothcontainedby the given model element, are valid.This implementation returns
falsebecause it's typically the case that only the primary annotation is meaningful and valid.- Parameters:
modelElement- the model element that contains both annotations in itsannotationsfeature.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 validandreports an invalid locationif it is not. Then checks forinvalid duplicatesandreports a duplicateif it is an invalid duplicate. Then itvalidates the referencesandvalidates the details.- Specified by:
validatein 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'sreferencesare 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 referencefor 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'scontainingmodel 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 whetherreferencesare 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 returntrueshould also overridegetValidReferences(Annotation, ModelElement, Collection)to control the valid choices.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel 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 todeterminewhich references are valid. An implementation that overrides this should also overrideisReferencesSupported(Annotation, ModelElement).- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel 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'scontentsare 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 contentfor 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'scontainingmodel 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 whethercontentsare 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 returntrueshould also overridegetValidContents(Annotation, ModelElement, Collection)to control the valid choices.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel 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 contentsof 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 todeterminewhich 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'scontainingmodel element.contents- nothing at all, or thecurrent or potential contentsof 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 annotationsare valid.This implementation iterates over the nested annotations, and if there is at least one for which there is no
registered annotation validatoror 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 annotationsandreports an invalid annotationfor 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'scontainingmodel 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 annotationsare 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 returntrueshould also overridegetValidAnnotations(Annotation, ModelElement, Collection)to control the valid choices.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel 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 annotationsof 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 validatorthat considers its annotationsvalidwhen 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 todeterminewhich 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'scontainingmodel element.annotations- typically thecurrent nested annotationsof 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 annotationsof 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 validatorthat considers its annotationsvalidwhen 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'scontainingmodel element.annotations- nothing at all, or thecurrent or potential nested annotationsof 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'sdetailsare 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 anyrequiredproperty feature is absent from the details andreports it missing.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel 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 eachincludedfeature. If that method returns an empty list, then implementation returns an empty map. In that case,validating the detailsof any annotation will report all detail entries as being ignored. An annotation validator implement must override either this method, thegetPropertyClassesmethod or thevalidateDetailsmethod.- 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
createsan instance andinitializesit.- 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 correspondingpropertyvia the key. If it's not anEAttributeit will throw anUnsupportedOperationException. If the attribute property ismulti-valued, itsplitsthe detail entry value, andconvertseach 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 setinto the instance. If the model representation includes references, an annotation validator implementation must specialize this method for theassistantto 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
EAttributeandEReference. For amulti-valuedfeature, itconvertsfor each item in the list, andjoinsthem into a single string. For a single-valued feature, it returns theconvertedvalue. 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'stypefor 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'stypefor 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'stypefor 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",
getsthe 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 propertiesby 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
propertyassociated 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 theassistantwill not provide any useful support.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel element.entry- the annotationdetailin 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
validateAttributeDetailor tovalidateReferenceDetaildepending on whether the feature is anEAttributeor anEReference. Itcreatesa place holder diagnostic that it passed to those methods, so all diagnostics gathered by those methods are grouped aschildrenof 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'scontainingmodel element.entry- the annotationdetailin question.feature- thepropertyassociated 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-valuedfeature, it validates that thelowerandupperbounds 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'scontainingmodel element.entry- the annotationdetailin question.feature- thepropertyassociated 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-valuedattribute,splitsthe detail value, if present, into a list of literal values andvalidates each literal value. For a single-valued attribute, itdirectly validatesthe 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 typeand is added to the data values list.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel element.entry- the annotationdetailin question.attribute- feature theattributepropertyassociated 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
convertthe 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 andvalidatesthe instance value.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel element.entry- the annotationdetailin question.attribute- feature theattributepropertyassociated 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-valuedreference,splitsthe detail value, if present, into a list of literal values andvalidates each literal value. For a single-valued attribute, itdirectly validatesthe 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'sclassand added to the reference values list.- Parameters:
annotation- the annotation in question.modelElement- the annotation'scontainingmodel element.entry- the annotationdetailin question.reference- thereferencepropertyassociated 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
falseandreports 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'scontainingmodel element.entry- the annotationdetailin question.reference- thereferencepropertyassociated 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'scontainingmodel element.entry- the annotationdetailin question.literalValue- a literal value of this feature'stype.feature- thepropertyassociated 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 locatorwith 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 entrywill be nested aschildrenof 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.
-