Package org.eclipse.xtext.validation
Class AbstractDeclarativeValidator
- java.lang.Object
-
- org.eclipse.xtext.validation.AbstractInjectableValidator
-
- org.eclipse.xtext.validation.AbstractDeclarativeValidator
-
- All Implemented Interfaces:
org.eclipse.emf.ecore.EValidator
,ValidationMessageAcceptor
- Direct Known Subclasses:
ImportUriValidator
,NamesAreUniqueValidator
,XtextValidator
public abstract class AbstractDeclarativeValidator extends AbstractInjectableValidator implements ValidationMessageAcceptor
Allows subclasses to specify invariants in a declarative manner usingCheck
annotation. Example:@Check void checkName(ParserRule rule) { if (!toFirstUpper(rule.getName()).equals(rule.getName())) { warning("Name should start with a capital.", XtextPackage.Literals.ABSTRACT_RULE__NAME); } }
By default
NullPointerExceptions
occurring in the invocation of validation code are swallowed. This behavior can be switched by overridinghandleExceptionDuringValidation(Throwable)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractDeclarativeValidator.MethodWrapper
static class
AbstractDeclarativeValidator.State
static class
AbstractDeclarativeValidator.StateAccess
-
Nested classes/interfaces inherited from interface org.eclipse.emf.ecore.EValidator
org.eclipse.emf.ecore.EValidator.Descriptor, org.eclipse.emf.ecore.EValidator.PatternMatcher, org.eclipse.emf.ecore.EValidator.Registry, org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider, org.eclipse.emf.ecore.EValidator.ValidationDelegate
-
-
Field Summary
-
Fields inherited from class org.eclipse.xtext.validation.AbstractInjectableValidator
CURRENT_LANGUAGE_NAME, ISSUE_SEVERITIES
-
Fields inherited from interface org.eclipse.emf.ecore.EValidator
MARKER, RELATED_URIS_ATTRIBUTE, URI_ATTRIBUTE
-
Fields inherited from interface org.eclipse.xtext.validation.ValidationMessageAcceptor
INSIGNIFICANT_INDEX
-
-
Constructor Summary
Constructors Constructor Description AbstractDeclarativeValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acceptError(java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
Annotate a range of the resource with an error.void
acceptError(java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
Annotate an instance, a feature value, or all feature values with an error.void
acceptInfo(java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
Annotate a range of the resource with an info message..void
acceptInfo(java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
Annotate an instance, a feature value, or all feature values with an info message.void
acceptWarning(java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
Annotate a range of the resource with a warning.void
acceptWarning(java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
Annotate an instance, a feature value, or all feature values with a warning.protected void
addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, int offset, int length, java.lang.String issueCode)
protected void
addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, int offset, int length, java.lang.String issueCode, java.lang.String... issueData)
protected void
addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, java.lang.String issueCode)
protected void
addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String issueCode, java.lang.String... issueData)
protected void
addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String issueCode, java.lang.String... issueData)
protected void
addIssueToState(java.lang.String issueCode, java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
checkDone()
protected void
checkIsFromCurrentlyCheckedResource(org.eclipse.emf.ecore.EObject object)
protected org.eclipse.emf.common.util.Diagnostic
createDiagnostic(Severity severity, java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
protected org.eclipse.emf.common.util.Diagnostic
createDiagnostic(Severity severity, java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected AbstractDeclarativeValidator.MethodWrapper
createMethodWrapper(AbstractDeclarativeValidator instanceToUse, java.lang.reflect.Method method)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected void
error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
protected org.eclipse.xtext.util.CancelIndicator
getCancelIndicator()
Obtain a cancel indicator that is valid for the current validation run.protected org.eclipse.emf.common.util.DiagnosticChain
getChain()
protected CheckMode
getCheckMode()
protected java.util.Map<java.lang.Object,java.lang.Object>
getContext()
protected java.lang.reflect.Method
getCurrentMethod()
protected org.eclipse.emf.ecore.EObject
getCurrentObject()
protected IssueSeverities
getIssueSeverities(java.util.Map<java.lang.Object,java.lang.Object> context, org.eclipse.emf.ecore.EObject eObject)
ValidationMessageAcceptor
getMessageAcceptor()
protected void
guard(boolean guardExpression)
protected void
handleExceptionDuringValidation(java.lang.Throwable targetException)
Handles exceptions occuring during execution of validation code.protected void
info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected void
info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
protected boolean
internalValidate(org.eclipse.emf.ecore.EClass class1, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.common.util.DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
protected boolean
isIgnored(java.lang.String issueCode)
protected AbstractDeclarativeValidator
newInstance(java.lang.Class<? extends AbstractDeclarativeValidator> clazz)
void
setInjector(com.google.inject.Injector injector)
AbstractDeclarativeValidator.StateAccess
setMessageAcceptor(ValidationMessageAcceptor messageAcceptor)
protected int
toDiagnosticSeverity(Severity severity)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
protected void
warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
-
Methods inherited from class org.eclipse.xtext.validation.AbstractInjectableValidator
getCurrentLanguage, getEPackages, isLanguageSpecific, isResponsible, register, validate, validate, validate
-
-
-
-
Method Detail
-
setInjector
public void setInjector(com.google.inject.Injector injector)
-
createMethodWrapper
protected AbstractDeclarativeValidator.MethodWrapper createMethodWrapper(AbstractDeclarativeValidator instanceToUse, java.lang.reflect.Method method)
- Since:
- 2.6
-
newInstance
protected AbstractDeclarativeValidator newInstance(java.lang.Class<? extends AbstractDeclarativeValidator> clazz)
-
getCurrentObject
protected org.eclipse.emf.ecore.EObject getCurrentObject()
-
getCurrentMethod
protected java.lang.reflect.Method getCurrentMethod()
-
getChain
protected org.eclipse.emf.common.util.DiagnosticChain getChain()
-
getCheckMode
protected CheckMode getCheckMode()
-
getContext
protected java.util.Map<java.lang.Object,java.lang.Object> getContext()
-
getCancelIndicator
protected org.eclipse.xtext.util.CancelIndicator getCancelIndicator()
Obtain a cancel indicator that is valid for the current validation run.- Since:
- 2.22
-
internalValidate
protected final boolean internalValidate(org.eclipse.emf.ecore.EClass class1, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.common.util.DiagnosticChain diagnostics, java.util.Map<java.lang.Object,java.lang.Object> context)
- Specified by:
internalValidate
in classAbstractInjectableValidator
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
- Since:
- 2.0
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)
- Since:
- 2.4
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
- Since:
- 2.4
-
info
protected void info(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
- Since:
- 2.4
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)
- Since:
- 2.4
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
-
warning
protected void warning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)
- Since:
- 2.4
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)
-
error
protected void error(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
-
addIssueToState
protected void addIssueToState(java.lang.String issueCode, java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)
- Since:
- 2.4
-
addIssue
protected void addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, java.lang.String issueCode)
- Since:
- 2.4
-
addIssue
protected void addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String issueCode, java.lang.String... issueData)
- Since:
- 2.4
-
addIssue
protected void addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String issueCode, java.lang.String... issueData)
- Since:
- 2.4
-
addIssue
protected void addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, int offset, int length, java.lang.String issueCode)
- Since:
- 2.4
-
addIssue
protected void addIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, int offset, int length, java.lang.String issueCode, java.lang.String... issueData)
- Since:
- 2.4
-
isIgnored
protected boolean isIgnored(java.lang.String issueCode)
- Since:
- 2.4
-
getIssueSeverities
protected IssueSeverities getIssueSeverities(java.util.Map<java.lang.Object,java.lang.Object> context, org.eclipse.emf.ecore.EObject eObject)
- Since:
- 2.4
-
guard
protected void guard(boolean guardExpression)
-
checkDone
protected void checkDone()
-
acceptError
public void acceptError(java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
Description copied from interface:ValidationMessageAcceptor
Annotate an instance, a feature value, or all feature values with an error.- Specified by:
acceptError
in interfaceValidationMessageAcceptor
- Parameters:
message
- the error message. May not benull
.object
- the object or the feature holder. May not benull
.feature
- the feature ornull
if the complete instance should be annotated.index
- the index of the erroneous value or-1
if all values are considered to be invalid. The index is ignored if the feature is null or the feature is a single value feature.code
- the optional issue code.issueData
- the optional issue data.
-
checkIsFromCurrentlyCheckedResource
protected void checkIsFromCurrentlyCheckedResource(org.eclipse.emf.ecore.EObject object)
- Since:
- 2.4
-
acceptWarning
public void acceptWarning(java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
Description copied from interface:ValidationMessageAcceptor
Annotate an instance, a feature value, or all feature values with a warning.- Specified by:
acceptWarning
in interfaceValidationMessageAcceptor
- Parameters:
message
- the warning message. May not benull
.object
- the object or the feature holder. May not benull
.feature
- the feature ornull
if the complete instance should be annotated.index
- the index of the relevant value or-1
if all values are considered to be affected. The index is ignored if the feature is null or the feature is a single value feature.code
- the optional issue code.issueData
- the optional issue data.
-
acceptInfo
public void acceptInfo(java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
Description copied from interface:ValidationMessageAcceptor
Annotate an instance, a feature value, or all feature values with an info message.- Specified by:
acceptInfo
in interfaceValidationMessageAcceptor
- Parameters:
message
- the info message. May not benull
.object
- the object or the feature holder. May not benull
.feature
- the feature ornull
if the complete instance should be annotated.index
- the index of the interesting value or-1
if all values are considered to be interesting. The index is ignored if the feature is null or the feature is a single value feature.code
- the optional issue code.issueData
- the optional issue data.
-
acceptError
public void acceptError(java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
Description copied from interface:ValidationMessageAcceptor
Annotate a range of the resource with an error.- Specified by:
acceptError
in interfaceValidationMessageAcceptor
- Parameters:
message
- the error message. May not benull
.offset
- the absolute offset in the resource.length
- the length of the erroneous range.code
- the optional issue code.issueData
- the optional issue data.
-
acceptWarning
public void acceptWarning(java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
Description copied from interface:ValidationMessageAcceptor
Annotate a range of the resource with a warning.- Specified by:
acceptWarning
in interfaceValidationMessageAcceptor
- Parameters:
message
- the warning message. May not benull
.offset
- the absolute offset in the resource.length
- the length of the invalid range.code
- the optional issue code.issueData
- the optional issue data.
-
acceptInfo
public void acceptInfo(java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
Description copied from interface:ValidationMessageAcceptor
Annotate a range of the resource with an info message..- Specified by:
acceptInfo
in interfaceValidationMessageAcceptor
- Parameters:
message
- the info message. May not benull
.offset
- the absolute offset in the resource.length
- the length of the annotated range.code
- the optional issue code.issueData
- the optional issue data.
-
createDiagnostic
protected org.eclipse.emf.common.util.Diagnostic createDiagnostic(Severity severity, java.lang.String message, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)
-
createDiagnostic
protected org.eclipse.emf.common.util.Diagnostic createDiagnostic(Severity severity, java.lang.String message, org.eclipse.emf.ecore.EObject object, int offset, int length, java.lang.String code, java.lang.String... issueData)
-
toDiagnosticSeverity
protected int toDiagnosticSeverity(Severity severity)
-
setMessageAcceptor
public AbstractDeclarativeValidator.StateAccess setMessageAcceptor(ValidationMessageAcceptor messageAcceptor)
-
getMessageAcceptor
public ValidationMessageAcceptor getMessageAcceptor()
-
handleExceptionDuringValidation
protected void handleExceptionDuringValidation(java.lang.Throwable targetException) throws java.lang.RuntimeException
Handles exceptions occuring during execution of validation code. By default this method will swallowNullPointerExceptions
andGuardException
s. Clients may override this method to propagateNullPointerExceptions
or more smarter handling.- Throws:
java.lang.RuntimeException
- Since:
- 2.17
-
-