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 usingCheckannotation. 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
NullPointerExceptionsoccurring 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 classAbstractDeclarativeValidator.MethodWrapperstatic classAbstractDeclarativeValidator.Statestatic classAbstractDeclarativeValidator.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 voidacceptError(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.voidacceptError(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.voidacceptInfo(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..voidacceptInfo(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.voidacceptWarning(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.voidacceptWarning(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 voidaddIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, int offset, int length, java.lang.String issueCode)protected voidaddIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, int offset, int length, java.lang.String issueCode, java.lang.String... issueData)protected voidaddIssue(java.lang.String message, org.eclipse.emf.ecore.EObject source, java.lang.String issueCode)protected voidaddIssue(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 voidaddIssue(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 voidaddIssueToState(java.lang.String issueCode, java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)protected voidcheckDone()protected voidcheckIsFromCurrentlyCheckedResource(org.eclipse.emf.ecore.EObject object)protected org.eclipse.emf.common.util.DiagnosticcreateDiagnostic(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.DiagnosticcreateDiagnostic(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.MethodWrappercreateMethodWrapper(AbstractDeclarativeValidator instanceToUse, java.lang.reflect.Method method)protected voiderror(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)protected voiderror(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)protected voiderror(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 voiderror(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 voiderror(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)protected voiderror(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)protected voiderror(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)protected voiderror(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)protected org.eclipse.xtext.util.CancelIndicatorgetCancelIndicator()Obtain a cancel indicator that is valid for the current validation run.protected org.eclipse.emf.common.util.DiagnosticChaingetChain()protected CheckModegetCheckMode()protected java.util.Map<java.lang.Object,java.lang.Object>getContext()protected java.lang.reflect.MethodgetCurrentMethod()protected org.eclipse.emf.ecore.EObjectgetCurrentObject()protected IssueSeveritiesgetIssueSeverities(java.util.Map<java.lang.Object,java.lang.Object> context, org.eclipse.emf.ecore.EObject eObject)ValidationMessageAcceptorgetMessageAcceptor()protected voidguard(boolean guardExpression)protected voidhandleExceptionDuringValidation(java.lang.Throwable targetException)Handles exceptions occuring during execution of validation code.protected voidinfo(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)protected voidinfo(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)protected voidinfo(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 voidinfo(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 voidinfo(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)protected voidinfo(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)protected voidinfo(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)protected voidinfo(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, java.lang.String code, java.lang.String... issueData)protected booleaninternalValidate(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 booleanisIgnored(java.lang.String issueCode)protected AbstractDeclarativeValidatornewInstance(java.lang.Class<? extends AbstractDeclarativeValidator> clazz)voidsetInjector(com.google.inject.Injector injector)AbstractDeclarativeValidator.StateAccesssetMessageAcceptor(ValidationMessageAcceptor messageAcceptor)protected inttoDiagnosticSeverity(Severity severity)protected voidwarning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature)protected voidwarning(java.lang.String message, org.eclipse.emf.ecore.EObject source, org.eclipse.emf.ecore.EStructuralFeature feature, int index)protected voidwarning(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 voidwarning(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 voidwarning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature)protected voidwarning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index)protected voidwarning(java.lang.String message, org.eclipse.emf.ecore.EStructuralFeature feature, int index, java.lang.String code, java.lang.String... issueData)protected voidwarning(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:
internalValidatein 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:ValidationMessageAcceptorAnnotate an instance, a feature value, or all feature values with an error.- Specified by:
acceptErrorin interfaceValidationMessageAcceptor- Parameters:
message- the error message. May not benull.object- the object or the feature holder. May not benull.feature- the feature ornullif the complete instance should be annotated.index- the index of the erroneous value or-1if 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:ValidationMessageAcceptorAnnotate an instance, a feature value, or all feature values with a warning.- Specified by:
acceptWarningin interfaceValidationMessageAcceptor- Parameters:
message- the warning message. May not benull.object- the object or the feature holder. May not benull.feature- the feature ornullif the complete instance should be annotated.index- the index of the relevant value or-1if 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:ValidationMessageAcceptorAnnotate an instance, a feature value, or all feature values with an info message.- Specified by:
acceptInfoin interfaceValidationMessageAcceptor- Parameters:
message- the info message. May not benull.object- the object or the feature holder. May not benull.feature- the feature ornullif the complete instance should be annotated.index- the index of the interesting value or-1if 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:ValidationMessageAcceptorAnnotate a range of the resource with an error.- Specified by:
acceptErrorin 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:ValidationMessageAcceptorAnnotate a range of the resource with a warning.- Specified by:
acceptWarningin 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:ValidationMessageAcceptorAnnotate a range of the resource with an info message..- Specified by:
acceptInfoin 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.RuntimeExceptionHandles exceptions occuring during execution of validation code. By default this method will swallowNullPointerExceptionsandGuardExceptions. Clients may override this method to propagateNullPointerExceptionsor more smarter handling.- Throws:
java.lang.RuntimeException- Since:
- 2.17
-
-