Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-10-28 22:52:07 +0000
committerGerrit Code Review @ Eclipse.org2015-11-09 10:33:33 +0000
commite638c413ede22d94939ac1528de9f17b5da0e5e7 (patch)
tree58e4c15526074ce9d15f32dbbc25676b69702c3e /plugins
parentfc34843cebb9b1ba93e1a6558a791536b9704662 (diff)
downloadorg.eclipse.papyrus-e638c413ede22d94939ac1528de9f17b5da0e5e7.tar.gz
org.eclipse.papyrus-e638c413ede22d94939ac1528de9f17b5da0e5e7.tar.xz
org.eclipse.papyrus-e638c413ede22d94939ac1528de9f17b5da0e5e7.zip
479331 - UML metamodel constraints are evaluated twice
446865 - lowerValue and upperValue cardinality values not accessible through UI Change-Id: Ia9c901dd5728c47aa61021b04171278503693a61
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java7
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml56
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintDescriptorWithOverride.java123
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintProviderWithOverride.java479
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingModelConstaintWithOverride.java205
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/contraints/UpperGeLowerConstraint.java87
6 files changed, 5 insertions, 952 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java
index a1008a63d6d..7fababa7de9 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java
@@ -37,6 +37,7 @@ import org.eclipse.emf.validation.service.ModelValidationService;
import org.eclipse.uml2.uml.LiteralInteger;
import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.ValueSpecification;
import org.eclipse.uml2.uml.util.UMLValidator;
@@ -149,8 +150,10 @@ public class EValidatorAdapter
boolean result = true;
if (eObject instanceof MultiplicityElement) {
final MultiplicityElement multiplicityElement = (MultiplicityElement) eObject;
- if ((!((multiplicityElement.getLowerValue() instanceof LiteralInteger || multiplicityElement.getLowerValue() instanceof LiteralUnlimitedNatural)
- && (multiplicityElement.getUpperValue() instanceof LiteralInteger || multiplicityElement.getUpperValue() instanceof LiteralUnlimitedNatural)))) {
+ ValueSpecification lower = multiplicityElement.getLowerValue();
+ ValueSpecification upper = multiplicityElement.getUpperValue();
+ if (!((lower instanceof LiteralInteger || lower instanceof LiteralUnlimitedNatural || lower == null)
+ && (upper instanceof LiteralInteger || upper instanceof LiteralUnlimitedNatural || upper == null))) {
result = false;
}
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml
index 06e8166d2f8..1150d79dd42 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/plugin.xml
@@ -5,63 +5,7 @@
<extension-point id="profileApplicationDelegates" name="Profile Application Delegates" schema="schema/profileApplicationDelegates.exsd"/>
<!-- Register the UML delegating constraint provider -->
-<extension
- point="org.eclipse.emf.validation.constraintProviders">
- <category
- id="org.eclipse.papyrus.uml.tools.uml"
- name="UML Metamodel Constraints">
- </category>
- <constraintProvider
- cache="true"
- class="org.eclipse.papyrus.uml.tools.constraints.providers.DelegatingConstraintProviderWithOverride"
- mode="Batch">
- <package
- namespaceUri="http://www.eclipse.org/uml2/5.0.0/UML">
- </package>
-
- <!-- Put the UML metamodel constraints into this category. -->
- <category path="org.eclipse.papyrus.uml.tools.uml"/>
-
- <!-- EMF Facet replaces the UML Validator with one that delegates
- to the ModelValidationService, which not only doesn't work
- with the delegating provider, but would be a dependency
- cycle anyways. -->
- <eValidatorProvider class="org.eclipse.uml2.uml.validation.IEValidatorProvider$UML"/>
- <constraints
- categories="org.eclipse.papyrus.uml.tools.uml">
- <constraint
- class="org.eclipse.papyrus.uml.tools.contraints.UpperGeLowerConstraint"
- id="org.eclipse.papyrus.uml.tools.uml.MultiplicityElement.UpperGeLower"
- isEnabledByDefault="true"
- lang="Java"
- mode="Batch"
- name="MultiplicityElement: UpperGeLower"
- severity="WARNING"
- statusCode="0">
- <message>
- Tue upper bound of multiplicity element {0} is not greater than or equal to its lower bound.
- </message>
- <target
- class="uml.MultiplicityElement">
- </target>
- </constraint>
- </constraints>
- </constraintProvider>
-</extension>
<!-- Bind the UML metamodel constraint provider's constraints to the Papyrus application. -->
-<extension
- point="org.eclipse.emf.validation.constraintBindings">
- <clientContext
- id="org.eclipse.papyrus.uml.tools.context">
- <selector
- class="org.eclipse.papyrus.infra.services.validation.PapyrusClientSelector">
- </selector>
- </clientContext>
- <binding
- context="org.eclipse.papyrus.uml.tools.context"
- category="org.eclipse.papyrus.uml.tools.uml">
- </binding>
-</extension>
<extension
point="org.eclipse.papyrus.infra.core.model">
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintDescriptorWithOverride.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintDescriptorWithOverride.java
deleted file mode 100644
index 25841889584..00000000000
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintDescriptorWithOverride.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.constraints.providers;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EValidator;
-import org.eclipse.emf.validation.model.ConstraintSeverity;
-import org.eclipse.emf.validation.model.EvaluationMode;
-import org.eclipse.emf.validation.preferences.EMFModelValidationPreferences;
-import org.eclipse.emf.validation.service.AbstractConstraintDescriptor;
-import org.eclipse.uml2.uml.UMLPlugin;
-
-/**
- * This class is copied from {@link org.eclipse.uml2.uml.validation.DelegatingConstraintDescriptor}.
- */
-class DelegatingConstraintDescriptorWithOverride
- extends AbstractConstraintDescriptor {
-
- private final String namespace;
-
- private final EClass target;
-
- private final String id;
-
- private final String name;
-
- /**
- * Initializes me with the {@code EClass} that I constrain.
- *
- * @param a
- * namespace in which to define the constraints (e.g.,
- * {@code "org.eclipse.uml2.uml"})
- * @param target
- * my target model class
- * @param name
- * my name, from the model
- */
- DelegatingConstraintDescriptorWithOverride(String namespace, EClass target, String name) {
- this.namespace = namespace;
- this.target = target;
- this.name = UMLPlugin.INSTANCE.getString(
- "_UI_Validation_constraintName", //$NON-NLS-1$
- new Object[]{target.getName(), name});
-
- StringBuilder buf = new StringBuilder();
- buf.append(namespace);
- buf.append('.').append(target.getEPackage().getName()).append('.')
- .append(target.getName());
- buf.append('.').append(name);
- this.id = buf.toString();
-
- // this public method call is safe because it's final in my superclass
- setEnabled(!EMFModelValidationPreferences.isConstraintDisabled(this.id));
- }
-
- public String getName() {
- return name;
- }
-
- public String getId() {
- return id;
- }
-
- public String getPluginId() {
- return namespace;
- }
-
- public String getDescription() {
- return UMLPlugin.INSTANCE.getString("_UI_Validation_constraintDesc", //$NON-NLS-1$
- new Object[]{getName()});
- }
-
- public ConstraintSeverity getSeverity() {
- // in the UML metamodel, constraints generally are warnings
- return ConstraintSeverity.WARNING;
- }
-
- public int getStatusCode() {
- return 0; // constraints determine their own codes
- }
-
- public EvaluationMode<?> getEvaluationMode() {
- // it is not appropriate to try to invoke EValidator constraints in
- // Batch mode
- return EvaluationMode.BATCH;
- }
-
- public boolean targetsTypeOf(EObject eObject) {
- return target.isInstance(eObject);
- }
-
- public boolean targetsEvent(Notification notification) {
- // live mode is not supported
- return false;
- }
-
- public String getMessagePattern() {
- return UMLPlugin.INSTANCE.getString("_UI_Validation_violation", //$NON-NLS-1$
- new Object[]{getName()});
- }
-
- public String getBody() {
- // delegated constraints have nobody (har, har)
- return null;
- }
-
- EClass getTarget() {
- return target;
- }
-}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintProviderWithOverride.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintProviderWithOverride.java
deleted file mode 100644
index 1ee3b892ab8..00000000000
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingConstraintProviderWithOverride.java
+++ /dev/null
@@ -1,479 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.constraints.providers;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.DiagnosticChain;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EValidator;
-import org.eclipse.emf.validation.internal.EMFModelValidationDebugOptions;
-import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
-import org.eclipse.emf.validation.internal.EMFModelValidationStatusCodes;
-import org.eclipse.emf.validation.internal.l10n.ValidationMessages;
-import org.eclipse.emf.validation.internal.util.Log;
-import org.eclipse.emf.validation.internal.util.Trace;
-import org.eclipse.emf.validation.internal.util.XmlConfigurationElement;
-import org.eclipse.emf.validation.internal.util.XmlConstraintDescriptor;
-import org.eclipse.emf.validation.model.Category;
-import org.eclipse.emf.validation.model.CategoryManager;
-import org.eclipse.emf.validation.model.IModelConstraint;
-import org.eclipse.emf.validation.service.AbstractConstraintProvider;
-import org.eclipse.emf.validation.service.ConstraintExistsException;
-import org.eclipse.emf.validation.service.ConstraintRegistry;
-import org.eclipse.emf.validation.service.IConstraintDescriptor;
-import org.eclipse.emf.validation.util.XmlConfig;
-import org.eclipse.emf.validation.xml.IXmlConstraintDescriptor;
-import org.eclipse.uml2.common.util.UML2Util;
-import org.eclipse.uml2.uml.UMLPlugin;
-import org.eclipse.uml2.uml.validation.IEValidatorProvider;
-
-/**
- * A provider of constraints that delegate to an {@link EPackage}'s constraints
- * via its generated {@link EValidator} and can be overrided by the created constrains.
- */
-@SuppressWarnings("restriction")
-public class DelegatingConstraintProviderWithOverride
- extends AbstractConstraintProvider {
-
- /**
- * The category element name.
- */
- private static final String E_CATEGORY = "category"; //$NON-NLS-1$
-
- /**
- * The path attribute name.
- */
- private static final String A_PATH = "path"; //$NON-NLS-1$
-
- /**
- * The eValidatorProvider element name.
- */
- private static final String E_EVALIDATOR_PROVIDER = "eValidatorProvider"; //$NON-NLS-1$
-
- /**
- * The class attribute name.
- */
- private static final String A_CLASS = "class"; //$NON-NLS-1$
-
- /**
- * Message for the text to replace an constraint unavailable
- * constraint name.
- */
- private static final String NO_NAME = ValidationMessages.constraint_not_init_name;
-
- /**
- * Message for the text indicating that a constraint has no ID.
- */
- private static final String REASON_NO_ID = ValidationMessages.constraint_reason_no_id;
-
- /**
- * Message key for the text indicating that the XML file with
- * errors is unknown.
- */
- private static final String UNKNOWN_FILE = ValidationMessages.xml_unknown_file;
-
- /**
- * Constructor.
- */
- public DelegatingConstraintProviderWithOverride() {
- super();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.uml2.uml.validation.DelegatingConstraintProvider#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
- */
- @Override
- public void setInitializationData(final IConfigurationElement config,
- final String propertyName, final Object data)
- throws CoreException {
-
- super.setInitializationData(config, propertyName, data);
-
- // first, grab the categories that I'll be assigning to my constraints
- final Set<Category> categories = getCategories(config);
-
- // get an EValidator provider
- IEValidatorProvider validatorProvider = getEValidatorProvider(config);
-
- // then find the constraints that I need to adapt
- for (String next : getNamespaceUris()) {
- // find the EValidator for this package
- EPackage epackage = EPackage.Registry.INSTANCE.getEPackage(next);
-
- if (epackage == null) {
- UMLPlugin.INSTANCE
- .log(new Status(
- IStatus.WARNING,
- UMLPlugin.INSTANCE.getSymbolicName(),
- "No such EPackage available for model validation: " + next)); //$NON-NLS-1$
- } else {
- EValidator validator = validatorProvider
- .getEValidator(epackage);
- if (validator == null) {
- UMLPlugin.INSTANCE
- .log(new Status(
- IStatus.WARNING,
- UMLPlugin.INSTANCE.getSymbolicName(),
- "No generated validator available for package: " + next)); //$NON-NLS-1$
- } else {
- EValidator.SubstitutionLabelProvider labelProvider = validatorProvider
- .getSubstitutionLabelProvider(epackage);
-
- try {
- Iterable<? extends IModelConstraint> constraints = createConstraints(
- config, epackage,
- validator, labelProvider);
-
- if (!categories.isEmpty()) {
- Category[] cats = categories
- .toArray(new Category[categories.size()]);
- for (IModelConstraint constraint : constraints) {
- IConstraintDescriptor desc = constraint
- .getDescriptor();
- for (int i = 0; i < cats.length; i++) {
- desc.addCategory(cats[i]);
- }
- }
- }
- } catch (ConstraintExistsException e) {
- throw new CoreException(new Status(IStatus.ERROR,
- UMLPlugin.INSTANCE.getSymbolicName(),
- "Failed to register model validation constraints.", //$NON-NLS-1$
- e));
- }
- }
- }
- }
- }
-
- /**
- * Get the defined categories.
- *
- * @param config The configuration element.
- * @return The defined categories.
- */
- private Set<Category> getCategories(final IConfigurationElement config) {
- final Set<Category> result = new java.util.HashSet<Category>();
- for (IConfigurationElement next : config.getChildren(E_CATEGORY)) {
- String path = next.getAttribute(A_PATH);
-
- if (!UML2Util.isEmpty(path)) {
- // if the category doesn't already exist, it is implicitly
- // created, so
- // we won't get a null category
- result.add(CategoryManager.getInstance().getCategory(path));
- }
- }
-
- return result;
- }
-
- /**
- * Get the defined validator provider.
- *
- * @param config The configuration eleemnt.
- * @return the defined validator provider.
- */
- private IEValidatorProvider getEValidatorProvider(
- final IConfigurationElement config) {
-
- IEValidatorProvider result = null;
-
- final IConfigurationElement[] vpConfig = config
- .getChildren(E_EVALIDATOR_PROVIDER);
- if (vpConfig.length > 0) {
- Object ext;
- try {
- ext = vpConfig[0].createExecutableExtension(A_CLASS);
- if (ext instanceof IEValidatorProvider) {
- result = (IEValidatorProvider) ext;
- }
- } catch (CoreException e) {
- UMLPlugin.INSTANCE.log(e.getStatus());
- }
- }
-
- if (result == null) {
- result = new IEValidatorProvider.Default();
- }
-
- return result;
- }
-
- /**
- * This allow to get the defined constraints in the configuration.
- *
- * @param config The configuration element.
- * @return The list of defined constraints in the configuration.
- * @throws CoreException The exception.
- */
- private List<IModelConstraint> getDefinedConstraints(final IConfigurationElement config) throws CoreException{
- final List<IModelConstraint> definedConstraints = new ArrayList<IModelConstraint>();
-
- final IConfigurationElement[] constraintsElement = config.getChildren(
- XmlConfig.E_CONSTRAINTS);
-
- for (final IConfigurationElement constraintElement : constraintsElement) {
- final IConfigurationElement next = XmlConfig.parseConstraintsWithIncludes(constraintElement);
-
- final IConfigurationElement[] configs = next.getChildren();
-
- for (final IConfigurationElement constraintElements : configs) {
- definedConstraints.add(getConstraint(constraintElements));
- }
- }
-
- return definedConstraints;
- }
-
- /**
- * This allow to create constraints and get it.
- *
- * @param config The configuration element.
- * @param epackage The package of the class.
- * @param validator The validator to use.
- * @param labelProvider The label Provider.
- * @return The list of model constraints corresponding to the validate method in the class.
- * @throws ConstraintExistsException The exception when a constraint already exist.
- * @throws CoreException The core exception
- */
- private Iterable<? extends IModelConstraint> createConstraints(
- final IConfigurationElement config,
- final EPackage epackage,
- final EValidator validator,
- final EValidator.SubstitutionLabelProvider labelProvider)
- throws ConstraintExistsException, CoreException {
-
- final List<IModelConstraint> result = new java.util.ArrayList<IModelConstraint>();
- final Matcher m = Pattern.compile("validate\\w+_validate(\\w+)") //$NON-NLS-1$
- .matcher(""); //$NON-NLS-1$
- final Map<Class<?>, EClass> eclasses = new java.util.HashMap<Class<?>, EClass>();
- final String namespace = config.getNamespaceIdentifier();
-
- final List<IModelConstraint> definedConstraints = getDefinedConstraints(config);
-
- for (Method next : validator.getClass().getDeclaredMethods()) {
- if (Modifier.isPublic(next.getModifiers())) {
- final Class<?>[] signature = next.getParameterTypes();
-
- m.reset(next.getName());
- if (m.matches()
- && isConstraintMethod(next.getReturnType(), signature)) {
-
- EClass eclass = getEClass(eclasses, epackage, signature[0]);
-
- if (eclass != null) {
- if (!isRedefinedConstraints(definedConstraints, createIdentifier(next, eclass, namespace))) {
-
- // constraint methods could exist for EDataTypes; this
- // framework doesn't handle them
- result.add(new DelegatingModelConstraint(namespace,
- validator, labelProvider, eclass, next));
- }
- }
- }
- }
- }
-
- result.addAll(definedConstraints);
-
- getConstraints().addAll(result);
- registerConstraints(result);
-
- return result;
- }
-
- /**
- * This allow to create the identifier corresponding to the method.
- *
- * @param method The method in the class.
- * @param eclass The class corresponding.
- * @param namespace The namespace.
- * @return The identifier corresponding.
- */
- protected static String createIdentifier(final Method method, final EClass eclass, final String namespace) {
- String name = method.getName();
- String expectedPrefix = String.format("validate%s_validate", //$NON-NLS-1$
- eclass.getName());
- if (name.startsWith(expectedPrefix)) {
- name = name.substring(expectedPrefix.length());
- }
-
- final StringBuilder buf = new StringBuilder();
- buf.append(namespace);
- buf.append('.').append(eclass.getEPackage().getName()).append('.')
- .append(eclass.getName());
- buf.append('.').append(name);
- return buf.toString();
- }
-
- /**
- * This allow to define if the constraint id is already existing the list of contraint.
- *
- * @param constraints The existing constrains.
- * @param id The identifier to check.
- * @return <code>true</code> if the constraint is already redefined, <code>false otherwise</code>.
- */
- private static boolean isRedefinedConstraints(final List<IModelConstraint> constraints, final String id) {
- boolean result = false;
-
- final Iterator<IModelConstraint> contraintsIterator = constraints.iterator();
- while (contraintsIterator.hasNext() && !result) {
- if (contraintsIterator.next().getDescriptor().getId().equals(id)) {
- result = true;
- }
- }
-
- return result;
- }
-
- /**
- * This allow to define if the method defined by the parameters is a contraint method.
- *
- * @param returnType The return type of the method.
- * @param parameterTypes The parameter types of the method.
- * @return <code>true</code> if this is a contraint method, <code>false</code> otherwise.
- */
- private static boolean isConstraintMethod(final Class<?> returnType,
- final Class<?>[] parameterTypes) {
-
- boolean result = false;
-
- if ((returnType == boolean.class) && (parameterTypes.length == 3)) {
- result = EObject.class.isAssignableFrom(parameterTypes[0])
- && (parameterTypes[1] == DiagnosticChain.class)
- && (parameterTypes[2] == Map.class);
- }
-
- return result;
- }
-
- /**
- * Look up an {@link EClass} by instance-class, using a cache for
- * performance of repeated queries.
- *
- * @param cache
- * a cache of previous look-up results
- * @param epackage
- * the epackage in which to find the eclass
- * @param interfaceType
- * the Java interface type by which to look up the eclass
- *
- * @return the eclass, or {@code null} if not found
- */
- private static EClass getEClass(final Map<Class<?>, EClass> cache,
- final EPackage epackage, final Class<?> interfaceType) {
-
- EClass result = cache.get(interfaceType);
-
- if (result == null) {
- for (EClassifier next : epackage.getEClassifiers()) {
- if ((next.getInstanceClass() == interfaceType)
- && (next instanceof EClass)) {
- result = (EClass) next;
- cache.put(interfaceType, result);
- break;
- }
- }
- }
-
- return result;
- }
-
- /**
- * Adds a constraint to my collection, constructed from the specified XML
- * content.
- *
- * @param config
- * the <TT>&lt;constraint&gt;</TT> element
- */
- private IModelConstraint getConstraint(final IConfigurationElement config) {
- IModelConstraint result = null;
- final String contributorId = config
- .getDeclaringExtension()
- .getNamespaceIdentifier();
-
- String id = config.getAttribute(XmlConfig.A_ID);
- if (id == null) {
- String name = config.getAttribute(XmlConfig.A_NAME);
- if (name == null) {
- String fileName;
-
- if (config instanceof XmlConfigurationElement) {
- fileName = ((XmlConfigurationElement) config).getFileName();
- } else {
- fileName = UNKNOWN_FILE;
- }
-
- name = EMFModelValidationPlugin.getMessage(
- NO_NAME,
- new Object[] { fileName });
- }
-
- Log.warningMessage(
- EMFModelValidationStatusCodes.CONSTRAINT_NOT_INITED,
- EMFModelValidationStatusCodes.CONSTRAINT_NOT_INITED_MSG,
- new Object[] {
- name,
- REASON_NO_ID, });
- } else {
- IConstraintDescriptor constraint = ConstraintRegistry.getInstance().getDescriptor(
- contributorId,
- id);
-
- if (constraint == null) {
- // why wasn't it already created?
- try {
- constraint = new XmlConstraintDescriptor(config);
- } catch (ConstraintExistsException e) {
- // shouldn't happen because I checked for existence.
- // Just leave 'constraint' null to skip it
- }
- }
-
- if (constraint instanceof IXmlConstraintDescriptor) {
- IXmlConstraintDescriptor xmlConstraint = (IXmlConstraintDescriptor) constraint;
-
- xmlConstraint.resolveTargetTypes(getNamespaceUris());
-
- IModelConstraint proxy = createModelConstraintProxy(xmlConstraint);
-
- result = proxy;
-
- Trace.trace(
- EMFModelValidationDebugOptions.PROVIDERS,
- "Added constraint proxy: " + constraint); //$NON-NLS-1$
- }
- }
-
- return result;
- }
-}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingModelConstaintWithOverride.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingModelConstaintWithOverride.java
deleted file mode 100644
index 8dc7af332f3..00000000000
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/constraints/providers/DelegatingModelConstaintWithOverride.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.constraints.providers;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.common.util.DiagnosticChain;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EValidator;
-import org.eclipse.emf.validation.IValidationContext;
-import org.eclipse.emf.validation.model.ConstraintStatus;
-import org.eclipse.emf.validation.model.IConstraintStatus;
-import org.eclipse.emf.validation.model.IModelConstraint;
-import org.eclipse.emf.validation.service.IConstraintDescriptor;
-import org.eclipse.uml2.uml.UMLPlugin;
-
-/**
- * This class is copied from {@link org.eclipse.uml2.uml.validation.DelegatingModelConstraint}.
- */
-class DelegatingModelConstraint
- implements IModelConstraint {
-
- private final IConstraintDescriptor descriptor;
-
- private final EValidator delegate;
-
- private final EValidator.SubstitutionLabelProvider labelProvider;
-
- private final Method constraintMethod;
-
- /**
- * Initializes me.
- */
- DelegatingModelConstraint(String namespace, EValidator delegate,
- EValidator.SubstitutionLabelProvider labelProvider, EClass target,
- Method constraintMethod) {
- // strip the type-qualifying part off of the validator method name
- String name = constraintMethod.getName();
- String expectedPrefix = String.format("validate%s_validate", //$NON-NLS-1$
- target.getName());
- if (name.startsWith(expectedPrefix)) {
- name = name.substring(expectedPrefix.length());
- }
-
- this.descriptor = new DelegatingConstraintDescriptorWithOverride(namespace, target,
- name);
- this.delegate = delegate;
- this.labelProvider = labelProvider;
- this.constraintMethod = constraintMethod;
- }
-
- public final IConstraintDescriptor getDescriptor() {
- return descriptor;
- }
-
- public IStatus validate(IValidationContext ctx) {
- IStatus result;
-
- final ContextAdapter ctxAdapter = ContextAdapter.getInstance(ctx);
- final BasicDiagnostic diagnostics = ctxAdapter.getDiagnostics();
- final Map<Object, Object> contextMap = ctxAdapter.getContextMap();
-
- try {
- // pass the label provider (if any) to the validator
- contextMap.put(EValidator.SubstitutionLabelProvider.class,
- labelProvider);
-
- boolean isOK = (Boolean) constraintMethod.invoke(delegate,
- ctx.getTarget(), diagnostics, contextMap);
-
- if (isOK) {
- result = ctx.createSuccessStatus();
- } else {
- final int count = diagnostics.getChildren().size();
-
- switch (count) {
- case 0 :
- result = ctx.createFailureStatus(getDescriptor()
- .getName());
- break;
- case 1 :
- result = toConstraintStatus(ctx, diagnostics
- .getChildren().get(0));
- break;
- default :
- List<IStatus> statuses = new java.util.ArrayList<IStatus>(
- diagnostics.getChildren().size());
- for (Diagnostic next : diagnostics.getChildren()) {
- statuses.add(toConstraintStatus(ctx, next));
- }
- result = ConstraintStatus.createMultiStatus(ctx,
- statuses);
- break;
- }
- }
- } catch (InvocationTargetException e) {
- // disable this constraint in future validation operations
- ctx.disableCurrentConstraint(e.getTargetException());
-
- result = ConstraintStatus.createStatus(ctx, ctx.getTarget(), ctx
- .getResultLocus(), IStatus.WARNING, getDescriptor()
- .getStatusCode(), UMLPlugin.INSTANCE
- .getString("_UI_Validation_runtimeError"), //$NON-NLS-1$
- getDescriptor().getException().getMessage());
- } catch (Exception e) {
- // disable this constraint in future validation operations
- ctx.disableCurrentConstraint(e);
-
- result = ConstraintStatus.createStatus(ctx, ctx.getTarget(), ctx
- .getResultLocus(), IStatus.WARNING, getDescriptor()
- .getStatusCode(), UMLPlugin.INSTANCE
- .getString("_UI_Validation_linkageError"), //$NON-NLS-1$
- e.getMessage());
- }
-
- return result;
- }
-
- private static IConstraintStatus toConstraintStatus(IValidationContext ctx,
- Diagnostic diagnostic) {
- final EObject target = ctx.getTarget();
-
- // collect the "result locus" on which to create problem markers, or
- // whatever
- List<EObject> resultLocus = new java.util.ArrayList<EObject>(3);
- for (Object next : diagnostic.getData()) {
- if ((next != target) && (next instanceof EObject)) {
- resultLocus.add((EObject) next);
- }
- }
-
- return ConstraintStatus.createStatus(ctx, target, resultLocus,
- diagnostic.getSeverity(), diagnostic.getCode(),
- diagnostic.getMessage());
- }
-
- //
- // Nested types
- //
-
- /**
- * A translation from the EMF Validation Framework's
- * {@link IValidationContext}-based API to EMF's {@link DiagnosticChain}-
- * and map-based API. A weak mapping ensures that the same adapters are
- * reused as appropriate for any given instance of the validation context.
- */
- private static final class ContextAdapter {
-
- private static final Map<IValidationContext, ContextAdapter> contextAdapters = new java.util.WeakHashMap<IValidationContext, ContextAdapter>();
-
- private Map<Object, Object> contextMap = new java.util.HashMap<Object, Object>();
-
- private BasicDiagnostic diagnostics;
-
- ContextAdapter() {
- super();
- }
-
- static ContextAdapter getInstance(IValidationContext ctx) {
- ContextAdapter result = contextAdapters.get(ctx);
-
- if (result == null) {
- result = new ContextAdapter();
- contextAdapters.put(ctx, result);
- }
-
- return result;
- }
-
- Map<Object, Object> getContextMap() {
- return contextMap;
- }
-
- BasicDiagnostic getDiagnostics() {
- if ((diagnostics != null) && !diagnostics.getChildren().isEmpty()) {
- // self-destruct a diagnostic that previously had problems added
- // to it
- diagnostics = null;
- }
-
- if (diagnostics == null) {
- diagnostics = new BasicDiagnostic();
- }
-
- return diagnostics;
- }
- }
-}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/contraints/UpperGeLowerConstraint.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/contraints/UpperGeLowerConstraint.java
deleted file mode 100644
index 5c802ae137a..00000000000
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/contraints/UpperGeLowerConstraint.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.contraints;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.validation.AbstractModelConstraint;
-import org.eclipse.emf.validation.EMFEventType;
-import org.eclipse.emf.validation.IValidationContext;
-import org.eclipse.uml2.uml.LiteralInteger;
-import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
-import org.eclipse.uml2.uml.MultiplicityElement;
-import org.eclipse.uml2.uml.NamedElement;
-
-/**
- * This class allows to manage the UpperGeLower constraint (this one will be called only if the lower and upper values are LiteralInteger of LiteralUnlimitedNatural).
- */
-public class UpperGeLowerConstraint extends AbstractModelConstraint {
-
- /**
- * Constructor.
- */
- public UpperGeLowerConstraint() {
- super();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext)
- */
- @Override
- public IStatus validate(final IValidationContext ctx) {
- IStatus result = ctx.createSuccessStatus();
- final EObject target = ctx.getTarget();
- final EMFEventType type = ctx.getEventType();
-
- // In the case of batch mode.
- if (EMFEventType.NULL == type) {
- if(target instanceof MultiplicityElement){
- final MultiplicityElement multiplicityElement = (MultiplicityElement)target;
- if(canCompareUpperGeLower(multiplicityElement)){
- if(!multiplicityElement.validateUpperGeLower(null, null)){
- final StringBuilder name = new StringBuilder();
- name.append("'");
- if(multiplicityElement instanceof NamedElement){
- name.append(((NamedElement) multiplicityElement).getQualifiedName());
- }else{
- name.append(multiplicityElement.eClass().getName());
- }
- name.append("'");
- result = ctx.createFailureStatus(name.toString());
- }
- }
- }
- }
-
- return result;
- }
-
- /**
- * This allows to define if the multiplicity element can compare the lower and the upper values (depending to the type of ValueSpecifications).
- *
- * @param eObject
- * The {@link EObject} to check.
- * @return <code>true</code> if the lower and upper can be compared (or if this is not a MultiplicityElement), <code>false</code> otherwise.
- */
- private boolean canCompareUpperGeLower(final MultiplicityElement multiplicityElement) {
- boolean result = true;
- if ((!((multiplicityElement.getLowerValue() instanceof LiteralInteger || multiplicityElement.getLowerValue() instanceof LiteralUnlimitedNatural)
- && (multiplicityElement.getUpperValue() instanceof LiteralInteger || multiplicityElement.getUpperValue() instanceof LiteralUnlimitedNatural)))) {
- result = false;
- }
- return result;
- }
-
-}

Back to the top