Package org.eclipse.xtext.validation
Class LocalUniqueNameContext
- java.lang.Object
-
- org.eclipse.xtext.validation.LocalUniqueNameContext
-
- All Implemented Interfaces:
ISelectable
,INamesAreUniqueValidationHelper.Context
@Beta public class LocalUniqueNameContext extends java.lang.Object implements INamesAreUniqueValidationHelper.Context, ISelectable
A case-sensitive, local validation context to check unique names in the contents of a container
Sample usage in a validator:EObject
or within a list.class MyDslValidator extends AbstractDeclarativeValidator { @Inject private INamesAreUniqueValidationHelper helper; @Check public void checkUniqueNames(Model model) { helper.checkUniqueNames(new LocalUniqueNameContext(model, getCancelIndicator()), this); } }
- Since:
- 2.22
- See Also:
INamesAreUniqueValidationHelper.checkUniqueNames(Context, ValidationMessageAcceptor)
-
-
Constructor Summary
Constructors Constructor Description LocalUniqueNameContext(java.lang.Iterable<T> objects, java.util.function.Function<T,java.lang.String> nameFunction, org.eclipse.xtext.util.CancelIndicator ci)
LocalUniqueNameContext(java.util.List<? extends org.eclipse.emf.ecore.EObject> objects, org.eclipse.xtext.util.CancelIndicator ci)
LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, boolean deep, java.util.function.Function<org.eclipse.emf.ecore.EObject,java.lang.String> nameFunction, org.eclipse.xtext.util.CancelIndicator ci)
LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, boolean deep, org.eclipse.xtext.util.CancelIndicator ci)
LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, java.util.function.Function<org.eclipse.emf.ecore.EObject,java.lang.String> nameFunction, org.eclipse.xtext.util.CancelIndicator ci)
LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, org.eclipse.xtext.util.CancelIndicator ci)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.eclipse.xtext.util.CancelIndicator
cancelIndicator()
The cancel-indicator that shall be used.java.lang.Iterable<IEObjectDescription>
getExportedObjects()
java.lang.Iterable<IEObjectDescription>
getExportedObjects(org.eclipse.emf.ecore.EClass type, QualifiedName name, boolean ignoreCase)
java.lang.Iterable<IEObjectDescription>
getExportedObjectsByObject(org.eclipse.emf.ecore.EObject object)
java.lang.Iterable<IEObjectDescription>
getExportedObjectsByType(org.eclipse.emf.ecore.EClass type)
java.util.List<IEObjectDescription>
getObjectsToValidate()
Returns the objects that should be checked for uniqueness in the context of theirINamesAreUniqueValidationHelper.Context.getValidationScope(IEObjectDescription, EClass)
.ISelectable
getValidationScope(IEObjectDescription description, org.eclipse.emf.ecore.EClass clusterType)
Returns anISelectable
that can be queried for elements with a given name to find duplicates.boolean
isCaseSensitive(org.eclipse.emf.ecore.EObject candidate, org.eclipse.emf.ecore.EClass clusterType)
Answers whether the names in the given cluster must be treated in a case sensistive or insensitive manner.boolean
isEmpty()
Clients may want to check the selectable to skip its processing in case it is empty.boolean
isUnique()
Context implementations that do know from their construction if they will or won't contain any duplicates, can overrideINamesAreUniqueValidationHelper.Context.isUnique()
to provide a more efficient means to validate allcandidates
at once.
-
-
-
Constructor Detail
-
LocalUniqueNameContext
public LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, java.util.function.Function<org.eclipse.emf.ecore.EObject,java.lang.String> nameFunction, org.eclipse.xtext.util.CancelIndicator ci)
-
LocalUniqueNameContext
public LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, org.eclipse.xtext.util.CancelIndicator ci)
-
LocalUniqueNameContext
public LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, boolean deep, org.eclipse.xtext.util.CancelIndicator ci)
-
LocalUniqueNameContext
public LocalUniqueNameContext(org.eclipse.emf.ecore.EObject container, boolean deep, java.util.function.Function<org.eclipse.emf.ecore.EObject,java.lang.String> nameFunction, org.eclipse.xtext.util.CancelIndicator ci)
-
LocalUniqueNameContext
public LocalUniqueNameContext(java.lang.Iterable<T> objects, java.util.function.Function<T,java.lang.String> nameFunction, org.eclipse.xtext.util.CancelIndicator ci)
-
LocalUniqueNameContext
public LocalUniqueNameContext(java.util.List<? extends org.eclipse.emf.ecore.EObject> objects, org.eclipse.xtext.util.CancelIndicator ci)
-
-
Method Detail
-
isUnique
public boolean isUnique()
Description copied from interface:INamesAreUniqueValidationHelper.Context
Context implementations that do know from their construction if they will or won't contain any duplicates, can overrideINamesAreUniqueValidationHelper.Context.isUnique()
to provide a more efficient means to validate allcandidates
at once.- Specified by:
isUnique
in interfaceINamesAreUniqueValidationHelper.Context
-
isCaseSensitive
public final boolean isCaseSensitive(org.eclipse.emf.ecore.EObject candidate, org.eclipse.emf.ecore.EClass clusterType)
Description copied from interface:INamesAreUniqueValidationHelper.Context
Answers whether the names in the given cluster must be treated in a case sensistive or insensitive manner.- Specified by:
isCaseSensitive
in interfaceINamesAreUniqueValidationHelper.Context
- See Also:
ICaseInsensitivityHelper
-
getValidationScope
public ISelectable getValidationScope(IEObjectDescription description, org.eclipse.emf.ecore.EClass clusterType)
Description copied from interface:INamesAreUniqueValidationHelper.Context
Returns an
ISelectable
that can be queried for elements with a given name to find duplicates.Depending on the type of objects that have to have unique names, different selectables may be returned. Some objects must be unique per project, others must be globally unique or only unique per file. This API allows to fine tune the scope of the validation.
- Specified by:
getValidationScope
in interfaceINamesAreUniqueValidationHelper.Context
- Parameters:
description
- the description of the validated object.clusterType
- the root type of the validated type hierarchy.- Returns:
- the validation scope.
-
getObjectsToValidate
public java.util.List<IEObjectDescription> getObjectsToValidate()
Description copied from interface:INamesAreUniqueValidationHelper.Context
Returns the objects that should be checked for uniqueness in the context of theirINamesAreUniqueValidationHelper.Context.getValidationScope(IEObjectDescription, EClass)
.- Specified by:
getObjectsToValidate
in interfaceINamesAreUniqueValidationHelper.Context
-
cancelIndicator
public org.eclipse.xtext.util.CancelIndicator cancelIndicator()
Description copied from interface:INamesAreUniqueValidationHelper.Context
The cancel-indicator that shall be used.- Specified by:
cancelIndicator
in interfaceINamesAreUniqueValidationHelper.Context
-
getExportedObjects
public java.lang.Iterable<IEObjectDescription> getExportedObjects()
- Specified by:
getExportedObjects
in interfaceISelectable
- Returns:
- all exported elements. May not be
null
.
-
isEmpty
public boolean isEmpty()
Description copied from interface:ISelectable
Clients may want to check the selectable to skip its processing in case it is empty. Implementations should be fast and not require expensive precalculation. Selectable may returnfalse
if it is too expensive to compute the actual result.- Specified by:
isEmpty
in interfaceISelectable
- Returns:
true
if the selectable does not provide any descriptions.
-
getExportedObjects
public java.lang.Iterable<IEObjectDescription> getExportedObjects(org.eclipse.emf.ecore.EClass type, QualifiedName name, boolean ignoreCase)
- Specified by:
getExportedObjects
in interfaceISelectable
- Returns:
- all elements which match the given qualified name and type. May not be
null
.
-
getExportedObjectsByObject
public java.lang.Iterable<IEObjectDescription> getExportedObjectsByObject(org.eclipse.emf.ecore.EObject object)
- Specified by:
getExportedObjectsByObject
in interfaceISelectable
- Returns:
- all elements which match the given instance. May not be
null
.
-
getExportedObjectsByType
public java.lang.Iterable<IEObjectDescription> getExportedObjectsByType(org.eclipse.emf.ecore.EClass type)
- Specified by:
getExportedObjectsByType
in interfaceISelectable
- Returns:
- all elements which match the given type. May not be
null
.
-
-