org.eclipse.xtext.validation
Class AbstractDeclarativeValidator

java.lang.Object
  extended by org.eclipse.xtext.validation.AbstractInjectableValidator
      extended by org.eclipse.xtext.validation.AbstractDeclarativeValidator
All Implemented Interfaces:
org.eclipse.emf.ecore.EValidator, ValidationMessageAcceptor
Direct Known Subclasses:
AbstractCodetemplatesJavaValidator, AbstractSimpleAntlrJavaValidator, AbstractSimpleExpressionsJavaValidator, AbstractXbaseJavaValidator, ClasspathBasedChecks, EarlyExitValidator, FeatureCallValidator, ImportUriValidator, JvmTypeReferencesValidator, NamesAreUniqueValidator, XtextValidator

public abstract class AbstractDeclarativeValidator
extends AbstractInjectableValidator
implements ValidationMessageAcceptor

Allows subclasses to specify invariants in a declarative manner using Check annotation. Example:

 @Check
 void checkName(ParserRule rule) {
        if (!toFirstUpper(rule.getName()).equals(rule.getName())) {
                warning("Name should start with a capital.", XtextPackage.ABSTRACT_RULE__NAME);
        }
 }
 

Author:
Sven Efftinge - Initial contribution and API, Michael Clay

Nested Class Summary
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
 
Fields inherited from interface org.eclipse.xtext.validation.ValidationMessageAcceptor
INSIGNIFICANT_INDEX
 
Fields inherited from interface org.eclipse.emf.ecore.EValidator
MARKER, RELATED_URIS_ATTRIBUTE, URI_ATTRIBUTE
 
Constructor Summary
AbstractDeclarativeValidator()
           
 
Method Summary
 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 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 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 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 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.
 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.
protected  void checkDone()
           
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  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  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.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()
           
 ValidationMessageAcceptor getMessageAcceptor()
           
protected  void guard(boolean guardExpression)
           
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.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  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, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDeclarativeValidator

public AbstractDeclarativeValidator()
Method Detail

setInjector

public void setInjector(com.google.inject.Injector injector)

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()

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 class AbstractInjectableValidator

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.EObject source,
                    org.eclipse.emf.ecore.EStructuralFeature feature,
                    int index)

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,
                    int index,
                    java.lang.String code,
                    java.lang.String... issueData)

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,
                       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,
                     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)

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 interface ValidationMessageAcceptor
Parameters:
message - the error message. May not be null.
object - the object or the feature holder. May not be null.
feature - the feature or null if the complete instance should be annotated.
code - the optional issue code.
issueData - the optional issue data.

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 interface ValidationMessageAcceptor
Parameters:
message - the warning message. May not be null.
object - the object or the feature holder. May not be null.
feature - the feature or null if the complete instance should be annotated.
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 interface ValidationMessageAcceptor
Parameters:
message - the info message. May not be null.
object - the object or the feature holder. May not be null.
feature - the feature or null if the complete instance should be annotated.
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 interface ValidationMessageAcceptor
Parameters:
message - the error message. May not be null.
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 interface ValidationMessageAcceptor
Parameters:
message - the warning message. May not be null.
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 interface ValidationMessageAcceptor
Parameters:
message - the info message. May not be null.
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()