public abstract class BasicEAnnotationValidator extends java.lang.Object implements EAnnotationValidator
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(EModelElement) 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(EAnnotation, EModelElement, 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.
EAnnotationValidator,
BasicEAnnotationValidator.Assistant| Modifier and Type | Class and Description |
|---|---|
static class |
BasicEAnnotationValidator.Assistant
An assistant that is useful for inducing a user interface that represents the annotation information in a more structured way
using
modeled objects that are created by BasicEAnnotationValidator.Assistant.createInstance(EClass, EAnnotation). |
static class |
BasicEAnnotationValidator.ValidationContext
Context data used by
validateAttributeDetailValueLiteral
to pass contextual information that can be used when a data type's value is validated. |
EAnnotationValidator.Descriptor, EAnnotationValidator.Registry| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
annotationName
The name used in messages for this validator's annotations.
|
protected java.lang.String |
annotationSource
The
annotation source validated by this annotation validator. |
protected BasicEAnnotationValidator.Assistant |
assistant
The
assistant used by the framework to induce a user interface. |
protected java.lang.String |
diagnosticSource
The
source used in this validator's diagnostics. |
static int |
IGNORED_ANNOTATIONS |
static int |
IGNORED_CONTENTS |
static int |
IGNORED_ENTRY |
static int |
IGNORED_REFERENCES |
static int |
INVALID_ANNOTATION |
static int |
INVALID_CONTENT |
static int |
INVALID_DETAIL_VALUE |
static int |
INVALID_DUPLICATE |
static int |
INVALID_LOCATION |
static int |
INVALID_REFERENCE |
static int |
INVALID_REFERENCE_LITERAL |
static int |
INVALID_VALUE_LITERAL |
static int |
MISSING_ENTRY |
static int |
MISSING_REQUIRED_ENTRY_VALUE |
static int |
TOO_FEW_VALUES |
static int |
TOO_MANY_VALUES |
| Constructor and Description |
|---|
BasicEAnnotationValidator(java.lang.String annotationSource,
java.lang.String annotationName,
java.lang.String diagnosticSource)
Creates an instance for the given
annotation source validated by this annotation validator. |
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.String |
convertPropertyAttributeValueToLiteralItem(EObject eObject,
EAttribute eAttribute,
java.lang.Object value)
Returns the single value of the attribute's
type for the modeled object converted to a literal representation as used in detail entry. |
protected java.lang.String |
convertPropertyReferenceValueToLiteralItem(EObject eObject,
EReference eReference,
java.lang.Object value)
Returns the single value of the references's
type for the modeled object converted to a literal representation as used in detail entry. |
protected java.lang.String |
convertPropertyValueToLiteral(EObject eObject,
EStructuralFeature eStructuralFeature,
java.lang.Object value)
Returns the value of the feature of the modeled object converted to a literal representation as used in
detail entry. |
protected java.lang.String |
convertPropertyValueToLiteralItem(EObject eObject,
EStructuralFeature eStructuralFeature,
java.lang.Object value)
Returns the single value of the feature's
type for the modeled object converted to a literal representation as used in detail entry. |
protected BasicEAnnotationValidator.Assistant |
createAssistant()
Creates the assistant.
|
protected BasicDiagnostic |
createDiagnostic(int severity,
int code,
java.lang.String message,
java.lang.Object... data)
Creates a diagnostic using the given parameters and the
annotationSource. |
protected EObject |
createInstance(EClass eClass,
EAnnotation eAnnotation)
Creates an instance of the modeled representation for the given annotation.
|
protected BasicDiagnostic |
createValueDiagnostic(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EStructuralFeature feature)
Creates the placeholder diagnostic used by
validateFeatureDetail. |
protected java.util.Collection<? extends EAnnotation> |
getAllValidAnnotations(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<? extends EAnnotation> annotations)
Returns the filtered collection of nested annotations that are valid for this annotation.
|
java.lang.String |
getAnnotationSource()
Returns the
annotation source of the annotations validated by this annotation validator. |
BasicEAnnotationValidator.Assistant |
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.
|
protected ResourceLocator |
getEcoreResourceLocator()
Returns the resource locator for fetching messages supported directly by the base implementation.
|
protected java.util.Map<java.lang.String,EStructuralFeature> |
getProperties(EModelElement eModelElement)
Returns a map from key to
feature. |
protected abstract java.util.List<EClass> |
getPropertyClasses(EModelElement eModelElement)
Returns the model classes used to represent annotations for the given model element.
|
protected abstract ResourceLocator |
getResourceLocator()
Returns the resource locator for fetching implementation-specific messages.
|
protected EValidator |
getRootEValidator(java.util.Map<java.lang.Object,java.lang.Object> context)
Returns the root validator of the context.
|
protected java.lang.String |
getString(ResourceLocator resourceLocator,
java.lang.String key,
java.lang.Object... substitutions)
Fetches a translated string from the resource locator using the message key and the give substitutions, if any.
|
protected java.util.Collection<? extends EAnnotation> |
getValidAnnotations(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<? extends EAnnotation> annotations)
Returns the filtered collection of nested annotations that are valid for this annotation.
|
protected java.util.Collection<? extends EObject> |
getValidContents(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<? extends EObject> contents)
Returns the filtered collection of contents that are valid for this annotation.
|
protected java.lang.String |
getValidLocationDescription()
Returns a description of the valid locations supported for annotations of this annotation validator.
|
protected java.util.Collection<?> |
getValidReferences(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<?> references)
Returns the filtered collection of references that are valid for this annotation.
|
protected EObject |
initialize(EObject eObject,
EAnnotation eAnnotation)
Returns an initialized instance of the given object for the given annotation.
|
protected boolean |
isAnnotationsSupported(EAnnotation eAnnotation,
EModelElement eModelElement)
Returns whether
nested 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(EAnnotation eAnnotation,
EModelElement eModelElement)
Returns whether
contents are meaningful for this annotation. |
protected boolean |
isDuplicateValid(EModelElement eModelElement,
EAnnotation primaryEAnnotation,
EAnnotation secondaryEAnnotation)
Returns whether the given two annotations, both with the annotation validator's annotation source, both
contained by the given model element, are valid. |
protected boolean |
isIncludedProperty(EModelElement eModelElement,
EClass eClass,
EStructuralFeature eStructuralFeature)
Returns whether the given structural feature of the given class for the given model element is
included as a property. |
protected boolean |
isReferencesSupported(EAnnotation eAnnotation,
EModelElement eModelElement)
Returns whether
references are meaningful for this annotation. |
boolean |
isValidLocation(EAnnotation eAnnotation)
Returns whether this annotation with this annotation validator's
annotation source is valid at its current location. |
protected boolean |
isValidLocation(EAnnotation eAnnotation,
EModelElement eModelElement)
Returns whether this annotation
contained by this model element is valid at this location. |
protected java.lang.String |
join(EObject eObject,
EStructuralFeature eStructuralFeature,
java.util.List<java.lang.String> literalValues)
Returns the joined list of values of this modeled object's feature.
|
protected static EPackage |
loadEPackage(java.lang.String uri)
Returns the package loaded from the location specified by the given URI.
|
protected void |
reportDuplicate(EAnnotation primaryEAnnotation,
EAnnotation secondaryEAnnotation,
EModelElement eModelElement,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportIgnoredAnnotations(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<? extends EAnnotation> ignoredAnnotations,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportIgnoredContents(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<? extends EObject> ignoredContents,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportIgnoredEntry(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportIgnoredReferences(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Collection<? extends EObject> ignoredReferences,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportInvalidAnnotation(EAnnotation eAnnotation,
EModelElement eModelElement,
EAnnotation nestedEAnnotation,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportInvalidContent(EAnnotation eAnnotation,
EModelElement eModelElement,
EObject content,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportInvalidLocation(EAnnotation eAnnotation,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportInvalidReference(EAnnotation eAnnotation,
EModelElement eModelElement,
EObject reference,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportInvalidReferenceLiteral(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EReference reference,
java.lang.String literalValue,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportInvalidValueLiteral(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EAttribute attribute,
java.lang.String literalValue,
EDataType dataType,
DiagnosticChain diagnostics,
java.lang.RuntimeException exception,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportMissingEntry(EAnnotation eAnnotation,
EModelElement eModelElement,
java.lang.String key,
EStructuralFeature property,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportMissingRequiredEntryValue(EAnnotation eAnnotation,
EModelElement eModelElement,
EStructuralFeature feature,
java.util.List<java.lang.Object> values,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportTooFewValues(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EStructuralFeature feature,
java.util.List<java.lang.Object> values,
int size,
int lowerBound,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected void |
reportTooManyValues(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EStructuralFeature feature,
java.util.List<java.lang.Object> values,
int size,
int upperBound,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context) |
protected java.util.List<java.lang.String> |
split(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
java.lang.String literalValue,
EStructuralFeature feature,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Splits the literal value into a list of literal values as appropriate for this feature.
|
boolean |
validate(EAnnotation eAnnotation,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether this annotation is valid.
|
protected boolean |
validateAnnotations(EAnnotation eAnnotation,
EModelElement eModelElement,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether this annotation's
nested annotations are valid. |
protected boolean |
validateAttributeDetailLiteralValue(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EAttribute attribute,
java.util.List<java.lang.Object> dataValues,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether the literal value of this detail entry for the corresponding attribute is valid.
|
protected boolean |
validateAttributeDetailValueLiteral(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EAttribute attribute,
java.lang.String literalValue,
java.util.List<java.lang.Object> dataValues,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether the given literal value is valid with respect to this detail entry's corresponding attribute's
data type. |
protected boolean |
validateContents(EAnnotation eAnnotation,
EModelElement eModelElement,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether this annotation's
contents are valid. |
protected boolean |
validateDetail(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether this detail entry is valid.
|
protected boolean |
validateDetails(EAnnotation eAnnotation,
EModelElement eModelElement,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether this annotation's
details are valid. |
protected boolean |
validateFeatureDetail(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EStructuralFeature feature,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether the value of this detail entry for the corresponding feature is valid.
|
protected boolean |
validateFeatureDetailValue(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EStructuralFeature feature,
java.util.List<java.lang.Object> values,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether the modeled values for this detail entry's corresponding feature are valid.
|
protected boolean |
validateReferenceDetailLiteralValue(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EReference reference,
java.util.List<java.lang.Object> referenceValues,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether the literal value of this detail entry for the corresponding reference is valid.
|
protected boolean |
validateReferenceDetailValueLiteral(EAnnotation eAnnotation,
EModelElement eModelElement,
java.util.Map.Entry<java.lang.String,java.lang.String> entry,
EReference reference,
java.lang.String literalValue,
java.util.List<java.lang.Object> referenceValues,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether the given literal value is valid with respect to this detail entry's corresponding reference's
class. |
protected boolean |
validateReferences(EAnnotation eAnnotation,
EModelElement eModelElement,
DiagnosticChain diagnostics,
java.util.Map<java.lang.Object,java.lang.Object> context)
Returns whether this annotation's
references are valid. |
public static final int INVALID_LOCATION
public static final int INVALID_DUPLICATE
public static final int INVALID_REFERENCE_LITERAL
public static final int INVALID_DETAIL_VALUE
public static final int INVALID_VALUE_LITERAL
public static final int IGNORED_ANNOTATIONS
public static final int IGNORED_CONTENTS
public static final int IGNORED_REFERENCES
public static final int INVALID_REFERENCE
public static final int INVALID_ANNOTATION
public static final int INVALID_CONTENT
public static final int IGNORED_ENTRY
public static final int MISSING_ENTRY
public static final int MISSING_REQUIRED_ENTRY_VALUE
public static final int TOO_FEW_VALUES
public static final int TOO_MANY_VALUES
protected final java.lang.String annotationSource
annotation source validated by this annotation validator.protected final java.lang.String annotationName
protected final java.lang.String diagnosticSource
source used in this validator's diagnostics.protected final BasicEAnnotationValidator.Assistant assistant
assistant used by the framework to induce a user interface.public BasicEAnnotationValidator(java.lang.String annotationSource,
java.lang.String annotationName,
java.lang.String diagnosticSource)
annotation source validated by this annotation validator.annotationSource - the annotation source validated by this annotation validator.annotationName - the name used in this validator's diagnosticsdiagnosticSource - the diagnostic source used in this validator's diagnostics.public java.lang.String getAnnotationSource()
annotation source of the annotations validated by this annotation validator.getAnnotationSource in interface EAnnotationValidatorprotected abstract ResourceLocator getResourceLocator()
protected abstract java.util.List<EClass> getPropertyClasses(EModelElement eModelElement)
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.
eModelElement - the model element in question.public BasicEAnnotationValidator.Assistant getAssistant()
protected BasicEAnnotationValidator.Assistant createAssistant()
Generally derived classes will not need to specialize this method because all methods of the assistant delegate back to the annotation validator.
public boolean isValidLocation(EAnnotation eAnnotation)
annotation source is valid at its current location.
This implementation returns false if the containing EAnnotation.getEModelElement() is null,
if the isValidLocation(EAnnotation, EModelElement) returns false for the containing model element,
or if this is not the first annotation with this annotation source in the model element and isDuplicateValue returns false.
isValidLocation in interface EAnnotationValidatoreAnnotation - the annotation in question.protected boolean isValidLocation(EAnnotation eAnnotation, EModelElement eModelElement)
contained by this model element is valid at this location.
This implementation returns false if the element is not a named element.
It's typically the case that annotations on annotations aren't meaningful and valid.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.isValidLocation(EAnnotation),
validate(EAnnotation, DiagnosticChain, Map)protected boolean isDuplicateValid(EModelElement eModelElement, EAnnotation primaryEAnnotation, EAnnotation secondaryEAnnotation)
contained 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.
eModelElement - the model element that contains both annotations in its annotations feature.primaryEAnnotation - the first annotation in the model element's details.secondaryEAnnotation - a subsequent annotation in the model element's details.isValidLocation(EAnnotation),
validate(EAnnotation, DiagnosticChain, Map)public boolean validate(EAnnotation eAnnotation, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
This implementation checks if the location is valid
and reports an invalid location if it is not.
Then checks for invalid duplicates
and reports a duplicate if it is an invalid duplicate.
Then it validates the references and validates the details.
validate in interface EAnnotationValidatoreAnnotation - the annotation in question.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.EObjectValidator.validate(EObject, DiagnosticChain, Map)protected boolean validateReferences(EAnnotation eAnnotation, EModelElement eModelElement, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
references are valid.
This implementation checks whether references are supported.
If not, it checks whether the references are empty and if not reports ignored references.
If references are supported, then for each reference, it tests whether that reference is among the valid references,
passing in this annotation's references to determine the valid references,
and reports 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(EAnnotation, EModelElement)
and getValidReferences(EAnnotation, EModelElement, Collection).
An implementation may override this method to report missing required references.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.isReferencesSupported(EAnnotation, EModelElement)protected boolean isReferencesSupported(EAnnotation eAnnotation, EModelElement eModelElement)
references 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 returns false.
Implementations that override this to ever return true should also override getValidReferences(EAnnotation, EModelElement, Collection) to control the valid choices.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.BasicEAnnotationValidator.Assistant.isReferencesSupported(EAnnotation),
validateReferences(EAnnotation, EModelElement, DiagnosticChain, Map)protected java.util.Collection<?> getValidReferences(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<?> references)
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 to determine which references are valid.
An implementation that overrides this should also override isReferencesSupported(EAnnotation, EModelElement).
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.references - all reachable objects, some subset there of, or none at all.BasicEAnnotationValidator.Assistant.getValidReferences(EAnnotation, Collection)protected boolean validateContents(EAnnotation eAnnotation, EModelElement eModelElement, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
contents are valid.
This implementation checks whether contents are supported.
If not, it checks whether the contents are empty and if not reports ignored contents.
If contents are supported, then for each content, it tests whether that content is among the valid contents,
passing in this annotation's contents to determine the valid contents,
and reports 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(EAnnotation, EModelElement)
and getValidContents(EAnnotation, EModelElement, Collection).
An implementation may override this method to report missing required contents.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.isContentsSupported(EAnnotation, EModelElement),
getValidContents(EAnnotation, EModelElement, Collection)protected boolean isContentsSupported(EAnnotation eAnnotation, EModelElement eModelElement)
contents 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 returns false.
Implementations that override this to ever return true should also override getValidContents(EAnnotation, EModelElement, Collection) to control the valid choices.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.BasicEAnnotationValidator.Assistant.isContentsSupported(EAnnotation),
validateContents(EAnnotation, EModelElement, DiagnosticChain, Map)protected java.util.Collection<? extends EObject> getValidContents(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<? extends EObject> contents)
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 if contents are supported, or an empty list otherwise.
It is also used to determine 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 override isContentsSupported(EAnnotation, EModelElement).
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.contents - nothing at all, or the current or potential contents of the annotation.BasicEAnnotationValidator.Assistant.getValidContents(EAnnotation, Collection)protected boolean validateAnnotations(EAnnotation eAnnotation, EModelElement eModelElement, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
nested 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 annotation valid at this location,
it reports ignored annotations.
It's typically the case that annotations ignore nested annotations.
If that's not the case, you should override this method and specialize isAnnotationsSupported(EAnnotation, EModelElement)
and consider specializing getValidAnnotations(EAnnotation, EModelElement, Collection)
This implementation checks whether nested annotations are supported.
If not, it checks whether the valid annotations,
passing in this annotation's nested annotations to determine the valid annotations,
contain all the nested annotations; if not it reports ignored annotations.
If nested annotations are supported, then for each nested annotation, it tests whether that annotation is among the valid annotations
and reports 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(EAnnotation, EModelElement)
and getValidAnnotations(EAnnotation, EModelElement, Collection).
An implementation may override this method to report missing required nested annotations.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.isAnnotationsSupported(EAnnotation, EModelElement)protected boolean isAnnotationsSupported(EAnnotation eAnnotation, EModelElement eModelElement)
nested 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 returns false.
Implementations that override this to ever return true should also override getValidAnnotations(EAnnotation, EModelElement, Collection) to control the valid choices.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.BasicEAnnotationValidator.Assistant.isAnnotationsSupported(EAnnotation),
validateAnnotations(EAnnotation, EModelElement, DiagnosticChain, Map)protected java.util.Collection<? extends EAnnotation> getValidAnnotations(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<? extends EAnnotation> annotations)
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 a registered annotation validator
that considers its annotations valid 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 to determine which nested annotations are valid
and that is why it should not remove values from the provided annotations argument if they are valid.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.annotations - typically the current nested annotations of the annotation.BasicEAnnotationValidator.Assistant.getValidAnnotations(EAnnotation, Collection)protected java.util.Collection<? extends EAnnotation> getAllValidAnnotations(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<? extends EAnnotation> annotations)
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 a registered annotation validator
that considers its annotations valid 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 override isAnnotationsSupported(EAnnotation, EModelElement).
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.annotations - nothing at all, or the current or potential nested annotations of the annotation.BasicEAnnotationValidator.Assistant.getValidAnnotations(EAnnotation, Collection)protected boolean validateDetails(EAnnotation eAnnotation, EModelElement eModelElement, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
details 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 detail without a property feature.
If so, it validates the detail with the property feature.
If all the details are valid,
it will check whether any required property feature is absent from the details
and reports it missing.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected java.util.Map<java.lang.String,EStructuralFeature> getProperties(EModelElement eModelElement)
feature.
These represents the keys that are considered valid and can be processed by this annotation validator.
This implementation uses getPropertyClasses(EModelElement), iterating over each class and each feature of each class, adding to the map each included 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, the getPropertyClasses method or the validateDetails method.
eModelElement - the model element that is being annotated.validateDetails(EAnnotation, EModelElement, DiagnosticChain, Map),
getPropertyClasses(EModelElement)protected boolean isIncludedProperty(EModelElement eModelElement, EClass eClass, EStructuralFeature eStructuralFeature)
included as a property.eModelElement - the model element.eClass - the class used to model the annotation for the model element.eStructuralFeature - a structural feature of the class.protected EObject createInstance(EClass eClass, EAnnotation eAnnotation)
This implementation creates an instance and initializes it.
eClass - the class to be instantiated.eAnnotation - the annotation with the information that needs to be represented.protected EObject initialize(EObject eObject, EAnnotation eAnnotation)
This implementation handles only the case of modeled attributes.
For each detail entry,
it looks up the corresponding property via the key.
If it's not an EAttribute it will throw an UnsupportedOperationException.
If the attribute property is multi-valued,
it splits the detail entry value, and converts each literal item into a value of the attribute'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 is reflectively set into the instance.
If the model representation includes references,
an annotation validator implementation must specialize this method for the assistant to function correctly.
eObject - the object to initialize.eAnnotation - the annotation used to initialize the object.protected java.lang.String convertPropertyValueToLiteral(EObject eObject, EStructuralFeature eStructuralFeature, java.lang.Object value)
detail entry.
This implementation handles both EAttribute and EReference.
For a multi-valued feature, it converts for each item in the list, and joins them into a single string.
For a single-valued feature, it returns the converted value.
This method is not used by the validator but is useful for specializing the BasicEAnnotationValidator.Assistant.convertPropertyValueToLiteral(EObject, EStructuralFeature, Object).
eObject - the modeled object.eStructuralFeature - a feature of that object.value - the value to converted to a literal representation.convertPropertyValueToLiteralItem(EObject, EStructuralFeature, Object)protected java.lang.String convertPropertyValueToLiteralItem(EObject eObject, EStructuralFeature eStructuralFeature, java.lang.Object value)
type for the modeled object converted to a literal representation as used in detail entry.
This implementation delegates to convertPropertyAttributeValueToLiteralItem(EObject, EAttribute, Object) or convertPropertyReferenceValueToLiteralItem(EObject, EReference, Object) as appropriate.
eObject - the modeled object.eStructuralFeature - a feature of that object.value - the value of the feature's type to converted to a literal representation.convertPropertyValueToLiteral(EObject, EStructuralFeature, Object)protected java.lang.String convertPropertyAttributeValueToLiteralItem(EObject eObject, EAttribute eAttribute, java.lang.Object value)
type for the modeled object converted to a literal representation as used in detail entry.
This implementation simple uses EcoreUtil.convertToString(EDataType, Object).
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.convertPropertyValueToLiteral(EObject, EStructuralFeature, Object)protected java.lang.String convertPropertyReferenceValueToLiteralItem(EObject eObject, EReference eReference, java.lang.Object value)
type for the modeled object converted to a literal representation as used in detail 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 an UnsupportedOperationException.
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.convertPropertyValueToLiteral(EObject, EStructuralFeature, Object)protected java.lang.String join(EObject eObject, EStructuralFeature eStructuralFeature, java.util.List<java.lang.String> literalValues)
This implementation simply separates the individual literal value items with a " ".
eObject - the modeled object.eStructuralFeature - a feature of that object.literalValues - the literal value to join into a single value.protected boolean isApplicable(EObject eObject, EStructuralFeature eStructuralFeature)
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 returns true.
eObject - the modeled object in question.eStructuralFeature - a feature of that object.protected boolean validateDetail(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
This method is only called when there is no property associated with this entry's key.
This implementation always reports an ignored entry.
An annotation validator implementation may choose to support validation by specializing this method, rather than providing a modeled representation,
but the assistant will not provide any useful support.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected boolean validateFeatureDetail(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EStructuralFeature feature, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
This implementation delegates
to validateAttributeDetail
or to validateReferenceDetail
depending on whether the feature is an EAttribute or an EReference.
It creates a place holder diagnostic that it passed to those methods,
so all diagnostics gathered by those methods are grouped as children of the placeholder.
Both those methods build the corresponding modeled values as a side-effect.
If the detail entry is otherwise valid,
the modeled value is validated.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.feature - the property associated with entry.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected boolean validateFeatureDetailValue(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EStructuralFeature feature, java.util.List<java.lang.Object> values, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
For a many-valued feature, it validates that the lower and upper bounds are respected.
For a singled valued feature that is required, it validates that the value is present;
in the single-valued case, the values list should contain a single value.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.feature - the property associated with entry.values - the list of instance values for this entry.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected boolean validateAttributeDetailLiteralValue(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EAttribute attribute, java.util.List<java.lang.Object> dataValues, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
This implementation,
for a many-valued attribute,
splits the detail value, if present, into a list of literal values
and validates each literal value.
For a single-valued attribute, it directly 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's data type and is added to the data values list.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.attribute - feature the attribute property associated with entry.dataValues - the list in which to accumulate valid instance values.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.validateAttributeDetailValueLiteral(EAnnotation, EModelElement, Map.Entry, EAttribute, String, List, DiagnosticChain, Map)protected boolean validateAttributeDetailValueLiteral(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EAttribute attribute, java.lang.String literalValue, java.util.List<java.lang.Object> dataValues, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
data 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 exception message.
Otherwise, it adds the instance value to the list of values
and validates the instance value.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.attribute - feature the attribute 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's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected boolean validateReferenceDetailLiteralValue(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EReference reference, java.util.List<java.lang.Object> referenceValues, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
This implementation,
for a many-valued reference,
splits the detail value, if present, into a list of literal values
and validates each literal value.
For a single-valued attribute, it directly 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's class and added to the reference values list.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.reference - the reference property associated with entry.referenceValues - the list in which to accumulate valid instance values.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected boolean validateReferenceDetailValueLiteral(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EReference reference, java.lang.String literalValue, java.util.List<java.lang.Object> referenceValues, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
class.
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 and reports an invalid reference literal.
An annotation validator implementation that supports reference literals must specialize this method.
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.reference - the reference 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's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.protected java.util.List<java.lang.String> split(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, java.lang.String literalValue, EStructuralFeature feature, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
This implementation splits the values at whitespace boundaries for all features..
eAnnotation - the annotation in question.eModelElement - the annotation's containing model element.entry - the annotation detail in question.literalValue - a literal value of this feature's type.feature - the property associated with entry.diagnostics - a place to accumulate diagnostics; if it's null, no diagnostics should be produced.context - a place to cache information, if it's null, no cache is supported.validateAttributeDetailValueLiteral(EAnnotation, EModelElement, Map.Entry, EAttribute, String, List, DiagnosticChain, Map),
validateReferenceDetailValueLiteral(EAnnotation, EModelElement, Map.Entry, EReference, String, List, DiagnosticChain, Map)protected void reportInvalidReferenceLiteral(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EReference reference, java.lang.String literalValue, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_REFERENCE_LITERALprotected void reportInvalidValueLiteral(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EAttribute attribute, java.lang.String literalValue, EDataType dataType, DiagnosticChain diagnostics, java.lang.RuntimeException exception, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_VALUE_LITERALprotected void reportMissingRequiredEntryValue(EAnnotation eAnnotation, EModelElement eModelElement, EStructuralFeature feature, java.util.List<java.lang.Object> values, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
MISSING_REQUIRED_ENTRY_VALUEprotected void reportTooFewValues(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EStructuralFeature feature, java.util.List<java.lang.Object> values, int size, int lowerBound, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
TOO_FEW_VALUESprotected void reportTooManyValues(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EStructuralFeature feature, java.util.List<java.lang.Object> values, int size, int upperBound, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
TOO_MANY_VALUESprotected void reportInvalidLocation(EAnnotation eAnnotation, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_LOCATIONprotected void reportDuplicate(EAnnotation primaryEAnnotation, EAnnotation secondaryEAnnotation, EModelElement eModelElement, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_DUPLICATEprotected void reportIgnoredEntry(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
IGNORED_ENTRYprotected void reportMissingEntry(EAnnotation eAnnotation, EModelElement eModelElement, java.lang.String key, EStructuralFeature property, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
MISSING_ENTRYprotected void reportIgnoredReferences(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<? extends EObject> ignoredReferences, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
IGNORED_REFERENCESprotected void reportInvalidReference(EAnnotation eAnnotation, EModelElement eModelElement, EObject reference, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_REFERENCEprotected void reportIgnoredContents(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<? extends EObject> ignoredContents, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_REFERENCEprotected void reportInvalidContent(EAnnotation eAnnotation, EModelElement eModelElement, EObject content, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_CONTENTprotected void reportIgnoredAnnotations(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Collection<? extends EAnnotation> ignoredAnnotations, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
IGNORED_ANNOTATIONSprotected void reportInvalidAnnotation(EAnnotation eAnnotation, EModelElement eModelElement, EAnnotation nestedEAnnotation, DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
INVALID_ANNOTATIONprotected java.lang.String getValidLocationDescription()
A annotation validator implementation must provide the key "_UI_Valid" + in its annotationName + "AnnotationLocation_substitution"resource locator
with a very short description of the valid locations of annotations.
reportInvalidLocation(EAnnotation, DiagnosticChain, Map)protected BasicDiagnostic createValueDiagnostic(EAnnotation eAnnotation, EModelElement eModelElement, java.util.Map.Entry<java.lang.String,java.lang.String> entry, EStructuralFeature feature)
validateFeatureDetail.
Diagnostics about problems with the value of a detail entry will be nested as children of this annotation.eAnnotation - the annotation.eModelElement - the model element of that annotation.entry - the entry.feature - the feature.protected ResourceLocator getEcoreResourceLocator()
protected BasicDiagnostic createDiagnostic(int severity,
int code,
java.lang.String message,
java.lang.Object... data)
annotationSource.severity - code - message - data - protected java.lang.String getString(ResourceLocator resourceLocator,
java.lang.String key,
java.lang.Object... substitutions)
resourceLocator - key - substitutions - protected EValidator getRootEValidator(java.util.Map<java.lang.Object,java.lang.Object> context)
context - the context.protected static EPackage loadEPackage(java.lang.String uri)
EPackage,
that package is registered in the EPackage.Registry.INSTANCE.uri - the location of a resource containing an EPackage.Copyright © 2018. Licensed under the Eclipse Public License v1.0. All rights reserved.
Submit a bug or feature