org.eclipse.xtext.validation
Class NamesAreUniqueValidationHelper

java.lang.Object
  extended by org.eclipse.xtext.validation.NamesAreUniqueValidationHelper
All Implemented Interfaces:
INamesAreUniqueValidationHelper

public class NamesAreUniqueValidationHelper
extends java.lang.Object
implements INamesAreUniqueValidationHelper

Author:
Sebastian Zarnekow - Initial contribution and API

Constructor Summary
NamesAreUniqueValidationHelper()
           
 
Method Summary
protected  void checkDescriptionForDuplicatedName(IEObjectDescription description, java.util.Map<org.eclipse.emf.ecore.EClass,java.util.Map<QualifiedName,IEObjectDescription>> clusterTypeToName, ValidationMessageAcceptor acceptor)
           
 void checkUniqueNames(java.lang.Iterable<IEObjectDescription> descriptions, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor)
           Create errors for objects that have the same name. The cancel indicator will be queried everytime a description has been processed.
 void checkUniqueNames(java.lang.Iterable<IEObjectDescription> descriptions, ValidationMessageAcceptor acceptor)
          Create errors for objects that have the same name.
protected  void createDuplicateNameError(IEObjectDescription description, org.eclipse.emf.ecore.EClass clusterType, ValidationMessageAcceptor acceptor)
           
protected  org.eclipse.emf.ecore.EClass getAssociatedClusterType(org.eclipse.emf.ecore.EClass eClass)
          Return the type that describes the set of instances that should have unique names.
protected  com.google.common.collect.ImmutableSet<org.eclipse.emf.ecore.EClass> getClusterTypes()
          Initialize the set of clustering types.
protected  org.eclipse.emf.ecore.EObject getContainerForErrorMessage(org.eclipse.emf.ecore.EObject object)
           
 java.lang.String getDuplicateNameErrorMessage(IEObjectDescription description, org.eclipse.emf.ecore.EClass clusterType, org.eclipse.emf.ecore.EStructuralFeature feature)
          Build the error message for duplicated names.
protected  java.lang.String getErrorCode()
          Returns null.
protected  org.eclipse.emf.ecore.EStructuralFeature getNameFeature(org.eclipse.emf.ecore.EObject object)
           
protected  java.lang.String getTypeLabel(org.eclipse.emf.ecore.EClass eClass)
           
protected  boolean isContainerInformationHelpful(IEObjectDescription description, org.eclipse.emf.ecore.EObject container, java.lang.String containerTypeLabel, org.eclipse.emf.ecore.EStructuralFeature containerNameFeature)
           
protected  boolean isContainerInformationHelpful(IEObjectDescription description, java.lang.String shortName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamesAreUniqueValidationHelper

public NamesAreUniqueValidationHelper()
Method Detail

getClusterTypes

protected com.google.common.collect.ImmutableSet<org.eclipse.emf.ecore.EClass> getClusterTypes()

Initialize the set of clustering types. A type is considered to be clustering if any instance of that type has to have a unique name when it is transformed to an IEObjectDescription. Instances that do not belong to the same cluster may have the same exported name.

A clustering type will often be some kind of root type in a type hierarchy.


checkUniqueNames

public void checkUniqueNames(java.lang.Iterable<IEObjectDescription> descriptions,
                             ValidationMessageAcceptor acceptor)
Description copied from interface: INamesAreUniqueValidationHelper
Create errors for objects that have the same name. Objects, that do not belong to the same cluster will not get any errors.

Specified by:
checkUniqueNames in interface INamesAreUniqueValidationHelper
See Also:
INamesAreUniqueValidationHelper.checkUniqueNames(Iterable, CancelIndicator, ValidationMessageAcceptor)

checkUniqueNames

public void checkUniqueNames(java.lang.Iterable<IEObjectDescription> descriptions,
                             CancelIndicator cancelIndicator,
                             ValidationMessageAcceptor acceptor)

Create errors for objects that have the same name. Objects, that do not belong to the same cluster will not get any errors. The cancel indicator may be used to interrupt the validation.

The cancel indicator will be queried everytime a description has been processed. It should provide a fast answer about its canceled state.

Specified by:
checkUniqueNames in interface INamesAreUniqueValidationHelper

checkDescriptionForDuplicatedName

protected void checkDescriptionForDuplicatedName(IEObjectDescription description,
                                                 java.util.Map<org.eclipse.emf.ecore.EClass,java.util.Map<QualifiedName,IEObjectDescription>> clusterTypeToName,
                                                 ValidationMessageAcceptor acceptor)

createDuplicateNameError

protected void createDuplicateNameError(IEObjectDescription description,
                                        org.eclipse.emf.ecore.EClass clusterType,
                                        ValidationMessageAcceptor acceptor)

getErrorCode

protected java.lang.String getErrorCode()
Returns null. Clients may override if they desire to attach an error code to the created errors.


getDuplicateNameErrorMessage

public java.lang.String getDuplicateNameErrorMessage(IEObjectDescription description,
                                                     org.eclipse.emf.ecore.EClass clusterType,
                                                     org.eclipse.emf.ecore.EStructuralFeature feature)
Build the error message for duplicated names. The default implementation will provider error messages of this form: If the container information will be helpful to locate the error or to understand the error it will be used, otherwise only the simple format will be build. Clients may override different methods that influence the error message.

See Also:
getNameFeature(EObject), getTypeLabel(EClass), getContainerForErrorMessage(EObject), isContainerInformationHelpful(IEObjectDescription, String), isContainerInformationHelpful(IEObjectDescription, EObject, String, EStructuralFeature)

isContainerInformationHelpful

protected boolean isContainerInformationHelpful(IEObjectDescription description,
                                                org.eclipse.emf.ecore.EObject container,
                                                java.lang.String containerTypeLabel,
                                                org.eclipse.emf.ecore.EStructuralFeature containerNameFeature)

isContainerInformationHelpful

protected boolean isContainerInformationHelpful(IEObjectDescription description,
                                                java.lang.String shortName)

getContainerForErrorMessage

protected org.eclipse.emf.ecore.EObject getContainerForErrorMessage(org.eclipse.emf.ecore.EObject object)

getTypeLabel

protected java.lang.String getTypeLabel(org.eclipse.emf.ecore.EClass eClass)

getNameFeature

protected org.eclipse.emf.ecore.EStructuralFeature getNameFeature(org.eclipse.emf.ecore.EObject object)

getAssociatedClusterType

protected org.eclipse.emf.ecore.EClass getAssociatedClusterType(org.eclipse.emf.ecore.EClass eClass)
Return the type that describes the set of instances that should have unique names. The default information will return the topmost type or the first super type that is contained in the set of cluster types (getClusterTypes()). Only the first super type will be taken into account when walking the hierarchy.