Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 118338 Details for
Bug 255786
Investigate support for Constraints directly annotated to Ecore
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
some improvements
constraintsDelegator2.patch (text/plain), 63.62 KB, created by
Tristan Faure
on 2008-11-20 04:05:30 EST
(
hide
)
Description:
some improvements
Filename:
MIME Type:
Creator:
Tristan Faure
Created:
2008-11-20 04:05:30 EST
Size:
63.62 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.ecore >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/plugin.xml,v >retrieving revision 1.22 >diff -u -r1.22 plugin.xml >--- plugin.xml 27 Apr 2008 20:27:23 -0000 1.22 >+++ plugin.xml 20 Nov 2008 09:01:03 -0000 >@@ -10,6 +10,7 @@ > <extension-point id="content_handler" name="%_UI_ContentHandlerRegistry_extensionpoint" schema="schema/content_handler.exsd"/> > <extension-point id="uri_mapping" name="%_UI_URIMappingRegistry_extensionpoint" schema="schema/uri_mapping.exsd"/> > <extension-point id="package_registry_implementation" name="%_UI_PackageRegistryImplementation_extensionpoint" schema="schema/package_registry_implementation.exsd"/> >+ <extension-point id="constraints_delegator_registry" name="%_UI_ConstraintsDelegatorRegistry_extensionpoint" schema="schema/constraints_delegator_registry.exsd"/> > > <extension point="org.eclipse.emf.ecore.generated_package"> > <package >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/plugin.properties,v >retrieving revision 1.30 >diff -u -r1.30 plugin.properties >--- plugin.properties 5 May 2008 21:25:31 -0000 1.30 >+++ plugin.properties 20 Nov 2008 09:01:03 -0000 >@@ -113,6 +113,8 @@ > _UI_ContentHandler_extensionpoint = Content Handler Registry > _UI_URIMappingRegistry_extensionpoint = URI Converter Mapping Registry > _UI_PackageRegistryImplementation_extensionpoint = Ecore Package Registry Implementation >+_UI_ConstraintsDelegatorRegistry_extensionpoint = Constraints Delegator Registry >+ > > _UI_GenericInvariant_diagnostic = The ''{0}'' invariant is violated on ''{1}'' > _UI_GenericConstraint_diagnostic = The ''{0}'' constraint is violated on ''{1}'' >Index: src/org/eclipse/emf/ecore/plugin/EcorePlugin.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java,v >retrieving revision 1.23 >diff -u -r1.23 EcorePlugin.java >--- src/org/eclipse/emf/ecore/plugin/EcorePlugin.java 2 Aug 2008 13:40:51 -0000 1.23 >+++ src/org/eclipse/emf/ecore/plugin/EcorePlugin.java 20 Nov 2008 09:01:03 -0000 >@@ -575,6 +575,7 @@ > new ContentParserRegistryReader().readRegistry(); > new ContentHandlerRegistryReader().readRegistry(); > new URIMappingRegistryReader().readRegistry(); >+ new ConstraintsDelegatorFactoryRegistryReader().readRegistry(); > } > } > >@@ -631,4 +632,5 @@ > public static final String SCHEME_PARSER_PPID = "scheme_parser"; > public static final String URI_MAPPING_PPID = "uri_mapping"; > public static final String PACKAGE_REGISTRY_IMPLEMENTATION_PPID = "package_registry_implementation"; >+ public static final String CONSTRAINTS_DELEGATOR_FACTORY = "constraints_delegator_regstry"; > } >\ No newline at end of file >Index: src/org/eclipse/emf/ecore/util/EObjectValidator.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/EObjectValidator.java,v >retrieving revision 1.26 >diff -u -r1.26 EObjectValidator.java >--- src/org/eclipse/emf/ecore/util/EObjectValidator.java 25 May 2008 16:37:42 -0000 1.26 >+++ src/org/eclipse/emf/ecore/util/EObjectValidator.java 20 Nov 2008 09:01:03 -0000 >@@ -16,11 +16,12 @@ > */ > package org.eclipse.emf.ecore.util; > >- > import java.util.ArrayList; > import java.util.Collection; >+import java.util.Collections; > import java.util.HashMap; > import java.util.Iterator; >+import java.util.LinkedList; > import java.util.List; > import java.util.ListIterator; > import java.util.Map; >@@ -37,6 +38,7 @@ > > import org.eclipse.emf.ecore.EValidator; > >+import org.eclipse.emf.ecore.EAnnotation; > import org.eclipse.emf.ecore.EAttribute; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.EClass; >@@ -51,6 +53,7 @@ > > import org.eclipse.emf.ecore.resource.Resource; > import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory; > > import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil; > >@@ -60,6 +63,14 @@ > */ > public class EObjectValidator implements EValidator > { >+ private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY = "factory"; >+ >+ private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_CONSTRAINTS = "constraints"; >+ >+ private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE = "inheritsConstraints"; >+ >+ private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_ECORE = "Ecore"; >+ > public static final EObjectValidator INSTANCE = new EObjectValidator(); > > public static final String DIAGNOSTIC_SOURCE = "org.eclipse.emf.ecore"; >@@ -78,7 +89,7 @@ > public static final int EOBJECT__UNIQUE_ID = 12; > public static final int EOBJECT__EVERY_KEY_UNIQUE = 13; > public static final int EOBJECT__EVERY_MAP_ENTRY_UNIQUE = 14; >- >+ > static final int EOBJECT_DIAGNOSTIC_CODE_COUNT = EOBJECT__EVERY_MAP_ENTRY_UNIQUE; > > /** >@@ -173,10 +184,11 @@ > else > { > List<EClass> eSuperTypes = eClass.getESuperTypes(); >- return >- eSuperTypes.isEmpty() ? >- validate_EveryDefaultConstraint(eObject, diagnostics, context) : >- validate(eSuperTypes.get(0), eObject, diagnostics, context); >+ return eSuperTypes.isEmpty() ? validate_EveryDefaultConstraint(eObject, diagnostics, context) : validate( >+ eSuperTypes.get(0), >+ eObject, >+ diagnostics, >+ context); > } > } > >@@ -212,6 +224,121 @@ > { > result &= validate_EveryMapEntryUnique(object, theDiagnostics, context); > } >+ // ADDS FOR MANAGING USER CONSTRAINTS >+ if (result || theDiagnostics != null) >+ { >+ result &= validate_UserConstraints(object, theDiagnostics, context); >+ } >+ return result; >+ } >+ >+ /** >+ * @since 2.5 >+ * @param object >+ * @param theDiagnostics >+ * @param context >+ * @return >+ */ >+ protected boolean validate_UserConstraints(EObject object, DiagnosticChain theDiagnostics, Map<Object, Object> context) >+ { >+ EClass theclass = object.eClass(); >+ boolean result = validate_UserConstraintsByEClass(theclass, object, theDiagnostics, context); >+ return result; >+ } >+ >+ /** >+ * @since 2.5 >+ * @param theEClass >+ * @param object >+ * @param theDiagnostics >+ * @param context >+ * @return >+ */ >+ protected boolean validate_UserConstraintsByEClass( >+ EClass theEClass, >+ EObject object, >+ DiagnosticChain theDiagnostics, >+ Map<Object, Object> context) >+ { >+ Collection<EAnnotation> annotations = theEClass.getEAnnotations(); >+ Collection<String> constraints = new LinkedList<String>(); >+ String factoryName = ""; >+ String keyName = ""; >+ boolean result = true; >+ boolean inheritsConstraints = true; >+ for (EAnnotation e : annotations) >+ { >+ if (USER_CONSTRAINT_VALIDATION_EANNOTATION_ECORE.equals(e.getSource())) >+ { >+ if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_CONSTRAINTS)) >+ { >+ String strConstraints = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_CONSTRAINTS); >+ >+ String[] stringSplited = strConstraints.split(" "); >+ Collections.addAll(constraints, stringSplited); >+ if (stringSplited != null && stringSplited.length > 0) >+ { >+ if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY)) >+ { >+ String strFactory = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY); >+ String[] strs = strFactory.split("#"); >+ if (strs != null && strs.length == 2) >+ { >+ factoryName = strs[0]; >+ keyName = strs[1]; >+ } >+ else >+ { >+ factoryName = strFactory; >+ keyName = strFactory; >+ } >+ // check if user specifies how to manage constraints inheritance >+ if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE)) >+ { >+ String value = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE); >+ if (value != null && ("true".equals(value.trim().toLowerCase()) || "false".equals(value.trim().toLowerCase()))) >+ { >+ inheritsConstraints = Boolean.valueOf(value); >+ } >+ } >+ } >+ } >+ break; >+ } >+ } >+ } >+ if (constraints.size() > 0 && keyName.length() > 0 && factoryName.length() > 0) >+ { >+ for (String currentConstraint : constraints) >+ { >+ for (EAnnotation e : annotations) >+ { >+ if (keyName.equals(e.getSource())) >+ { >+ if (e.getDetails().containsKey(currentConstraint)) >+ { >+ String rule = e.getDetails().get(currentConstraint); >+ Factory factory = ConstraintsDelegator.Factory.Registry.INSTANCE.getFactory(factoryName); >+ if (factory != null) >+ { >+ ConstraintsDelegator constraintDelegator = factory.createConstraintDelegator(); >+ if (constraintDelegator != null) >+ { >+ if (inheritsConstraints) >+ { >+ for (EClass c : theEClass.getESuperTypes()) >+ { >+ result &= validate_UserConstraintsByEClass(c, object, theDiagnostics, context); >+ } >+ } >+ result &= constraintDelegator.validate(rule, object, theDiagnostics, context); >+ } >+ } >+ } >+ } >+ } >+ } >+ } > return result; > } > >@@ -229,9 +356,12 @@ > } > return result; > } >- >- protected boolean validate_MultiplicityConforms >- (EObject eObject, EStructuralFeature eStructuralFeature, DiagnosticChain diagnostics, Map<Object, Object> context) >+ >+ protected boolean validate_MultiplicityConforms( >+ EObject eObject, >+ EStructuralFeature eStructuralFeature, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) > { > boolean result = true; > if (eStructuralFeature.isMany()) >@@ -239,27 +369,20 @@ > int lowerBound = eStructuralFeature.getLowerBound(); > if (lowerBound > 0) > { >- int size = ((List<?>)eObject.eGet(eStructuralFeature)).size(); >+ int size = ((List< ? >)eObject.eGet(eStructuralFeature)).size(); > if (size < lowerBound) > { > result = false; > if (diagnostics != null) > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_MULTIPCITY_CONFORMS, >- "_UI_FeatureHasTooFewValues_diagnostic", >- new Object [] >- { >- getFeatureLabel(eStructuralFeature, context), >- getObjectLabel(eObject, context), >- size, >- lowerBound >- }, >- new Object [] { eObject, eStructuralFeature }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_MULTIPCITY_CONFORMS, >+ "_UI_FeatureHasTooFewValues_diagnostic", >+ new Object []{ getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context), size, lowerBound }, >+ new Object []{ eObject, eStructuralFeature }, >+ context)); > } > } > int upperBound = eStructuralFeature.getUpperBound(); >@@ -268,21 +391,18 @@ > result = false; > if (diagnostics != null) > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_MULTIPCITY_CONFORMS, >- "_UI_FeatureHasTooManyValues_diagnostic", >- new Object [] >- { >- getFeatureLabel(eStructuralFeature, context), >- getObjectLabel(eObject, context), >- new Integer(size), >- new Integer(upperBound) >- }, >- new Object [] { eObject, eStructuralFeature }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_MULTIPCITY_CONFORMS, >+ "_UI_FeatureHasTooManyValues_diagnostic", >+ new Object []{ >+ getFeatureLabel(eStructuralFeature, context), >+ getObjectLabel(eObject, context), >+ new Integer(size), >+ new Integer(upperBound) }, >+ new Object []{ eObject, eStructuralFeature }, >+ context)); > } > } > } >@@ -291,27 +411,24 @@ > int upperBound = eStructuralFeature.getUpperBound(); > if (upperBound > 0) > { >- int size = ((List<?>)eObject.eGet(eStructuralFeature)).size(); >+ int size = ((List< ? >)eObject.eGet(eStructuralFeature)).size(); > if (size > upperBound) > { > result = false; > if (diagnostics != null) > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_MULTIPCITY_CONFORMS, >- "_UI_FeatureHasTooManyValues_diagnostic", >- new Object [] >- { >- getFeatureLabel(eStructuralFeature, context), >- getObjectLabel(eObject, context), >- new Integer(size), >- new Integer(upperBound) >- }, >- new Object [] { eObject, eStructuralFeature }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_MULTIPCITY_CONFORMS, >+ "_UI_FeatureHasTooManyValues_diagnostic", >+ new Object []{ >+ getFeatureLabel(eStructuralFeature, context), >+ getObjectLabel(eObject, context), >+ new Integer(size), >+ new Integer(upperBound) }, >+ new Object []{ eObject, eStructuralFeature }, >+ context)); > } > } > } >@@ -324,15 +441,14 @@ > result = false; > if (diagnostics != null) > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_MULTIPCITY_CONFORMS, >- "_UI_RequiredFeatureMustBeSet_diagnostic", >- new Object [] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) }, >- new Object [] { eObject, eStructuralFeature }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_MULTIPCITY_CONFORMS, >+ "_UI_RequiredFeatureMustBeSet_diagnostic", >+ new Object []{ getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) }, >+ new Object []{ eObject, eStructuralFeature }, >+ context)); > } > } > } >@@ -343,7 +459,7 @@ > public boolean validate_EveryProxyResolves(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) > { > boolean result = true; >- for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext(); ) >+ for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();) > { > EObject eCrossReferenceObject = i.next(); > if (eCrossReferenceObject.eIsProxy()) >@@ -351,20 +467,17 @@ > result = false; > if (diagnostics != null) > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_PROXY_RESOLVES, >- "_UI_UnresolvedProxy_diagnostic", >- new Object [] >- { >- getFeatureLabel(i.feature(), context), >- getObjectLabel(eObject, context), >- getObjectLabel(eCrossReferenceObject, context) >- }, >- new Object [] { eObject, i.feature(), eCrossReferenceObject }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_PROXY_RESOLVES, >+ "_UI_UnresolvedProxy_diagnostic", >+ new Object []{ >+ getFeatureLabel(i.feature(), context), >+ getObjectLabel(eObject, context), >+ getObjectLabel(eCrossReferenceObject, context) }, >+ new Object []{ eObject, i.feature(), eCrossReferenceObject }, >+ context)); > } > else > { >@@ -380,7 +493,7 @@ > boolean result = true; > if (eObject.eResource() != null) > { >- for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext(); ) >+ for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();) > { > EObject eCrossReferenceObject = i.next(); > if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !i.feature().isTransient()) >@@ -388,20 +501,17 @@ > result = false; > if (diagnostics != null) > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_REFERENCE_IS_CONTAINED, >- "_UI_DanglingReference_diagnostic", >- new Object [] >- { >- getFeatureLabel(i.feature(), context), >- getObjectLabel(eObject, context), >- getObjectLabel(eCrossReferenceObject, context) >- }, >- new Object [] { eObject, i.feature(), eCrossReferenceObject }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_REFERENCE_IS_CONTAINED, >+ "_UI_DanglingReference_diagnostic", >+ new Object []{ >+ getFeatureLabel(i.feature(), context), >+ getObjectLabel(eObject, context), >+ getObjectLabel(eCrossReferenceObject, context) }, >+ new Object []{ eObject, i.feature(), eCrossReferenceObject }, >+ context)); > } > else > { >@@ -427,8 +537,11 @@ > return result; > } > >- protected boolean validate_DataValueConforms >- (EObject eObject, EAttribute eAttribute, DiagnosticChain diagnostics, Map<Object, Object> context) >+ protected boolean validate_DataValueConforms( >+ EObject eObject, >+ EAttribute eAttribute, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) > { > if (!eObject.eIsSet(eAttribute)) > { >@@ -440,15 +553,15 @@ > Object value = eObject.eGet(eAttribute); > if (FeatureMapUtil.isFeatureMap(eAttribute)) > { >- @SuppressWarnings("unchecked") Collection<FeatureMap.Entry> featureMap = (Collection<FeatureMap.Entry>)value; >+ @SuppressWarnings("unchecked") >+ Collection<FeatureMap.Entry> featureMap = (Collection<FeatureMap.Entry>)value; > EClass eClass = eObject.eClass(); > Map<EStructuralFeature, DiagnosticChain> entryFeatureToDiagnosticChainMap = null; >- for (Iterator<FeatureMap.Entry> i = featureMap.iterator(); i.hasNext() && (result || diagnostics != null); ) >+ for (Iterator<FeatureMap.Entry> i = featureMap.iterator(); i.hasNext() && (result || diagnostics != null);) > { > FeatureMap.Entry entry = i.next(); > EStructuralFeature entryFeature = entry.getEStructuralFeature(); >- if (entryFeature instanceof EAttribute && >- ExtendedMetaData.INSTANCE.getAffiliation(eClass, entryFeature) == eAttribute) >+ if (entryFeature instanceof EAttribute && ExtendedMetaData.INSTANCE.getAffiliation(eClass, entryFeature) == eAttribute) > { > EDataType entryType = (EDataType)entryFeature.getEType(); > Object entryValue = entry.getValue(); >@@ -476,7 +589,7 @@ > } > else if (eAttribute.isMany()) > { >- for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && result; ) >+ for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && result;) > { > result &= rootValidator.validate(eDataType, i.next(), null, context); > } >@@ -484,7 +597,7 @@ > if (!result && diagnostics != null) > { > DiagnosticChain diagnostic = createBadDataValueDiagnostic(eObject, eAttribute, diagnostics, context); >- for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext(); ) >+ for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext();) > { > rootValidator.validate(eDataType, i.next(), diagnostic, context); > } >@@ -503,33 +616,35 @@ > return result; > } > >- protected DiagnosticChain createBadDataValueDiagnostic >- (EObject eObject, EAttribute eAttribute, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- BasicDiagnostic diagnostic = >- createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_DATA_VALUE_CONFORMS, >- "_UI_BadDataValue_diagnostic", >- new Object [] >- { >- getFeatureLabel(eAttribute, context), >- getObjectLabel(eObject, context) >- }, >- new Object [] { eObject, eAttribute }, >- context); >+ protected DiagnosticChain createBadDataValueDiagnostic( >+ EObject eObject, >+ EAttribute eAttribute, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ BasicDiagnostic diagnostic = createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_DATA_VALUE_CONFORMS, >+ "_UI_BadDataValue_diagnostic", >+ new Object []{ getFeatureLabel(eAttribute, context), getObjectLabel(eObject, context) }, >+ new Object []{ eObject, eAttribute }, >+ context); > diagnostics.add(diagnostic); > return diagnostic; > } > >- protected boolean validatePattern >- (EDataType eDataType, Object value, PatternMatcher [][] patterns, DiagnosticChain diagnostics, Map<Object, Object> context) >+ protected boolean validatePattern( >+ EDataType eDataType, >+ Object value, >+ PatternMatcher[][] patterns, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) > { > String literal = EcoreUtil.convertToString(eDataType, value); > for (int i = 0; i < patterns.length; ++i) > { >- PatternMatcher [] children = patterns[i]; >+ PatternMatcher[] children = patterns[i]; > boolean matches = false; > for (int j = 0; j < children.length; ++j) > { >@@ -554,7 +669,7 @@ > public class DynamicEDataTypeValidator > { > protected List<Object> effectiveEnumeration; >- protected PatternMatcher [][] effectivePattern; >+ protected PatternMatcher[][] effectivePattern; > protected int effectiveTotalDigits = -1; > protected int effectiveFractionDigits = -1; > protected int effectiveMinLength = -1; >@@ -605,9 +720,9 @@ > { > patterns = new ArrayList<PatternMatcher[]>(); > } >- PatternMatcher [] children = new PatternMatcher [pattern.size()]; >+ PatternMatcher[] children = new PatternMatcher [pattern.size()]; > patterns.add(children); >- for (ListIterator<String> i = pattern.listIterator(); i.hasNext(); ) >+ for (ListIterator<String> i = pattern.listIterator(); i.hasNext();) > { > PatternMatcher patternMatcher = XMLTypeUtil.createPatternMatcher(i.next()); > children[i.previousIndex()] = patternMatcher; >@@ -691,7 +806,7 @@ > > if (patterns != null) > { >- effectivePattern = new PatternMatcher [patterns.size()][]; >+ effectivePattern = new PatternMatcher [patterns.size()] []; > patterns.toArray(effectivePattern); > } > >@@ -702,14 +817,15 @@ > { > digits.append("0"); > } >- >+ > try > { > Object lowerBound = EcoreUtil.createFromString(eDataType, "-" + digits.toString()); >- @SuppressWarnings("unchecked") boolean lowerBounded = effectiveMin == null || >- (effectiveMinIsInclusive ? >- ((Comparable<Object>)effectiveMin).compareTo(lowerBound) <= 0: >- ((Comparable<Object>)effectiveMin).compareTo(lowerBound) < 0); >+ @SuppressWarnings("unchecked") >+ boolean lowerBounded = effectiveMin == null >+ || (effectiveMinIsInclusive >+ ? ((Comparable<Object>)effectiveMin).compareTo(lowerBound) <= 0 >+ : ((Comparable<Object>)effectiveMin).compareTo(lowerBound) < 0); > if (lowerBounded) > { > effectiveMinIsInclusive = false; >@@ -717,7 +833,7 @@ > effectiveTotalDigitsMin = effectiveTotalDigits; > } > } >- catch (NumberFormatException exception) >+ catch (NumberFormatException exception) > { > // Ignore the bound if the value is too big. > } >@@ -725,10 +841,11 @@ > try > { > Object upperBound = EcoreUtil.createFromString(eDataType, digits.toString()); >- @SuppressWarnings("unchecked") boolean upperBounded = effectiveMax == null || >- (effectiveMaxIsInclusive ? >- ((Comparable<Object>)effectiveMax).compareTo(upperBound) >= 0: >- ((Comparable<Object>)effectiveMax).compareTo(upperBound) > 0); >+ @SuppressWarnings("unchecked") >+ boolean upperBounded = effectiveMax == null >+ || (effectiveMaxIsInclusive >+ ? ((Comparable<Object>)effectiveMax).compareTo(upperBound) >= 0 >+ : ((Comparable<Object>)effectiveMax).compareTo(upperBound) > 0); > if (upperBounded) > { > effectiveMaxIsInclusive = false; >@@ -736,7 +853,7 @@ > effectiveTotalDigitsMax = effectiveTotalDigits; > } > } >- catch (NumberFormatException exception) >+ catch (NumberFormatException exception) > { > // Ignore the bound if the value is too big. > } >@@ -757,7 +874,8 @@ > { > if (!effectiveEnumeration.contains(value)) > { >- if (diagnostics != null) reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); >+ if (diagnostics != null) >+ reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); > result = false; > } > } >@@ -769,10 +887,9 @@ > > if (effectiveMin != null) > { >- @SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; >- if (effectiveMinIsInclusive ? >- comparableObject.compareTo(value) > 0: >- comparableObject.compareTo(value) >= 0) >+ @SuppressWarnings("unchecked") >+ Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; >+ if (effectiveMinIsInclusive ? comparableObject.compareTo(value) > 0 : comparableObject.compareTo(value) >= 0) > { > if (diagnostics != null) > { >@@ -791,10 +908,9 @@ > > if (effectiveMax != null) > { >- @SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; >- if (effectiveMaxIsInclusive ? >- comparableObject.compareTo(value) < 0: >- comparableObject.compareTo(value) <= 0) >+ @SuppressWarnings("unchecked") >+ Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; >+ if (effectiveMaxIsInclusive ? comparableObject.compareTo(value) < 0 : comparableObject.compareTo(value) <= 0) > { > if (diagnostics != null) > { >@@ -813,30 +929,24 @@ > > if (effectiveMinLength != -1) > { >- int length = >- value instanceof String ? >- ((String)value).length() : >- value instanceof Collection ? >- ((Collection<?>)value).size() : >- Array.getLength(value); >+ int length = value instanceof String ? ((String)value).length() : value instanceof Collection >+ ? ((Collection< ? >)value).size() : Array.getLength(value); > if (length < effectiveMinLength) > { >- if (diagnostics != null) reportMinLengthViolation(eDataType, value, length, effectiveMinLength, diagnostics, context); >+ if (diagnostics != null) >+ reportMinLengthViolation(eDataType, value, length, effectiveMinLength, diagnostics, context); > result = false; > } > } > > if (effectiveMaxLength != -1) > { >- int length = >- value instanceof String ? >- ((String)value).length() : >- value instanceof Collection ? >- ((Collection<?>)value).size() : >- Array.getLength(value); >+ int length = value instanceof String ? ((String)value).length() : value instanceof Collection >+ ? ((Collection< ? >)value).size() : Array.getLength(value); > if (length > effectiveMaxLength) > { >- if (diagnostics != null) reportMaxLengthViolation(eDataType, value, length, effectiveMaxLength, diagnostics, context); >+ if (diagnostics != null) >+ reportMaxLengthViolation(eDataType, value, length, effectiveMaxLength, diagnostics, context); > result = false; > } > } >@@ -845,7 +955,8 @@ > { > if (value instanceof BigDecimal && ((BigDecimal)value).unscaledValue().abs().toString().length() > effectiveTotalDigits) > { >- if (diagnostics != null) reportTotalDigitsViolation(eDataType, value, effectiveTotalDigits, diagnostics, context); >+ if (diagnostics != null) >+ reportTotalDigitsViolation(eDataType, value, effectiveTotalDigits, diagnostics, context); > result = false; > } > } >@@ -854,7 +965,8 @@ > { > if (value instanceof BigDecimal && ((BigDecimal)value).scale() > effectiveFractionDigits) > { >- if (diagnostics != null) reportFractionDigitsViolation(eDataType, value, effectiveFractionDigits, diagnostics, context); >+ if (diagnostics != null) >+ reportFractionDigitsViolation(eDataType, value, effectiveFractionDigits, diagnostics, context); > result = false; > } > } >@@ -862,7 +974,7 @@ > if (itemType != null) > { > EValidator rootValidator = getRootEValidator(context); >- for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && (result || diagnostics != null); ) >+ for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && (result || diagnostics != null);) > { > result &= rootValidator.validate(itemType, i.next(), diagnostics, context); > } >@@ -871,7 +983,7 @@ > else if (!memberTypes.isEmpty()) > { > EValidator rootValidator = getRootEValidator(context); >- >+ > for (EDataType memberType : memberTypes) > { > if (rootValidator.validate(memberType, value, null, context)) >@@ -905,7 +1017,8 @@ > } > else > { >- if (diagnostics != null) reportDataValueTypeViolation(eDataType, value, diagnostics, context); >+ if (diagnostics != null) >+ reportDataValueTypeViolation(eDataType, value, diagnostics, context); > return false; > } > } >@@ -916,8 +1029,7 @@ > } > else > { >- return >- new DynamicEDataTypeValidator(eDataType) >+ return new DynamicEDataTypeValidator(eDataType) > { > // Ensure that the class loader for this class will be used downstream. > // >@@ -925,202 +1037,184 @@ > } > } > >- protected void reportMinViolation >- (EDataType eDataType, Object value, Object bound, boolean isInclusive, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__VALUE_IN_RANGE, >- isInclusive ? "_UI_MinInclusiveConstraint_diagnostic" : "_UI_MinExclusiveConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- isInclusive ? ">=" : ">", >- getValueLabel(eDataType, bound, context) >- }, >- new Object [] { value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, >- context)); >- } >- >- protected void reportMaxViolation >- (EDataType eDataType, Object value, Object bound, boolean isInclusive, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__VALUE_IN_RANGE, >- isInclusive ? "_UI_MaxInclusiveConstraint_diagnostic" : "_UI_MaxExclusiveConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- "<", >- getValueLabel(eDataType, bound, context) >- }, >- new Object [] { value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, >- context)); >- } >- >- protected void reportMinLengthViolation >- (EDataType eDataType, Object value, int length, int bound, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__LENGTH_IN_RANGE, >- "_UI_MinLengthConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- Integer.toString(length), >- Integer.toString(bound) >- }, >- new Object [] { value, eDataType, length, bound }, >- context)); >- } >- >- protected void reportMaxLengthViolation >- (EDataType eDataType, Object value, int length, int bound, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__LENGTH_IN_RANGE, >- "_UI_MaxLengthConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- Integer.toString(length), >- Integer.toString(bound) >- }, >- new Object [] { value, eDataType, length, bound }, >- context)); >- } >- >- protected void reportTotalDigitsViolation >- (EDataType eDataType, Object value, int totalDigits, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__TOTAL_DIGITS_IN_RANGE, >- "_UI_TotalDigitsConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- totalDigits >- }, >- new Object [] { value, eDataType, totalDigits }, >- context)); >- } >- >- protected void reportFractionDigitsViolation >- (EDataType eDataType, Object value, int fractionDigits, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__TOTAL_DIGITS_IN_RANGE, >- "_UI_FractionDigitsConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- fractionDigits >- }, >- new Object [] { value, eDataType, fractionDigits }, >- context)); >- } >- >- protected void reportEnumerationViolation >- (EDataType eDataType, Object value, Collection<?> values, DiagnosticChain diagnostics, Map<Object, Object> context) >+ protected void reportMinViolation( >+ EDataType eDataType, >+ Object value, >+ Object bound, >+ boolean isInclusive, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, DATA_VALUE__VALUE_IN_RANGE, isInclusive >+ ? "_UI_MinInclusiveConstraint_diagnostic" : "_UI_MinExclusiveConstraint_diagnostic", new Object []{ >+ getValueLabel(eDataType, value, context), >+ isInclusive ? ">=" : ">", >+ getValueLabel(eDataType, bound, context) }, new Object []{ value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, context)); >+ } >+ >+ protected void reportMaxViolation( >+ EDataType eDataType, >+ Object value, >+ Object bound, >+ boolean isInclusive, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, DATA_VALUE__VALUE_IN_RANGE, isInclusive >+ ? "_UI_MaxInclusiveConstraint_diagnostic" : "_UI_MaxExclusiveConstraint_diagnostic", new Object []{ >+ getValueLabel(eDataType, value, context), >+ "<", >+ getValueLabel(eDataType, bound, context) }, new Object []{ value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, context)); >+ } >+ >+ protected void reportMinLengthViolation( >+ EDataType eDataType, >+ Object value, >+ int length, >+ int bound, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__LENGTH_IN_RANGE, >+ "_UI_MinLengthConstraint_diagnostic", >+ new Object []{ getValueLabel(eDataType, value, context), Integer.toString(length), Integer.toString(bound) }, >+ new Object []{ value, eDataType, length, bound }, >+ context)); >+ } >+ >+ protected void reportMaxLengthViolation( >+ EDataType eDataType, >+ Object value, >+ int length, >+ int bound, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__LENGTH_IN_RANGE, >+ "_UI_MaxLengthConstraint_diagnostic", >+ new Object []{ getValueLabel(eDataType, value, context), Integer.toString(length), Integer.toString(bound) }, >+ new Object []{ value, eDataType, length, bound }, >+ context)); >+ } >+ >+ protected void reportTotalDigitsViolation( >+ EDataType eDataType, >+ Object value, >+ int totalDigits, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__TOTAL_DIGITS_IN_RANGE, >+ "_UI_TotalDigitsConstraint_diagnostic", >+ new Object []{ getValueLabel(eDataType, value, context), totalDigits }, >+ new Object []{ value, eDataType, totalDigits }, >+ context)); >+ } >+ >+ protected void reportFractionDigitsViolation( >+ EDataType eDataType, >+ Object value, >+ int fractionDigits, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__TOTAL_DIGITS_IN_RANGE, >+ "_UI_FractionDigitsConstraint_diagnostic", >+ new Object []{ getValueLabel(eDataType, value, context), fractionDigits }, >+ new Object []{ value, eDataType, fractionDigits }, >+ context)); >+ } >+ >+ protected void reportEnumerationViolation( >+ EDataType eDataType, >+ Object value, >+ Collection< ? > values, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) > { > String valueLiterals = ""; >- Iterator<?> i = values.iterator(); >+ Iterator< ? > i = values.iterator(); > if (i.hasNext()) > { >- valueLiterals = >- getEcoreResourceLocator().getString("_UI_ListHead_composition", new Object [] { getValueLabel(eDataType, i.next(), context) }); >+ valueLiterals = getEcoreResourceLocator().getString( >+ "_UI_ListHead_composition", >+ new Object []{ getValueLabel(eDataType, i.next(), context) }); > while (i.hasNext()) > { >- valueLiterals = >- getEcoreResourceLocator().getString >- ("_UI_ListTail_composition", >- new Object [] { valueLiterals, getValueLabel(eDataType, i.next(), context) }); >- } >- } >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__VALUE_IN_ENUMERATION, >- "_UI_EnumerationConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- valueLiterals >- }, >- new Object [] { value, eDataType, values }, >- context)); >- } >- >- protected void reportDataValuePatternViolation >- (EDataType eDataType, Object value, PatternMatcher [] patterns, DiagnosticChain diagnostics, Map<Object, Object> context) >+ valueLiterals = getEcoreResourceLocator().getString( >+ "_UI_ListTail_composition", >+ new Object []{ valueLiterals, getValueLabel(eDataType, i.next(), context) }); >+ } >+ } >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__VALUE_IN_ENUMERATION, >+ "_UI_EnumerationConstraint_diagnostic", >+ new Object []{ getValueLabel(eDataType, value, context), valueLiterals }, >+ new Object []{ value, eDataType, values }, >+ context)); >+ } >+ >+ protected void reportDataValuePatternViolation( >+ EDataType eDataType, >+ Object value, >+ PatternMatcher[] patterns, >+ DiagnosticChain diagnostics, >+ Map<Object, Object> context) > { > String patternLiterals = ""; > if (patterns.length > 0) > { >- patternLiterals = getEcoreResourceLocator().getString("_UI_ListHead_composition", new Object [] { patterns[0] }); >+ patternLiterals = getEcoreResourceLocator().getString("_UI_ListHead_composition", new Object []{ patterns[0] }); > for (int i = 1; i < patterns.length; ++i) > { >- patternLiterals = getEcoreResourceLocator().getString("_UI_ListTail_composition", new Object [] { patternLiterals, patterns[i] }); >+ patternLiterals = getEcoreResourceLocator().getString("_UI_ListTail_composition", new Object []{ patternLiterals, patterns[i] }); > } > } > >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__MATCHES_PATTERN, >- "_UI_PatternConstraint_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- patternLiterals >- }, >- new Object [] { value, eDataType, patterns }, >- context)); >- } >- >- protected void reportDataValueTypeViolation >- (EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) >- { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- DATA_VALUE__TYPE_CORRECT, >- "_UI_BadDataValueType_diagnostic", >- new Object [] >- { >- getValueLabel(eDataType, value, context), >- value == null ? "<null>" : value.getClass().getName(), >- eDataType.getInstanceClass().getName() >- }, >- new Object [] { value, eDataType }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__MATCHES_PATTERN, >+ "_UI_PatternConstraint_diagnostic", >+ new Object []{ getValueLabel(eDataType, value, context), patternLiterals }, >+ new Object []{ value, eDataType, patterns }, >+ context)); >+ } >+ >+ protected void reportDataValueTypeViolation(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) >+ { >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ DATA_VALUE__TYPE_CORRECT, >+ "_UI_BadDataValueType_diagnostic", >+ new Object []{ >+ getValueLabel(eDataType, value, context), >+ value == null ? "<null>" : value.getClass().getName(), >+ eDataType.getInstanceClass().getName() }, >+ new Object []{ value, eDataType }, >+ context)); > } > >- protected static Collection<Object> wrapEnumerationValues(Object [] values) >+ protected static Collection<Object> wrapEnumerationValues(Object[] values) > { > return java.util.Arrays.asList(values); > } >- >+ > /** > * @since 2.2 > */ >@@ -1137,20 +1231,14 @@ > if (eObject != otherEObject && otherEObject != null) > { > // ... >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__UNIQUE_ID, >- "_UI_DuplicateID_diagnostic", >- new Object [] >- { >- id, >- getObjectLabel(eObject, context), >- getObjectLabel(otherEObject, context) >- }, >- new Object [] { eObject, otherEObject, id }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__UNIQUE_ID, >+ "_UI_DuplicateID_diagnostic", >+ new Object []{ id, getObjectLabel(eObject, context), getObjectLabel(otherEObject, context) }, >+ new Object []{ eObject, otherEObject, id }, >+ context)); > } > } > } >@@ -1186,7 +1274,7 @@ > } > return result; > } >- >+ > /** > * @since 2.3 > * @param eObject >@@ -1195,17 +1283,16 @@ > * @param context > * @return whether every key is unique. > */ >- protected boolean validate_KeyUnique >- (EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) >+ protected boolean validate_KeyUnique(EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) > { > boolean result = true; > Map<List<Object>, EObject> keys = new HashMap<List<Object>, EObject>(); >- EAttribute [] eAttributes = (EAttribute[])((BasicEList<?>)eReference.getEKeys()).data(); >+ EAttribute[] eAttributes = (EAttribute[])((BasicEList< ? >)eReference.getEKeys()).data(); > @SuppressWarnings("unchecked") > List<EObject> values = (List<EObject>)eObject.eGet(eReference); > for (EObject value : values) > { >- ArrayList<Object> key = new ArrayList<Object>(); >+ ArrayList<Object> key = new ArrayList<Object>(); > for (int i = 0, size = eAttributes.length; i < size; ++i) > { > EAttribute eAttribute = eAttributes[i]; >@@ -1213,7 +1300,7 @@ > { > break; > } >- else >+ else > { > key.add(value.eGet(eAttribute)); > } >@@ -1234,21 +1321,18 @@ > { > uriFragmentSegment = uriFragmentSegment.substring(index); > } >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_KEY_UNIQUE, >- "_UI_DuplicateKey_diagnostic", >- new Object [] >- { >- getFeatureLabel(eReference, context), >- uriFragmentSegment, >- getObjectLabel(value, context), >- getObjectLabel(otherValue, context) >- }, >- new Object [] { eObject, eReference, value, otherValue }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_KEY_UNIQUE, >+ "_UI_DuplicateKey_diagnostic", >+ new Object []{ >+ getFeatureLabel(eReference, context), >+ uriFragmentSegment, >+ getObjectLabel(value, context), >+ getObjectLabel(otherValue, context) }, >+ new Object []{ eObject, eReference, value, otherValue }, >+ context)); > } > } > } >@@ -1291,19 +1375,18 @@ > * @param context > * @return whether every map entry is unique. > */ >- protected boolean validate_MapEntryUnique >- (EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) >+ protected boolean validate_MapEntryUnique(EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) > { > boolean result = true; > Object value = eObject.eGet(eReference); > if (value instanceof EMap) > { >- EMap<?, ?> eMap = (EMap<?, ?>)value; >+ EMap< ? , ? > eMap = (EMap< ? , ? >)value; > for (int i = 0, size = eMap.size(); i < size; ++i) > { >- Map.Entry<?, ?> entry = eMap.get(i); >+ Map.Entry< ? , ? > entry = eMap.get(i); > Object key = entry.getKey(); >- int index = eMap.indexOfKey(key); >+ int index = eMap.indexOfKey(key); > if (index != i) > { > result = false; >@@ -1313,20 +1396,14 @@ > } > else > { >- diagnostics.add >- (createDiagnostic >- (Diagnostic.ERROR, >- DIAGNOSTIC_SOURCE, >- EOBJECT__EVERY_MAP_ENTRY_UNIQUE, >- "_UI_DuplicateMapEntry_diagnostic", >- new Object [] >- { >- getFeatureLabel(eReference, context), >- i, >- index >- }, >- new Object [] { eObject, eReference, entry, eMap.get(index) }, >- context)); >+ diagnostics.add(createDiagnostic( >+ Diagnostic.ERROR, >+ DIAGNOSTIC_SOURCE, >+ EOBJECT__EVERY_MAP_ENTRY_UNIQUE, >+ "_UI_DuplicateMapEntry_diagnostic", >+ new Object []{ getFeatureLabel(eReference, context), i, index }, >+ new Object []{ eObject, eReference, entry, eMap.get(index) }, >+ context)); > } > } > } >@@ -1351,13 +1428,18 @@ > * @see BasicDiagnostic#BasicDiagnostic(int, String, int, String, Object[]) > * @since 2.4 > */ >- protected BasicDiagnostic createDiagnostic >- (int severity, String source, int code, String messageKey, Object[] messageSubstitutions, Object[] data, Map<Object, Object> context) >- { >- String message = >- DIAGNOSTIC_SOURCE.equals(source) ? >- getEcoreString(messageKey, messageSubstitutions) : >- getString(messageKey, messageSubstitutions); >+ protected BasicDiagnostic createDiagnostic( >+ int severity, >+ String source, >+ int code, >+ String messageKey, >+ Object[] messageSubstitutions, >+ Object[] data, >+ Map<Object, Object> context) >+ { >+ String message = DIAGNOSTIC_SOURCE.equals(source) ? getEcoreString(messageKey, messageSubstitutions) : getString( >+ messageKey, >+ messageSubstitutions); > return new BasicDiagnostic(severity, source, code, message, data); > } > >@@ -1369,7 +1451,7 @@ > * @return the message. > * @since 2.4 > */ >- protected String getEcoreString(String key, Object [] substitutions) >+ protected String getEcoreString(String key, Object[] substitutions) > { > return getString(getEcoreResourceLocator(), key, substitutions); > } >@@ -1392,7 +1474,7 @@ > * @return the message. > * @since 2.4 > */ >- protected String getString(String key, Object [] substitutions) >+ protected String getString(String key, Object[] substitutions) > { > return getString("_UI_GenericConstraint_diagnostic".equals(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); > } >@@ -1409,7 +1491,7 @@ > return getEcoreResourceLocator(); > } > >- private String getString(ResourceLocator resourceLocator, String key, Object [] substitutions) >+ private String getString(ResourceLocator resourceLocator, String key, Object[] substitutions) > { > return substitutions == null ? resourceLocator.getString(key) : resourceLocator.getString(key, substitutions); > } >Index: src/org/eclipse/emf/ecore/plugin/ConstraintsDelegatorFactoryRegistryReader.java >=================================================================== >RCS file: src/org/eclipse/emf/ecore/plugin/ConstraintsDelegatorFactoryRegistryReader.java >diff -N src/org/eclipse/emf/ecore/plugin/ConstraintsDelegatorFactoryRegistryReader.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/ecore/plugin/ConstraintsDelegatorFactoryRegistryReader.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id: EMF_codetemplates.xml,v 1.1 2008/05/06 20:12:20 nickb Exp $ >+ */ >+package org.eclipse.emf.ecore.plugin; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.emf.common.util.WrappedException; >+import org.eclipse.emf.ecore.util.ConstraintsDelegator; >+import org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory; >+ >+/** >+ * A plugin extension reader that populates the >+ * {@link org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory.Registry#INSTANCE global} resource factory's >+ * Clients are not expected to use this class directly. >+ */ >+public class ConstraintsDelegatorFactoryRegistryReader extends RegistryReader >+{ >+ static final String TAG_FACTORY = "factory"; >+ static final String ATT_URI = "uri"; >+ static final String ATT_CLASS = "class"; >+ >+ public ConstraintsDelegatorFactoryRegistryReader() >+ { >+ super >+ (Platform.getExtensionRegistry(), >+ EcorePlugin.getPlugin().getBundle().getSymbolicName(), >+ EcorePlugin.CONSTRAINTS_DELEGATOR_FACTORY); >+ } >+ >+ @Override >+ protected boolean readElement(IConfigurationElement element, boolean add) >+ { >+ if (element.getName().equals(TAG_FACTORY)) >+ { >+ String packageURI = element.getAttribute(ATT_URI); >+ if (packageURI == null) >+ { >+ logMissingAttribute(element, ATT_URI); >+ } >+ else if (element.getAttribute(ATT_CLASS) == null) >+ { >+ logMissingAttribute(element, ATT_CLASS); >+ } >+ else >+ { >+ try >+ { >+ Object o = element.createExecutableExtension(ATT_CLASS); >+ if (o instanceof ConstraintsDelegator.Factory) >+ { >+ Factory tmp = ConstraintsDelegator.Factory.Registry.INSTANCE.getFactory(packageURI); >+ if (tmp != null) >+ { >+ EcorePlugin.INSTANCE.log >+ ("factory '" + o.getClass().getName() + "'tries to override '" + packageURI + "' instead of factor '" + tmp.getClass().getName()+"'"); >+ } >+ else >+ { >+ ConstraintsDelegator.Factory.Registry.INSTANCE.putFactory(packageURI, (Factory)o); >+ } >+ } >+ return true; >+ } >+ catch (CoreException e) >+ { >+ throw new WrappedException(e); >+ } >+ } >+ } >+ return false; >+ } >+} >Index: schema/constraints_delegator_registry.exsd >=================================================================== >RCS file: schema/constraints_delegator_registry.exsd >diff -N schema/constraints_delegator_registry.exsd >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ schema/constraints_delegator_registry.exsd 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,113 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<!-- Schema file written by PDE --> >+<schema targetNamespace="org.eclipse.emf.ecore" xmlns="http://www.w3.org/2001/XMLSchema"> >+<annotation> >+ <appinfo> >+ <meta.schema plugin="org.eclipse.emf.ecore" id="constraints_delegator_registry" name="%_UI_ConstraintsDelegatorRegistry_extensionpoint"/> >+ </appinfo> >+ <documentation> >+ Adds a ConstraintDelegatorFactory to check constraints in Ecore models >+ </documentation> >+ </annotation> >+ >+ <element name="extension"> >+ <annotation> >+ <appinfo> >+ <meta.element /> >+ </appinfo> >+ </annotation> >+ <complexType> >+ <sequence> >+ <element ref="factory"/> >+ </sequence> >+ <attribute name="point" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="id" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="name" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appinfo> >+ <meta.attribute translatable="true"/> >+ </appinfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="factory"> >+ <complexType> >+ <attribute name="uri" type="string" use="required"> >+ <annotation> >+ <documentation> >+ the uri which will be inserted by user to check constraints >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="class" type="string" use="required"> >+ <annotation> >+ <documentation> >+ A fully qualified name of the Java class implementing <samp>org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory >+</samp>. >+ </documentation> >+ <appinfo> >+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory"/> >+ </appinfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="since"/> >+ </appinfo> >+ <documentation> >+ 2.5.0 >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="examples"/> >+ </appinfo> >+ <documentation> >+ Following is an example of implementation >+<pre> >+<extension >+ point="org.eclipse.emf.ecore.constraints_delegator_regstry"> >+ <factory >+ class="ocl.test.ConstraintsDelegator.MyFactory" >+ uri="org.eclipse.emf.ocl"> >+ </factory> >+ </extension> >+</pre> >+ </documentation> >+ </annotation> >+ >+ >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="copyright"/> >+ </appinfo> >+ <documentation> >+ Copyright (c) 2002, 2004 IBM Corporation and others.<br> >+All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at <a >+href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> >+ </documentation> >+ </annotation> >+ >+</schema> >Index: src/org/eclipse/emf/ecore/util/ConstraintsDelegator.java >=================================================================== >RCS file: src/org/eclipse/emf/ecore/util/ConstraintsDelegator.java >diff -N src/org/eclipse/emf/ecore/util/ConstraintsDelegator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/ecore/util/ConstraintsDelegator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id: ConstraintsDelegator.java,v 1.0 2008/11/19 16:37:42 tfaure Exp $ >+ */ >+package org.eclipse.emf.ecore.util; >+ >+import java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.emf.common.util.DiagnosticChain; >+import org.eclipse.emf.ecore.EObject; >+ >+ >+/** >+ * An interface to validate a constraint >+ * The only method to implement is {@link #validate(String, EObject, DiagnosticChain, Map) >+ * To add a factory please see extension point : constraints_delegator_regstry >+ */ >+public interface ConstraintsDelegator >+{ >+ interface Factory >+ { >+ interface Registry >+ { >+ Registry INSTANCE = new Impl(); >+ >+ /** >+ * Returns the factory identified by the key >+ * @param key the factory id >+ * @return the factory or null if it doesn't exist >+ */ >+ Factory getFactory(String key); >+ >+ /** >+ * Registers a factory and associates it to an id >+ * @param key the id >+ * @param value the factory >+ */ >+ void putFactory(String key, Factory value); >+ >+ class Impl extends HashMap<String, Factory> implements Registry >+ { >+ private static final long serialVersionUID = 1L; >+ >+ public Factory getFactory(String key) >+ { >+ return get(key); >+ } >+ >+ public void putFactory(String key, Factory value) >+ { >+ put(key, value); >+ } >+ } >+ } >+ >+ /** >+ * Create a constraint delegator which is able to check a constraint >+ * @return the constraint Delegator >+ */ >+ ConstraintsDelegator createConstraintDelegator(); >+ } >+ >+ /** >+ * Validate a constraint and add to the diagnostic chain the evaluation's diagnostic >+ * @param value the expression to manage >+ * @param object the current EObject >+ * @param theDiagnostics the diagnostic's chain >+ * @param context the context of the current validation >+ * @return true if it's OK else false >+ */ >+ boolean validate(String value, EObject object, DiagnosticChain theDiagnostics, Map<Object, Object> context); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 255786
:
118244
|
118245
|
118338
|
123880
|
123881
|
123883
|
123885
|
126724
|
126725
|
126726
|
126727
|
126729
|
146761
|
146762
|
146778
|
146787
|
147341
|
147449
|
147455
|
147479