Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.eclipse.uml2.uml.util.UMLUtil Maven / Gradle / Ivy
/*
* Copyright (c) 2005, 2013 IBM Corporation, Embarcadero Technologies, CEA, and others.
* 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:
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 199624, 184249, 204406, 208125, 204200, 213218, 213903, 220669, 208016, 226396, 271470
* Nicolas Rouquette (JPL) - 260120, 313837
* Kenn Hussey - 286329, 313601, 314971, 344907, 236184, 335125
* Kenn Hussey (CEA) - 327039, 358792, 364419, 366350, 307343, 382637, 273949, 389542, 389495, 316165, 392833, 399544, 322715, 163556, 212765, 397324, 204658, 408612, 411731
* Yann Tanguy (CEA) - 350402
* Christian W. Damus (CEA) - 392833
*
*/
package org.eclipse.uml2.uml.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.emf.common.CommonPlugin;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.UniqueEList;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.ETypeParameter;
import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreSwitch;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
import org.eclipse.uml2.common.util.CacheAdapter;
import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.types.TypesFactory;
import org.eclipse.uml2.types.TypesPackage;
import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Artifact;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.BehavioredClassifier;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.ClassifierTemplateParameter;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Extension;
import org.eclipse.uml2.uml.Feature;
import org.eclipse.uml2.uml.Generalization;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.InterfaceRealization;
import org.eclipse.uml2.uml.LiteralInteger;
import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.MultiplicityElement;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.OpaqueExpression;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.PackageMerge;
import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.ParameterDirectionKind;
import org.eclipse.uml2.uml.ParameterableElement;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.RedefinableElement;
import org.eclipse.uml2.uml.Signal;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.StructuralFeature;
import org.eclipse.uml2.uml.StructuredClassifier;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.TemplateParameterSubstitution;
import org.eclipse.uml2.uml.TemplateSignature;
import org.eclipse.uml2.uml.TemplateableElement;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.TypedElement;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.UMLPlugin;
import org.eclipse.uml2.uml.ValueSpecification;
import org.eclipse.uml2.uml.VisibilityKind;
import org.eclipse.uml2.uml.resource.CMOF202UMLResource;
import org.eclipse.uml2.uml.resource.CMOF2UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.CMOF2UMLResource;
import org.eclipse.uml2.uml.resource.UML212UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.UML212UMLResource;
import org.eclipse.uml2.uml.resource.UML22UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.UML22UMLResource;
import org.eclipse.uml2.uml.resource.UML302UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.UML302UMLResource;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.resource.XMI212UMLResource;
import org.eclipse.uml2.uml.resource.XMI222UMLResource;
import org.eclipse.uml2.uml.resource.XMI2UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.XMI2UMLResource;
/**
* Utilities for working with UML elements and resources.
*
* @since 2.0
*/
public class UMLUtil
extends UML2Util {
/**
* The ProfileApplicationHelper can be overridden to change the way packages
* are traversed when looking for profile applications relevant to an
* element in a given package.
*
* @since 3.0
*/
public static class ProfileApplicationHelper {
public static final ProfileApplicationHelper INSTANCE = createProfileApplicationHelper();
private static ProfileApplicationHelper createProfileApplicationHelper() {
ProfileApplicationHelper profileApplicationHelper = UML2Util
.loadClassFromSystemProperty("org.eclipse.uml2.uml.util.UMLUtil$ProfileApplicationHelper.INSTANCE"); //$NON-NLS-1$
if (profileApplicationHelper != null) {
return profileApplicationHelper;
}
return new ProfileApplicationHelper();
}
public Iterable getOtherApplyingPackages(
org.eclipse.uml2.uml.Package package_) {
return package_.allOwningPackages();
}
}
/**
* The StereotypeApplicationHelper can be overridden to change the default
* location of applied stereotypes.
* Typically, stereotype applications are placed in the same location as
* the element to which the stereotype is applied, however, stereotype
* applications may be placed in other resources.
*
* @since 3.0
*/
public static class StereotypeApplicationHelper {
public static final StereotypeApplicationHelper INSTANCE = createStereotypeApplicationHelper();
private static StereotypeApplicationHelper createStereotypeApplicationHelper() {
StereotypeApplicationHelper stereotypeApplicationHelper = UML2Util
.loadClassFromSystemProperty("org.eclipse.uml2.uml.util.UMLUtil$StereotypeApplicationHelper.INSTANCE"); //$NON-NLS-1$
if (stereotypeApplicationHelper != null) {
return stereotypeApplicationHelper;
}
return new StereotypeApplicationHelper();
}
protected EList getContainmentList(Element element,
EClass definition) {
Resource eResource = element.eResource();
if (eResource != null) {
return eResource.getContents();
}
return null;
}
public boolean addToContainmentList(Element element,
EObject stereotypeApplication) {
boolean result = false;
EList containmentList = getContainmentList(element,
stereotypeApplication.eClass());
if (containmentList != null) {
result = containmentList.add(stereotypeApplication);
}
return result;
}
public boolean removeFromContainmentList(Element element,
EObject stereotypeApplication) {
boolean result = false;
EList containmentList = getContainmentList(element,
stereotypeApplication.eClass());
if (containmentList != null) {
result = containmentList.remove(stereotypeApplication);
}
return result;
}
public EObject applyStereotype(Element element, EClass definition) {
EObject stereotypeApplication = EcoreUtil.create(definition);
CacheAdapter.getInstance().adapt(stereotypeApplication);
addToContainmentList(element, stereotypeApplication);
setBaseElement(stereotypeApplication, element);
return stereotypeApplication;
}
}
/**
* A qualified text provider that uses names of named elements as qualified
* text segments and :: as a separator.
*/
public static class QualifiedTextProvider
extends UML2Util.QualifiedTextProvider {
/**
* The default instance.
*/
public static final QualifiedTextProvider DEFAULT = new QualifiedTextProvider();
@Override
public String getText(EObject eObject) {
return eObject instanceof NamedElement
? ((NamedElement) eObject).getName()
: super.getText(eObject);
}
@Override
public String getSeparator() {
return NamedElement.SEPARATOR;
}
}
/**
* A copier that merges the contents of packages involved in package merge
* relationships based on the rules defined in the UML specification.
*/
public static class PackageMerger
extends EcoreUtil.Copier {
private static final long serialVersionUID = 1L;
protected class BodyMatcher
extends EStructuralFeatureMatcher {
protected BodyMatcher(Comment comment) {
super(comment, UMLPackage.Literals.COMMENT__BODY);
}
}
protected class NameMatcher
extends EStructuralFeatureMatcher {
protected NameMatcher(NamedElement namedElement) {
super(namedElement, UMLPackage.Literals.NAMED_ELEMENT__NAME);
}
}
protected class KeyMatcher
extends EClassMatcher {
protected KeyMatcher(BasicEMap.Entry entry) {
super((EObject) entry);
}
@SuppressWarnings("unchecked")
@Override
public boolean matches(EObject otherEObject) {
return super.matches(otherEObject)
&& safeEquals(((BasicEMap.Entry) eObject)
.getKey(),
((BasicEMap.Entry) otherEObject)
.getKey());
}
}
protected class ResultingQNameMatcher
extends EClassMatcher {
protected ResultingQNameMatcher(EObject eObject) {
super(eObject);
}
@Override
public boolean matches(EObject otherEObject) {
return super.matches(otherEObject)
&& safeEquals(getResultingQName(eObject),
getResultingQName(otherEObject));
}
}
protected class StringValueMatcher
extends EClassMatcher {
protected StringValueMatcher(ValueSpecification valueSpecification) {
super(valueSpecification);
}
@Override
public boolean matches(EObject otherEObject) {
return super.matches(otherEObject)
&& safeEquals(((ValueSpecification) eObject).stringValue(),
((ValueSpecification) otherEObject).stringValue());
}
}
protected class SourceMatcher
extends EStructuralFeatureMatcher {
protected SourceMatcher(EAnnotation eAnnotation) {
super(eAnnotation, EcorePackage.Literals.EANNOTATION__SOURCE);
}
}
protected class TypeMatcher
extends NameMatcher {
protected TypeMatcher(TypedElement typedElement) {
super(typedElement);
}
@Override
public boolean matches(EObject otherEObject) {
if (super.matches(otherEObject)) {
Type type = ((TypedElement) eObject).getType();
Type otherType = ((TypedElement) otherEObject).getType();
return (type == null && otherType == null)
|| new ResultingQNameMatcher(type).matches(otherType)
|| (type instanceof Classifier
&& otherType instanceof Classifier && (findEObject(
((Classifier) type).allParents(),
new ResultingQNameMatcher(otherType)) != null || findEObject(
((Classifier) otherType).allParents(),
new ResultingQNameMatcher(type)) != null));
}
return false;
}
}
private static final boolean DEBUG = false;
/**
* The option for handling cases where the staticity of merged
* properties does not match. Supported choices are
* OPTION__IGNORE
and OPTION__REPORT
.
*/
public static final String OPTION__DIFFERENT_PROPERTY_STATICITY = "DIFFERENT_PROPERTY_STATICITY"; //$NON-NLS-1$
/**
* The option for handling cases where the uniqueness of merged
* properties does not match. Supported choices are
* OPTION__IGNORE
and OPTION__REPORT
.
*/
public static final String OPTION__DIFFERENT_PROPERTY_UNIQUENESS = "DIFFERENT_PROPERTY_UNIQUENESS"; //$NON-NLS-1$
/**
* The option for handling cases where a redundant generalization is
* detected. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__DISCARD
.
*/
public static final String OPTION__REDUNDANT_GENERALIZATIONS = "REDUNDANT_GENERALIZATIONS"; //$NON-NLS-1$
/**
* The option for handling cases where an implicit redefinition is
* detected. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__IMPLICIT_REDEFINITIONS = "IMPLICIT_REDEFINITIONS"; //$NON-NLS-1$
/**
* The option for handling cases where an invalid redefinition is
* detected. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, OPTION__DISCARD
, and
* OPTION__PROCESS
.
*/
public static final String OPTION__INVALID_REDEFINITIONS = "INVALID_REDEFINITIONS"; //$NON-NLS-1$
/**
* The option for handling cases where an invalid subset is detected.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, OPTION__DISCARD
, and
* OPTION__PROCESS
.
*/
public static final String OPTION__INVALID_SUBSETS = "INVALID_SUBSETS"; //$NON-NLS-1$
/**
* The option for handling cases where an empty union is detected.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__EMPTY_UNIONS = "EMPTY_UNIONS"; //$NON-NLS-1$
/**
* The option for handling cases where an association specialization is
* missing. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__ASSOCIATION_SPECIALIZATIONS = "ASSOCIATION_SPECIALIZATIONS"; //$NON-NLS-1$
/**
* The option for handling cases where capability information is
* missing. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__CAPABILITIES = "CAPABILITIES"; //$NON-NLS-1$
/**
* The option for handling cases where a classifier with an empty
* qualified name is detected. Supported choices are
* OPTION__IGNORE
and OPTION__REPORT
.
*/
public static final String OPTION__EMPTY_QUALIFIED_NAMES = "EMPTY_QUALIFIED_NAMES"; //$NON-NLS-1$
/**
* The option for handling cases where an indistinguishable classifier
* is detected. Supported choices are OPTION__IGNORE
and
* OPTION__REPORT
.
*/
public static final String OPTION__INDISTINGUISHABLE_CLASSIFIERS = "INDISTINGUISHABLE_CLASSIFIERS"; //$NON-NLS-1$
private static final int DIAGNOSTIC_CODE_OFFSET = 1000;
/**
* The diagnostic code for cases where the staticity of merged
* properties does not match.
*/
public static final int DIFFERENT_PROPERTY_STATICITY = DIAGNOSTIC_CODE_OFFSET + 1;
/**
* The diagnostic code for cases where the uniqueness of merged
* properties does not match.
*/
public static final int DIFFERENT_PROPERTY_UNIQUENESS = DIAGNOSTIC_CODE_OFFSET + 2;
/**
* The diagnostic code for cases where a redundant generalization is
* detected.
*/
public static final int REDUNDANT_GENERALIZATION = DIAGNOSTIC_CODE_OFFSET + 3;
/**
* The diagnostic code for cases where an implicit redefinition is
* detected.
*/
public static final int IMPLICIT_REDEFINITION = DIAGNOSTIC_CODE_OFFSET + 4;
/**
* The diagnostic code for cases where an invalid redefinition is
* detected.
*/
public static final int INVALID_REDEFINITION = DIAGNOSTIC_CODE_OFFSET + 5;
/**
* The diagnostic code for cases where an invalid subset is detected.
*/
public static final int INVALID_SUBSET = DIAGNOSTIC_CODE_OFFSET + 6;
/**
* The diagnostic code for cases where an empty union is detected.
*/
public static final int EMPTY_UNION = DIAGNOSTIC_CODE_OFFSET + 7;
/**
* The diagnostic code for cases where an association specialization is
* missing.
*/
public static final int ASSOCIATION_SPECIALIZATION = DIAGNOSTIC_CODE_OFFSET + 8;
/**
* The diagnostic code for cases where capability information is
* missing.
*/
public static final int CAPABILITY = DIAGNOSTIC_CODE_OFFSET + 9;
/**
* The diagnostic code for cases where the qualified named of a
* classifier in a receiving or merged package is empty.
*/
public static final int EMPTY_QUALIFIED_NAME = DIAGNOSTIC_CODE_OFFSET + 10;
/**
* The diagnostic code for cases where a classifier in a receiving or
* merged package is indistinguishable.
*/
public static final int INDISTINGUISHABLE_CLASSIFIER = DIAGNOSTIC_CODE_OFFSET + 11;
protected org.eclipse.uml2.uml.Package receivingPackage = null;
protected Collection mergedPackages = null;
protected final Map> resultingToMergedEObjectMap = new LinkedHashMap>();
protected List getMatchCandidates(EO eObject) {
Element baseElement = getBaseElement(eObject);
if (baseElement == null) {
EStructuralFeature eContainingFeature = eObject
.eContainingFeature();
if (eContainingFeature.isMany()) {
@SuppressWarnings("unchecked")
List values = (List) get(eObject.eContainer())
.eGet(eContainingFeature);
return values;
} else {
@SuppressWarnings("unchecked")
EO value = (EO) get(eObject.eContainer()).eGet(
eContainingFeature);
return Collections. singletonList(value);
}
} else {
@SuppressWarnings("unchecked")
List stereotypeApplications = (List) ((Element) get(baseElement))
.getStereotypeApplications();
return stereotypeApplications;
}
}
protected List getMergedEObjects(
EO resultingEObject) {
@SuppressWarnings("unchecked")
List mergedEObjects = (List) resultingToMergedEObjectMap
.get(resultingEObject);
return mergedEObjects == null
? Collections. singletonList(resultingEObject)
: (List) mergedEObjects;
}
protected EO getPreviouslyMergedEObject(
EO resultingEObject) {
List mergedEObjects = getMergedEObjects(resultingEObject);
return mergedEObjects.get(mergedEObjects.size() - 1);
}
protected String getResultingQName(EObject eObject) {
StringBuffer resultingQName = appendResultingQName(
new StringBuffer(), eObject, QualifiedTextProvider.DEFAULT);
return resultingQName.toString();
}
private StringBuffer appendResultingQName(StringBuffer resultingQName,
EObject eObject, QualifiedTextProvider qualifiedTextProvider) {
eObject = mergedPackages.contains(eObject)
? receivingPackage
: eObject;
EObject eContainer = eObject.eContainer();
if (eContainer != null) {
appendResultingQName(resultingQName, eContainer,
qualifiedTextProvider);
if (resultingQName.length() > 0) {
resultingQName.append(qualifiedTextProvider.getSeparator());
}
}
return getQualifiedTextSegment(eObject, qualifiedTextProvider,
resultingQName);
}
protected void mergeAssociation_IsDerived(
Association receivingAssociation, Association mergedAssociation) {
receivingAssociation.setIsDerived(receivingAssociation.isDerived()
|| mergedAssociation.isDerived());
}
protected void mergeClassifier_IsAbstract(
Classifier receivingClassifier, Classifier mergedClassifier) {
receivingClassifier.setIsAbstract(receivingClassifier.isAbstract()
&& mergedClassifier.isAbstract());
}
protected void mergeClassifier_IsFinalSpecialization(
Classifier receivingClassifier, Classifier mergedClassifier) {
receivingClassifier.setIsFinalSpecialization(receivingClassifier
.isFinalSpecialization()
&& mergedClassifier.isFinalSpecialization());
}
protected void mergeLiteralInteger_Value(
LiteralInteger receivingLiteralInteger,
LiteralInteger mergedLiteralInteger) {
receivingLiteralInteger.setValue(getLesserLowerBound(
receivingLiteralInteger.getValue(), mergedLiteralInteger
.getValue()));
}
protected void mergeLiteralUnlimitedNatural_Value(
LiteralUnlimitedNatural receivingLiteralUnlimitedNatural,
LiteralUnlimitedNatural mergedLiteralUnlimitedNatural) {
receivingLiteralUnlimitedNatural.setValue(getGreaterUpperBound(
receivingLiteralUnlimitedNatural.getValue(),
mergedLiteralUnlimitedNatural.getValue()));
}
protected void mergeMultiplicityElement_IsOrdered(
MultiplicityElement receivingMultiplicityElement,
MultiplicityElement mergedMultiplicityElement) {
receivingMultiplicityElement
.setIsOrdered(receivingMultiplicityElement.isOrdered()
|| mergedMultiplicityElement.isOrdered());
}
protected void mergeMultiplicityElement_IsUnique(
MultiplicityElement receivingMultiplicityElement,
MultiplicityElement mergedMultiplicityElement) {
receivingMultiplicityElement
.setIsUnique(receivingMultiplicityElement.isUnique()
&& mergedMultiplicityElement.isUnique());
}
protected void mergeNamedElement_Visibility(
NamedElement receivingNamedElement,
NamedElement mergedNamedElement) {
if (receivingNamedElement.getVisibility() == VisibilityKind.PRIVATE_LITERAL
&& mergedNamedElement.getVisibility() == VisibilityKind.PRIVATE_LITERAL) {
receivingNamedElement
.setVisibility(VisibilityKind.PRIVATE_LITERAL);
} else if (receivingNamedElement.isSetVisibility()) {
receivingNamedElement
.setVisibility(VisibilityKind.PUBLIC_LITERAL);
}
}
protected void mergeProperty_IsDerived(Property receivingProperty,
Property mergedProperty) {
receivingProperty.setIsDerived(receivingProperty.isDerived()
|| mergedProperty.isDerived());
}
protected void mergeProperty_IsDerivedUnion(Property receivingProperty,
Property mergedProperty) {
receivingProperty.setIsDerivedUnion(receivingProperty
.isDerivedUnion()
|| mergedProperty.isDerivedUnion());
}
protected void mergeRedefinableElement_IsLeaf(
RedefinableElement receivingRedefinableElement,
RedefinableElement mergedRedefinableElement) {
receivingRedefinableElement.setIsLeaf(receivingRedefinableElement
.isLeaf() && mergedRedefinableElement.isLeaf());
}
protected void mergeStructuralFeature_IsReadOnly(
StructuralFeature receivingStructuralFeature,
StructuralFeature mergedStructuralFeature) {
receivingStructuralFeature.setIsReadOnly(receivingStructuralFeature
.isReadOnly()
&& mergedStructuralFeature.isReadOnly());
}
@Override
protected void copyAttribute(EAttribute eAttribute, EObject eObject,
EObject copyEObject) {
if (eObject != copyEObject) {
if (copyEObject == receivingPackage) {
return;
} else if (resultingToMergedEObjectMap.containsKey(copyEObject)) {
if (eAttribute == UMLPackage.Literals.ASSOCIATION__IS_DERIVED) {
mergeAssociation_IsDerived((Association) copyEObject,
(Association) eObject);
} else if (eAttribute == UMLPackage.Literals.CLASSIFIER__IS_ABSTRACT) {
mergeClassifier_IsAbstract((Classifier) copyEObject,
(Classifier) eObject);
} else if (eAttribute == UMLPackage.Literals.CLASSIFIER__IS_FINAL_SPECIALIZATION) {
mergeClassifier_IsFinalSpecialization(
(Classifier) copyEObject, (Classifier) eObject);
} else if (eAttribute == UMLPackage.Literals.LITERAL_INTEGER__VALUE
&& copyEObject.eContainingFeature() == UMLPackage.Literals.MULTIPLICITY_ELEMENT__LOWER_VALUE) {
mergeLiteralInteger_Value((LiteralInteger) copyEObject,
(LiteralInteger) eObject);
} else if (eAttribute == UMLPackage.Literals.LITERAL_UNLIMITED_NATURAL__VALUE
&& copyEObject.eContainingFeature() == UMLPackage.Literals.MULTIPLICITY_ELEMENT__UPPER_VALUE) {
mergeLiteralUnlimitedNatural_Value(
(LiteralUnlimitedNatural) copyEObject,
(LiteralUnlimitedNatural) eObject);
} else if (eAttribute == UMLPackage.Literals.MULTIPLICITY_ELEMENT__IS_ORDERED) {
mergeMultiplicityElement_IsOrdered(
(MultiplicityElement) copyEObject,
(MultiplicityElement) eObject);
} else if (eAttribute == UMLPackage.Literals.MULTIPLICITY_ELEMENT__IS_UNIQUE) {
mergeMultiplicityElement_IsUnique(
(MultiplicityElement) copyEObject,
(MultiplicityElement) eObject);
} else if (eAttribute == UMLPackage.Literals.NAMED_ELEMENT__VISIBILITY) {
mergeNamedElement_Visibility(
(NamedElement) copyEObject, (NamedElement) eObject);
} else if (eAttribute == UMLPackage.Literals.PROPERTY__IS_DERIVED) {
mergeProperty_IsDerived((Property) copyEObject,
(Property) eObject);
} else if (eAttribute == UMLPackage.Literals.PROPERTY__IS_DERIVED_UNION) {
mergeProperty_IsDerivedUnion((Property) copyEObject,
(Property) eObject);
} else if (eAttribute == UMLPackage.Literals.REDEFINABLE_ELEMENT__IS_LEAF) {
mergeRedefinableElement_IsLeaf(
(RedefinableElement) copyEObject,
(RedefinableElement) eObject);
} else if (eAttribute == UMLPackage.Literals.STRUCTURAL_FEATURE__IS_READ_ONLY) {
mergeStructuralFeature_IsReadOnly(
(StructuralFeature) copyEObject,
(StructuralFeature) eObject);
} else {
super.copyAttribute(eAttribute, eObject, copyEObject);
}
} else {
super.copyAttribute(eAttribute, eObject, copyEObject);
}
}
}
@Override
protected void copyContainment(EReference eReference, EObject eObject,
EObject copyEObject) {
if (eObject != copyEObject) {
if (eReference.isMany()) {
@SuppressWarnings("unchecked")
List sourceList = (List) eObject
.eGet(eReference);
@SuppressWarnings("unchecked")
InternalEList targetList = (InternalEList) copyEObject
.eGet(getTarget(eReference));
for (EObject childEObject : sourceList) {
EObject copyChildEObject = copy(childEObject);
if (childEObject != copyChildEObject) {
targetList.addUnique(copyChildEObject);
}
}
} else {
EObject childEObject = (EObject) eObject.eGet(eReference);
EObject copyChildEObject = childEObject == null
? null
: copy(childEObject);
if (childEObject != copyChildEObject) {
copyEObject.eSet(getTarget(eReference),
copyChildEObject);
}
}
}
}
protected void mergeTypedElement_Type(
TypedElement receivingTypedElement,
TypedElement mergedTypedElement) {
Type receivingType = receivingTypedElement.getType();
Type mergedType = mergedTypedElement.getType();
if (receivingType != null && mergedType instanceof Classifier) {
EList allParents = ((Classifier) mergedType)
.allParents();
for (EObject mergedEObject : getMergedEObjects(receivingType)) {
if (findEObject(allParents, new ResultingQNameMatcher(
mergedEObject)) != null) {
mergedType = (Type) mergedEObject;
}
}
}
Type resultingType = mergedType == null
? null
: (Type) get(mergedType);
receivingTypedElement.setType(resultingType == null
? mergedType
: resultingType);
}
@Override
protected void copyReference(EReference eReference, EObject eObject,
EObject copyEObject) {
if (eObject != copyEObject && eObject.eIsSet(eReference)) {
if (eReference == UMLPackage.Literals.TYPED_ELEMENT__TYPE) {
mergeTypedElement_Type((TypedElement) copyEObject,
(TypedElement) eObject);
} else if (eReference.isMany()) {
@SuppressWarnings("unchecked")
List sourceList = (List) eObject
.eGet(eReference);
@SuppressWarnings("unchecked")
InternalEList targetList = (InternalEList) copyEObject
.eGet(getTarget(eReference));
boolean isBidirectional = eReference.getEOpposite() != null;
int index = 0;
for (EObject referencedEObject : sourceList) {
EObject copyReferencedEObject = get(referencedEObject);
if (copyReferencedEObject == null) {
if (!isBidirectional) {
if (!targetList.contains(referencedEObject)) {
targetList.addUnique(index,
referencedEObject);
}
index++;
}
} else {
if (isBidirectional) {
int position = targetList
.indexOf(copyReferencedEObject);
if (position == -1) {
targetList.addUnique(index,
copyReferencedEObject);
} else if (index != position) {
targetList.move(index,
copyReferencedEObject);
}
} else if (!targetList
.contains(copyReferencedEObject)) {
targetList.addUnique(index,
copyReferencedEObject);
}
index++;
}
}
} else {
super.copyReference(eReference, eObject, copyEObject);
}
}
}
@Override
protected EObject createCopy(EObject eObject) {
return new UMLSwitch() {
@Override
public EObject caseAssociation(Association association) {
Association matchingAssociation = (Association) findEObject(
getMatchCandidates(association), new NameMatcher(
association));
return matchingAssociation == null
? super.caseAssociation(association)
: matchingAssociation;
}
@Override
public EObject caseClass(org.eclipse.uml2.uml.Class class_) {
org.eclipse.uml2.uml.Class matchingClass = (org.eclipse.uml2.uml.Class) findEObject(
getMatchCandidates(class_), new NameMatcher(class_));
return matchingClass == null
? super.caseClass(class_)
: matchingClass;
}
@Override
public EObject caseComment(Comment comment) {
Comment matchingComment = (Comment) findEObject(
getMatchCandidates(comment), new BodyMatcher(comment));
return matchingComment == null
? super.caseComment(comment)
: matchingComment;
}
@Override
public EObject caseConstraint(Constraint constraint) {
Constraint matchingConstraint = (Constraint) findEObject(
getMatchCandidates(constraint), new NameMatcher(
constraint));
return matchingConstraint == null
? super.caseConstraint(constraint)
: matchingConstraint;
}
@Override
public EObject caseDataType(DataType dataType) {
DataType matchingDataType = (DataType) findEObject(
getMatchCandidates(dataType), new NameMatcher(dataType));
return matchingDataType == null
? super.caseDataType(dataType)
: matchingDataType;
}
@Override
public EObject caseDirectedRelationship(
DirectedRelationship directedRelationship) {
if (mergedPackages.containsAll(directedRelationship
.getTargets())) {
return directedRelationship;
}
DirectedRelationship matchingDirectedRelationship = (DirectedRelationship) findEObject(
getMatchCandidates(directedRelationship),
new EClassMatcher(directedRelationship) {
@Override
public boolean matches(EObject otherEObject) {
if (super.matches(otherEObject)) {
otherEObject = getPreviouslyMergedEObject(otherEObject);
List targets = ((DirectedRelationship) eObject)
.getTargets();
List otherTargets = ((DirectedRelationship) otherEObject)
.getTargets();
if (targets.size() == otherTargets.size()) {
for (Element target : targets) {
if (findEObject(otherTargets,
new ResultingQNameMatcher(
target)) == null) {
return false;
}
}
return true;
}
}
return false;
}
});
return matchingDirectedRelationship == null
? super.caseDirectedRelationship(directedRelationship)
: matchingDirectedRelationship;
}
@Override
public EObject caseEnumerationLiteral(
EnumerationLiteral enumerationLiteral) {
EnumerationLiteral matchingEnumerationLiteral = (EnumerationLiteral) findEObject(
getMatchCandidates(enumerationLiteral),
new NameMatcher(enumerationLiteral));
return matchingEnumerationLiteral == null
? super.caseEnumerationLiteral(enumerationLiteral)
: matchingEnumerationLiteral;
}
@Override
public EObject caseOperation(Operation operation) {
Operation matchingOperation = (Operation) findEObject(
getMatchCandidates(operation), new NameMatcher(
operation) {
@Override
public boolean matches(EObject otherEObject) {
if (super.matches(otherEObject)) {
otherEObject = getPreviouslyMergedEObject(otherEObject);
List ownedParameters = ((Operation) eObject)
.getOwnedParameters();
List otherOwnedParameters = ((Operation) otherEObject)
.getOwnedParameters();
if (ownedParameters.size() == otherOwnedParameters
.size()) {
for (int i = 0; i < ownedParameters
.size(); i++) {
if (!new TypeMatcher(
ownedParameters.get(i))
.matches(otherOwnedParameters
.get(i))) {
return false;
}
}
return true;
}
}
return false;
}
});
return matchingOperation == null
? super.caseOperation(operation)
: matchingOperation;
}
@Override
public EObject casePackage(org.eclipse.uml2.uml.Package package_) {
org.eclipse.uml2.uml.Package matchingPackage = null;
if (mergedPackages.contains(package_)) {
matchingPackage = receivingPackage;
} else {
matchingPackage = (org.eclipse.uml2.uml.Package) findEObject(
getMatchCandidates(package_), new NameMatcher(
package_));
}
return matchingPackage == null
? super.casePackage(package_)
: matchingPackage;
}
@Override
public EObject caseParameter(Parameter parameter) {
Parameter matchingParameter = (Parameter) findEObject(
getMatchCandidates(parameter), new NameMatcher(
parameter));
return matchingParameter == null
? super.caseParameter(parameter)
: matchingParameter;
}
@Override
public EObject caseProperty(Property property) {
Property matchingProperty = (Property) findEObject(
getMatchCandidates(property), new NameMatcher(property));
return matchingProperty == null
? super.caseProperty(property)
: matchingProperty;
}
@Override
public EObject defaultCase(EObject eObject) {
Element baseElement = getBaseElement(eObject);
return baseElement == null
? PackageMerger.super.createCopy(eObject)
: applyStereotype((Element) get(baseElement),
getTarget(eObject.eClass()));
}
@Override
protected EObject doSwitch(EClass theEClass, EObject theEObject) {
if (theEClass.eContainer() != modelPackage) {
if (theEClass == EcorePackage.Literals.EANNOTATION) {
EAnnotation matchingEAnnotation = (EAnnotation) findEObject(
getMatchCandidates(theEObject),
new SourceMatcher((EAnnotation) theEObject));
if (matchingEAnnotation != null) {
return matchingEAnnotation;
}
} else if (theEClass == EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY) {
@SuppressWarnings("unchecked")
BasicEMap.Entry matchingEntry = (BasicEMap.Entry) findEObject(
getMatchCandidates(theEObject),
new KeyMatcher(
(BasicEMap.Entry) theEObject));
if (matchingEntry != null) {
return (EObject) matchingEntry;
}
} else if (getStereotype(theEClass, theEObject) != null) {
EObject matchingEObject = findEObject(
getMatchCandidates(theEObject),
new EClassMatcher(theEObject));
if (matchingEObject != null) {
return matchingEObject;
}
}
}
return super.doSwitch(theEClass, theEObject);
}
}.doSwitch(eObject);
}
@Override
public EObject copy(EObject eObject) {
EObject copyEObject = super.copy(eObject);
if (eObject != copyEObject) {
List mergedEObjects = resultingToMergedEObjectMap
.get(copyEObject);
if (mergedEObjects == null) {
resultingToMergedEObjectMap
.put(
copyEObject,
mergedEObjects = new UniqueEList.FastCompare(
1));
}
mergedEObjects.add(eObject);
}
if (DEBUG) {
System.out.println(getQualifiedText(eObject) + "->" //$NON-NLS-1$
+ getQualifiedText(copyEObject));
}
return copyEObject;
}
@Override
public Collection copyAll(Collection extends T> eObjects) {
Collection result = new ArrayList(eObjects.size());
for (Object object : eObjects) {
@SuppressWarnings("unchecked")
T copy = (T) copy((EObject) object);
result.add(copy);
for (TreeIterator eAllContents = ((EObject) object)
.eAllContents(); eAllContents.hasNext();) {
EObject childEObject = eAllContents.next();
if (childEObject instanceof Element) {
@SuppressWarnings("unchecked")
Collection copies = (Collection) super
.copyAll(((Element) childEObject)
.getStereotypeApplications());
result.addAll(copies);
}
}
}
return result;
}
protected Collection getAllMergedPackages(
org.eclipse.uml2.uml.Package package_) {
return getAllMergedPackages(package_,
new UniqueEList.FastCompare());
}
private Collection getAllMergedPackages(
org.eclipse.uml2.uml.Package package_,
Collection allMergedPackages) {
return getAllMergedPackages(package_, allMergedPackages,
new UniqueEList.FastCompare());
}
private Collection getAllMergedPackages(
org.eclipse.uml2.uml.Package package_,
Collection allMergedPackages,
Collection visitedPackages) {
for (PackageMerge packageMerge : package_.getPackageMerges()) {
org.eclipse.uml2.uml.Package mergedPackage = packageMerge
.getMergedPackage();
if (mergedPackage != null && visitedPackages.add(mergedPackage)) {
getAllMergedPackages(mergedPackage, allMergedPackages,
visitedPackages);
allMergedPackages.add(mergedPackage);
}
}
return allMergedPackages;
}
protected void processDifferentPropertyStaticity(
Map options, DiagnosticChain diagnostics,
Map context) {
for (Map.Entry> entry : resultingToMergedEObjectMap
.entrySet()) {
EObject key = entry.getKey();
if (key instanceof Property) {
Property property = (Property) key;
for (EObject mergedProperty : entry.getValue()) {
if (OPTION__REPORT.equals(options
.get(OPTION__DIFFERENT_PROPERTY_STATICITY))
&& diagnostics != null) {
if (property.isStatic() != ((Property) mergedProperty)
.isStatic()) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
DIFFERENT_PROPERTY_STATICITY,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportDifferentPropertyStaticity_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, property,
mergedProperty)),
new Object[]{property, mergedProperty}));
}
}
}
}
}
}
protected void processDifferentPropertyUniqueness(
Map options, DiagnosticChain diagnostics,
Map context) {
for (Map.Entry> entry : resultingToMergedEObjectMap
.entrySet()) {
EObject key = entry.getKey();
if (key instanceof Property) {
Property property = (Property) key;
for (EObject mergedProperty : entry.getValue()) {
if (OPTION__REPORT.equals(options
.get(OPTION__DIFFERENT_PROPERTY_UNIQUENESS))
&& diagnostics != null) {
if (property.isUnique() != ((Property) mergedProperty)
.isUnique()) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
DIFFERENT_PROPERTY_UNIQUENESS,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportDifferentPropertyUniqueness_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, property,
mergedProperty)),
new Object[]{property, mergedProperty}));
}
}
}
}
}
}
protected void processImplicitRedefinitions(
Map options, DiagnosticChain diagnostics,
Map context) {
for (EObject resultingEObject : resultingToMergedEObjectMap
.keySet()) {
if (resultingEObject instanceof Feature) {
Feature redefiningFeature = (Feature) resultingEObject;
EList redefinedFeatures = getRedefinedFeatures(redefiningFeature);
for (Feature validRedefinition : findValidRedefinitions(
redefiningFeature, redefiningFeature.getName())) {
if (!redefinedFeatures.contains(validRedefinition)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__IMPLICIT_REDEFINITIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
IMPLICIT_REDEFINITION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ProcessImplicitFeatureRedefinition_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
redefiningFeature,
validRedefinition)),
new Object[]{redefiningFeature,
validRedefinition}));
}
redefinedFeatures.add(validRedefinition);
} else if (OPTION__REPORT.equals(options
.get(OPTION__IMPLICIT_REDEFINITIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
IMPLICIT_REDEFINITION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportImplicitFeatureRedefinition_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, redefiningFeature,
validRedefinition)),
new Object[]{redefiningFeature,
validRedefinition}));
}
}
}
}
}
}
protected void processInvalidRedefinitions(Map options,
DiagnosticChain diagnostics, Map context) {
for (EObject resultingEObject : resultingToMergedEObjectMap
.keySet()) {
if (resultingEObject instanceof Feature) {
Feature redefiningFeature = (Feature) resultingEObject;
EList redefinedFeatures = getRedefinedFeatures(redefiningFeature);
for (Feature redefinedFeature : new ArrayList(
redefinedFeatures)) {
if (!UMLUtil.isRedefinitionValid(redefiningFeature,
redefinedFeature)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__INVALID_REDEFINITIONS))
|| OPTION__DISCARD.equals(options
.get(OPTION__INVALID_REDEFINITIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
INVALID_REDEFINITION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_DiscardInvalidFeatureRedefinition_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
redefiningFeature,
redefinedFeature)),
new Object[]{redefiningFeature,
redefinedFeature}));
}
redefinedFeatures.remove(redefinedFeature);
} else if (OPTION__REPORT.equals(options
.get(OPTION__INVALID_REDEFINITIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
INVALID_REDEFINITION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportInvalidFeatureRedefinition_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, redefiningFeature,
redefinedFeature)),
new Object[]{redefiningFeature,
redefinedFeature}));
}
}
if (OPTION__PROCESS.equals(options
.get(OPTION__INVALID_REDEFINITIONS))) {
Collection validRedefinitions = findValidRedefinitions(
redefiningFeature, redefinedFeature.getName());
if (!validRedefinitions.isEmpty()) {
for (Feature validRedefinition : validRedefinitions) {
if (!redefinedFeatures
.contains(validRedefinition)) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
INVALID_REDEFINITION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ProcessInvalidRedefinition_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
redefiningFeature,
redefinedFeature,
validRedefinition)),
new Object[]{
redefiningFeature,
validRedefinition}));
}
redefinedFeatures
.add(validRedefinition);
}
}
if (!validRedefinitions
.contains(redefinedFeature)) {
redefinedFeatures.remove(redefinedFeature);
}
}
}
}
}
}
}
protected void processInvalidSubsets(Map options,
DiagnosticChain diagnostics, Map context) {
for (EObject resultingEObject : resultingToMergedEObjectMap
.keySet()) {
if (resultingEObject instanceof Property) {
Property subsettingProperty = (Property) resultingEObject;
EList subsettedProperties = subsettingProperty
.getSubsettedProperties();
for (Property subsettedProperty : new ArrayList(
subsettedProperties)) {
if (!UMLUtil.isSubsetValid(subsettingProperty,
subsettedProperty)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__INVALID_SUBSETS))
|| OPTION__DISCARD.equals(options
.get(OPTION__INVALID_SUBSETS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
INVALID_SUBSET,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_DiscardInvalidSubset_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
subsettingProperty,
subsettedProperty)),
new Object[]{subsettingProperty,
subsettedProperty}));
}
subsettedProperties.remove(subsettedProperty);
} else if (OPTION__REPORT.equals(options
.get(OPTION__INVALID_SUBSETS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
INVALID_SUBSET,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportInvalidSubset_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
subsettingProperty,
subsettedProperty)),
new Object[]{subsettingProperty,
subsettedProperty}));
}
if (OPTION__PROCESS.equals(options
.get(OPTION__INVALID_SUBSETS))) {
Collection validSubsets = findValidSubsets(
subsettingProperty, subsettedProperty.getName());
if (!validSubsets.isEmpty()) {
for (Property validSubset : validSubsets) {
if (!subsettedProperties
.contains(validSubset)) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
INVALID_SUBSET,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ProcessInvalidSubset_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
subsettingProperty,
subsettedProperty,
validSubset)),
new Object[]{
subsettingProperty,
validSubset}));
}
subsettedProperties.add(validSubset);
}
}
if (!validSubsets.contains(subsettedProperty)) {
subsettedProperties
.remove(subsettedProperty);
}
}
}
}
}
}
}
}
protected void processEmptyUnions(Map options,
DiagnosticChain diagnostics, Map context) {
Map> unionToSubsettingPropertyMap = new LinkedHashMap>();
for (EObject resultingEObject : resultingToMergedEObjectMap
.keySet()) {
if (resultingEObject instanceof Property) {
Property property = (Property) resultingEObject;
if (property.isDerivedUnion()
&& !unionToSubsettingPropertyMap.containsKey(property)) {
unionToSubsettingPropertyMap.put(property,
new UniqueEList.FastCompare());
}
for (Property subsettedProperty : property
.getSubsettedProperties()) {
if (subsettedProperty.isDerivedUnion()) {
EList subsettingProperties = unionToSubsettingPropertyMap
.get(subsettedProperty);
if (subsettingProperties == null) {
unionToSubsettingPropertyMap
.put(
subsettedProperty,
subsettingProperties = new UniqueEList.FastCompare());
}
subsettingProperties.add(property);
}
}
}
}
for (Map.Entry> entry : unionToSubsettingPropertyMap
.entrySet()) {
if (entry.getValue().isEmpty()) {
Property unionProperty = entry.getKey();
if (OPTION__PROCESS.equals(options
.get(OPTION__EMPTY_UNIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
EMPTY_UNION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ProcessEmptyUnion_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
unionProperty)),
new Object[]{unionProperty}));
}
unionProperty.setIsDerivedUnion(false);
} else if (OPTION__REPORT.equals(options
.get(OPTION__EMPTY_UNIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
EMPTY_UNION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportEmptyUnion_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
unionProperty)),
new Object[]{unionProperty}));
}
}
}
}
protected void processRedundantGeneralizations(
Map options, DiagnosticChain diagnostics,
Map context) {
for (EObject resultingEObject : resultingToMergedEObjectMap
.keySet()) {
if (resultingEObject instanceof Classifier) {
Classifier classifier = (Classifier) resultingEObject;
EList generalizations = classifier
.getGeneralizations();
for (Generalization generalization : new ArrayList(
generalizations)) {
Classifier general = generalization.getGeneral();
if (general != null) {
EList generalAllParents = general
.allParents();
for (Iterator g = generalizations
.iterator(); g.hasNext();) {
Generalization otherGeneralization = g.next();
Classifier otherGeneral = otherGeneralization
.getGeneral();
if (general != otherGeneral
&& generalAllParents.contains(otherGeneral)
&& !otherGeneralization
.hasKeyword("extend")) { //$NON-NLS-1$
if (OPTION__DISCARD
.equals(options
.get(OPTION__REDUNDANT_GENERALIZATIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
REDUNDANT_GENERALIZATION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_DiscardRedundantGeneralization_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
classifier,
otherGeneral,
general)),
new Object[]{classifier,
otherGeneral}));
}
g.remove();
otherGeneralization.destroy();
} else if (OPTION__REPORT
.equals(options
.get(OPTION__REDUNDANT_GENERALIZATIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
REDUNDANT_GENERALIZATION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportRedundantGeneralization_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
classifier,
otherGeneral,
general)),
new Object[]{classifier,
otherGeneral}));
}
break;
}
}
}
}
}
}
}
protected void processEmptyQualifiedNames(Map options,
DiagnosticChain diagnostics, Map context) {
if (OPTION__REPORT.equals(options
.get(OPTION__EMPTY_QUALIFIED_NAMES)) && diagnostics != null) {
EList packages = new UniqueEList();
packages.add(receivingPackage);
packages.addAll(mergedPackages);
for (org.eclipse.uml2.uml.Package package_ : packages) {
for (Type ownedType : package_.getOwnedTypes()) {
if (UML2Util.isEmpty(ownedType.getQualifiedName())) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
EMPTY_QUALIFIED_NAME,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportEmptyQualifiedName_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
ownedType, package_)),
new Object[]{ownedType, package_}));
}
}
}
}
}
protected void processIndistinguishableClassifiers(
Map options, DiagnosticChain diagnostics,
Map context) {
if (OPTION__REPORT.equals(options
.get(OPTION__INDISTINGUISHABLE_CLASSIFIERS))
&& diagnostics != null) {
EList packages = new UniqueEList();
packages.add(receivingPackage);
packages.addAll(mergedPackages);
for (org.eclipse.uml2.uml.Package package_ : packages) {
EList ownedTypes = package_.getOwnedTypes();
for (Type ownedType : ownedTypes) {
for (Type otherOwnedType : ownedTypes) {
if (ownedType != otherOwnedType
&& !ownedType.isDistinguishableFrom(
otherOwnedType, package_)) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
INDISTINGUISHABLE_CLASSIFIER,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportIndistinguishableClassifier_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, ownedType,
package_)), new Object[]{
ownedType, package_}));
break;
}
}
}
}
}
}
protected void processAssociationSpecializations(
Map options, DiagnosticChain diagnostics,
Map context) {
for (EObject resultingEObject : resultingToMergedEObjectMap
.keySet()) {
if (resultingEObject instanceof Association) {
Association association = (Association) resultingEObject;
EList generalAssociations = new UniqueEList.FastCompare();
for (Property memberEnd : association.getMemberEnds()) {
for (Property redefinedProperty : memberEnd
.getRedefinedProperties()) {
Association redefinedAssociation = redefinedProperty
.getAssociation();
if (redefinedAssociation != null) {
generalAssociations.add(redefinedAssociation);
}
}
for (Property subsettedProperty : memberEnd
.getSubsettedProperties()) {
Association subsettedAssociation = subsettedProperty
.getAssociation();
if (subsettedAssociation != null) {
generalAssociations.add(subsettedAssociation);
}
}
}
for (Association generalAssociation : generalAssociations) {
if (!association.allParents().contains(
generalAssociation)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__ASSOCIATION_SPECIALIZATIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
ASSOCIATION_SPECIALIZATION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ProcessAssociationSpecialization_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, association,
generalAssociation)),
new Object[]{association,
generalAssociation}));
}
association
.createGeneralization(generalAssociation);
} else if (OPTION__REPORT.equals(options
.get(OPTION__ASSOCIATION_SPECIALIZATIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
ASSOCIATION_SPECIALIZATION,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportAssociationSpecialization_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, association,
generalAssociation)),
new Object[]{association,
generalAssociation}));
}
}
}
}
}
}
protected void processCapabilities(Map options,
DiagnosticChain diagnostics, Map context) {
for (Map.Entry> entry : resultingToMergedEObjectMap
.entrySet()) {
EObject resultingEObject = entry.getKey();
if (resultingEObject instanceof RedefinableElement) {
org.eclipse.uml2.uml.Package resultingPackage = ((RedefinableElement) resultingEObject)
.getNearestPackage();
for (EObject mergedEObject : entry.getValue()) {
org.eclipse.uml2.uml.Package mergedPackage = ((Element) mergedEObject)
.getNearestPackage();
if (OPTION__PROCESS.equals(options
.get(OPTION__CAPABILITIES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
CAPABILITY,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ProcessCapability_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, resultingEObject,
mergedPackage)),
new Object[]{resultingEObject,
mergedPackage}));
}
getEAnnotation(
getEAnnotation(resultingPackage,
UML2_UML_PACKAGE_2_0_NS_URI, true),
mergedPackage.getQualifiedName(), true)
.getReferences().add(resultingEObject);
} else if (OPTION__REPORT.equals(options
.get(OPTION__CAPABILITIES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
CAPABILITY,
UMLPlugin.INSTANCE
.getString(
"_UI_PackageMerger_ReportCapability_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
resultingEObject, mergedPackage)),
new Object[]{resultingEObject,
mergedPackage}));
}
}
}
}
}
protected void processOptions(Map options,
DiagnosticChain diagnostics, Map context) {
if (!OPTION__IGNORE.equals(options
.get(OPTION__EMPTY_QUALIFIED_NAMES))) {
processEmptyQualifiedNames(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__INDISTINGUISHABLE_CLASSIFIERS))) {
processIndistinguishableClassifiers(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__DIFFERENT_PROPERTY_STATICITY))) {
processDifferentPropertyStaticity(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__DIFFERENT_PROPERTY_UNIQUENESS))) {
processDifferentPropertyUniqueness(options, diagnostics,
context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__IMPLICIT_REDEFINITIONS))) {
processImplicitRedefinitions(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__INVALID_REDEFINITIONS))) {
processInvalidRedefinitions(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__INVALID_SUBSETS))) {
processInvalidSubsets(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__EMPTY_UNIONS))) {
processEmptyUnions(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__ASSOCIATION_SPECIALIZATIONS))) {
processAssociationSpecializations(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__REDUNDANT_GENERALIZATIONS))) {
processRedundantGeneralizations(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__CAPABILITIES))) {
processCapabilities(options, diagnostics, context);
}
}
/**
* Merges the contents of (all of) the packages merged by the specified
* package using the specified options, reporting problems to the
* specified diagnostics, within the specified context.
*
* @param package_
* The receiving package.
* @param options
* The options to use.
* @param diagnostics
* The chain of diagnostics to which problems are to be
* appended.
* @param context
* The cache of context-specific information.
*
* @return A traceability map from resulting elements to merged elements.
*/
public Map> merge(
org.eclipse.uml2.uml.Package package_,
Map options, DiagnosticChain diagnostics,
Map context) {
receivingPackage = package_;
mergedPackages = getAllMergedPackages(package_);
copyAll(mergedPackages);
copyReferences();
for (Iterator packageMerges = receivingPackage
.getPackageMerges().iterator(); packageMerges.hasNext();) {
PackageMerge packageMerge = packageMerges.next();
packageMerges.remove();
packageMerge.destroy();
}
if (options != null) {
processOptions(options, diagnostics, context);
}
return resultingToMergedEObjectMap;
}
}
/**
* A converter that converts UML elements to representative Ecore model
* elements.
*/
public static class UML2EcoreConverter
extends UMLSwitch
implements Converter {
protected class NameMatcher
extends EStructuralFeatureMatcher {
protected NameMatcher(ENamedElement eNamedElement) {
super(eNamedElement, EcorePackage.Literals.ENAMED_ELEMENT__NAME);
}
}
protected class ETypeMatcher
extends NameMatcher {
protected ETypeMatcher(ETypedElement eTypedElement) {
super(eTypedElement);
}
@Override
public boolean matches(EObject otherEObject) {
return super.matches(otherEObject)
&& safeEquals(((ETypedElement) eObject).getEType(),
((ETypedElement) otherEObject).getEType());
}
}
protected class SignatureMatcher
extends ETypeMatcher {
protected SignatureMatcher(EOperation eOperation) {
super(eOperation);
}
@Override
public boolean matches(EObject otherEObject) {
if (super.matches(otherEObject)) {
List eParameters = ((EOperation) eObject)
.getEParameters();
int eParametersSize = eParameters.size();
List otherEParameters = ((EOperation) otherEObject)
.getEParameters();
if (eParametersSize == otherEParameters.size()) {
for (int i = 0; i < eParametersSize; i++) {
if (!new ETypeMatcher(eParameters.get(i))
.matches(otherEParameters.get(i))) {
return false;
}
}
return true;
}
}
return false;
}
}
private static final boolean DEBUG = false;
/**
* The option for handling cases where an Ecore tagged value is
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__ECORE_TAGGED_VALUES = "ECORE_TAGGED_VALUES"; //$NON-NLS-1$
/**
* The option for handling cases where a redefining operation is
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__REDEFINING_OPERATIONS = "REDEFINING_OPERATIONS"; //$NON-NLS-1$
/**
* The option for handling cases where a redefining property is
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__REDEFINING_PROPERTIES = "REDEFINING_PROPERTIES"; //$NON-NLS-1$
/**
* The option for handling cases where a subsetting property is
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__SUBSETTING_PROPERTIES = "SUBSETTING_PROPERTIES"; //$NON-NLS-1$
/**
* The option for handling cases where a derived union property is
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__UNION_PROPERTIES = "UNION_PROPERTIES"; //$NON-NLS-1$
/**
* The option for handling cases where a derived feature is encountered.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__DERIVED_FEATURES = "DERIVED_FEATURES"; //$NON-NLS-1$
/**
* The option for handling cases where a duplicate operation is
* detected. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, OPTION__DISCARD
, and
* OPTION__PROCESS
.
*/
public static final String OPTION__DUPLICATE_OPERATIONS = "DUPLICATE_OPERATIONS"; //$NON-NLS-1$
/**
* The option for handling cases where an operation is inherited more
* than once. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, OPTION__DISCARD
, and
* OPTION__PROCESS
.
*/
public static final String OPTION__DUPLICATE_OPERATION_INHERITANCE = "DUPLICATE_OPERATION_INHERITANCE"; //$NON-NLS-1$
/**
* The option for handling cases where a duplicate feature is detected.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, OPTION__DISCARD
, and
* OPTION__PROCESS
.
*/
public static final String OPTION__DUPLICATE_FEATURES = "DUPLICATE_FEATURES"; //$NON-NLS-1$
/**
* The option for handling cases where a feature is inherited more than
* once. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, OPTION__DISCARD
, and
* OPTION__PROCESS
.
*/
public static final String OPTION__DUPLICATE_FEATURE_INHERITANCE = "DUPLICATE_FEATURE_INHERITANCE"; //$NON-NLS-1$
/**
* The option for handling cases where superclasses are not ordered.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__SUPER_CLASS_ORDER = "SUPER_CLASS_ORDER"; //$NON-NLS-1$
/**
* The option for handling cases where annotation details are
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__ANNOTATION_DETAILS = "ANNOTATION_DETAILS"; //$NON-NLS-1$
/**
* The option for handling cases where invariant constraints are
* encountered. Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__INVARIANT_CONSTRAINTS = "INVARIANT_CONSTRAINTS"; //$NON-NLS-1$
/**
* The option for handling cases where operation bodies are encountered.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__OPERATION_BODIES = "OPERATION_BODIES"; //$NON-NLS-1$
/**
* The option for handling cases where comments are encountered.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__COMMENTS = "COMMENTS"; //$NON-NLS-1$
/**
* The option for handling cases where names are not camel case.
* Supported choices are OPTION__IGNORE
,
* OPTION__REPORT
, and OPTION__PROCESS
.
*/
public static final String OPTION__CAMEL_CASE_NAMES = "CAMEL_CASE_NAMES"; //$NON-NLS-1$
/**
* The option for handling cases where invocation delegates can be used
* to define the behavior of operation bodies. Supported choices are
* OPTION__IGNORE
and OPTION__PROCESS
.
*/
public static final String OPTION__INVOCATION_DELEGATES = "INVOCATION_DELEGATES"; //$NON-NLS-1$
/**
* The option for handling cases where validation delegates can be used
* to define the behavior of invariant constraints. Supported choices
* are OPTION__IGNORE
and OPTION__PROCESS
.
*/
public static final String OPTION__VALIDATION_DELEGATES = "VALIDATION_DELEGATES"; //$NON-NLS-1$
private static final int DIAGNOSTIC_CODE_OFFSET = 2000;
/**
* The diagnostic code for cases where an Ecore tagged value is
* encountered.
*/
public static final int ECORE_TAGGED_VALUE = DIAGNOSTIC_CODE_OFFSET + 1;
/**
* The diagnostic code for cases where a redefining operation is
* encountered.
*/
public static final int REDEFINING_OPERATION = DIAGNOSTIC_CODE_OFFSET + 2;
/**
* The diagnostic code for cases where a redefining property is
* encountered.
*/
public static final int REDEFINING_PROPERTY = DIAGNOSTIC_CODE_OFFSET + 3;
/**
* The diagnostic code for cases where a subsetting property is
* encountered.
*/
public static final int SUBSETTING_PROPERTY = DIAGNOSTIC_CODE_OFFSET + 4;
/**
* The diagnostic code for cases where a derived union property is
* encountered.
*/
public static final int UNION_PROPERTY = DIAGNOSTIC_CODE_OFFSET + 5;
/**
* The diagnostic code for cases where a derived feature is encountered.
*/
public static final int DERIVED_FEATURE = DIAGNOSTIC_CODE_OFFSET + 6;
/**
* The diagnostic code for cases where a duplicate operation is
* detected.
*/
public static final int DUPLICATE_OPERATION = DIAGNOSTIC_CODE_OFFSET + 7;
/**
* The diagnostic code for cases where an operation is inherited more
* than once.
*/
public static final int DUPLICATE_OPERATION_INHERITANCE = DIAGNOSTIC_CODE_OFFSET + 8;
/**
* The diagnostic code for cases where a duplicate feature is detected.
*/
public static final int DUPLICATE_FEATURE = DIAGNOSTIC_CODE_OFFSET + 9;
/**
* The diagnostic code for cases where a feature is inherited more than
* once.
*/
public static final int DUPLICATE_FEATURE_INHERITANCE = DIAGNOSTIC_CODE_OFFSET + 10;
/**
* The diagnostic code for cases where superclasses are not ordered.
*/
public static final int SUPER_CLASS_ORDER = DIAGNOSTIC_CODE_OFFSET + 11;
/**
* The diagnostic code for cases where annotation details are
* encountered.
*/
public static final int ANNOTATION_DETAILS = DIAGNOSTIC_CODE_OFFSET + 12;
/**
* The diagnostic code for cases where invariant constraints are
* encountered.
*/
public static final int INVARIANT_CONSTRAINT = DIAGNOSTIC_CODE_OFFSET + 13;
/**
* The diagnostic code for cases where operation body details are
* encountered.
*/
public static final int OPERATION_BODY = DIAGNOSTIC_CODE_OFFSET + 14;
/**
* The diagnostic code for cases where comments are encountered.
*/
public static final int COMMENT = DIAGNOSTIC_CODE_OFFSET + 15;
/**
* The diagnostic code for cases where names are not camel case.
*/
public static final int CAMEL_CASE_NAME = DIAGNOSTIC_CODE_OFFSET + 16;
protected static final Pattern ANNOTATION_PATTERN = Pattern
.compile("\\G\\s*((?>\\\\.|\\S)+)((?:\\s+(?>\\\\.|\\S)+\\s*+=\\s*(['\"])((?>\\\\.|.)*?)\\3)*)"); //$NON-NLS-1$
protected static final Pattern ANNOTATION_DETAIL_PATTERN = Pattern
.compile("\\s+((?>\\\\.|\\S)+)\\s*+=\\s*((['\"])((?>\\\\.|.)*?)\\3)"); //$NON-NLS-1$
protected static final String OCL_DELEGATE_URI = "http://www.eclipse.org/emf/2002/Ecore/OCL"; //$NON-NLS-1$
protected final Map elementToEModelElementMap = new LinkedHashMap();
protected Collection packages = null;
protected Map options = null;
protected DiagnosticChain diagnostics = null;
protected Map context = null;
protected void setName(ENamedElement eNamedElement, String name,
boolean validate) {
if (!isEmpty(name)
&& options != null
&& !OPTION__IGNORE
.equals(options.get(OPTION__CAMEL_CASE_NAMES))) {
Iterator wordIterator = parseName(name, '_', "\\s").iterator(); //$NON-NLS-1$
StringBuffer camelCaseNameBuffer = new StringBuffer();
String word = wordIterator.next();
if (word.length() > 0) {
if (eNamedElement instanceof EClassifier
|| eNamedElement instanceof ETypeParameter) {
camelCaseNameBuffer.append(word.substring(0, 1)
.toUpperCase());
} else {
camelCaseNameBuffer.append(word.substring(0, 1)
.toLowerCase());
}
camelCaseNameBuffer.append(word.substring(1).toLowerCase());
}
while (wordIterator.hasNext()) {
word = wordIterator.next();
if (word.length() > 0) {
camelCaseNameBuffer.append(word.substring(0, 1)
.toUpperCase());
camelCaseNameBuffer.append(word.substring(1)
.toLowerCase());
}
}
String camelCaseName = camelCaseNameBuffer.toString();
if (OPTION__PROCESS.equals(options
.get(OPTION__CAMEL_CASE_NAMES))) {
eNamedElement.setName(validate
? getValidJavaIdentifier(camelCaseName)
: camelCaseName);
} else {
eNamedElement.setName(validate
? getValidJavaIdentifier(name)
: name);
}
if (!camelCaseName.equals(name)) {
if (DEBUG) {
System.out.println(name + " -> " + camelCaseNameBuffer); //$NON-NLS-1$
}
if (OPTION__PROCESS.equals(options
.get(OPTION__CAMEL_CASE_NAMES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
CAMEL_CASE_NAME,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessCamelCaseName_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eNamedElement)),
new Object[]{eNamedElement}));
}
} else if (OPTION__REPORT.equals(options
.get(OPTION__CAMEL_CASE_NAMES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
CAMEL_CASE_NAME,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportCamelCaseName_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eNamedElement)),
new Object[]{eNamedElement}));
}
}
} else {
eNamedElement.setName(validate
? getValidJavaIdentifier(name)
: name);
}
}
protected void setName(ENamedElement eNamedElement,
NamedElement namedElement) {
setName(eNamedElement, namedElement.getName(), true);
if (namedElement instanceof Classifier) {
Namespace namespace = namedElement.getNamespace();
if (namespace instanceof Classifier) {
qualifyName(eNamedElement, getValidJavaIdentifier(namespace
.getName()));
}
}
}
protected EClassifier getEType(Type type) {
EClassifier eType = null;
if (type != null) {
String qualifiedName = type.getQualifiedName();
if (!isEmpty(qualifiedName) && type instanceof PrimitiveType) {
if ("JavaPrimitiveTypes::boolean".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.EBOOLEAN;
} else if ("JavaPrimitiveTypes::byte".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.EBYTE;
} else if ("JavaPrimitiveTypes::char".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.ECHAR;
} else if ("JavaPrimitiveTypes::double".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.EDOUBLE;
} else if ("JavaPrimitiveTypes::float".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.EFLOAT;
} else if ("JavaPrimitiveTypes::int".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.EINT;
} else if ("JavaPrimitiveTypes::long".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.ELONG;
} else if ("JavaPrimitiveTypes::short".equals(qualifiedName)) { //$NON-NLS-1$
eType = EcorePackage.Literals.ESHORT;
} else if (qualifiedName
.startsWith("EcorePrimitiveTypes::")) { //$NON-NLS-1$
eType = EcorePackage.eINSTANCE.getEClassifier(type
.getName());
} else if (qualifiedName.startsWith("XMLPrimitiveTypes::")) { //$NON-NLS-1$
eType = XMLTypePackage.eINSTANCE.getEClassifier(type
.getName());
}
}
if (eType == null) {
Object eObject = doSwitch(type);
if (eObject instanceof EClassifier) {
eType = (EClassifier) eObject;
}
}
}
return eType;
}
protected ETypeParameter getETypeParameter(Type type) {
ETypeParameter eTypeParameter = null;
if (type != null) {
TemplateParameter templateParameter = type
.getTemplateParameter();
if (templateParameter != null) {
TemplateSignature signature = templateParameter
.getSignature();
if (signature != null) {
TemplateableElement template = signature.getTemplate();
if (template instanceof Type) {
EClassifier eType = getEType((Type) template);
if (eType != null) {
String name = type.getName();
for (ETypeParameter eParameter : eType
.getETypeParameters()) {
if (safeEquals(name, eParameter.getName())) {
eTypeParameter = eParameter;
break;
}
}
}
}
}
}
if (eTypeParameter == null) {
Object eObject = doSwitch(type);
if (eObject instanceof ETypeParameter) {
eTypeParameter = (ETypeParameter) eObject;
}
}
}
return eTypeParameter;
}
protected EGenericType getEGenericType(Type type) {
EGenericType eGenericType = null;
if (type instanceof Classifier) {
eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
EClassifier eType = getEType(type);
if (eType == null) {
ETypeParameter eTypeParameter = getETypeParameter(type);
if (eTypeParameter != null) {
eGenericType.setETypeParameter(eTypeParameter);
} else {
if (options != null
&& !OPTION__IGNORE.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))) {
processEcoreTaggedValues(eGenericType, type,
options, diagnostics, context);
}
EList eTypeArguments = eGenericType
.getETypeArguments();
for (TemplateBinding templateBinding : ((Classifier) type)
.getTemplateBindings()) {
TemplateSignature signature = templateBinding
.getSignature();
if (signature != null) {
TemplateableElement template = signature
.getTemplate();
if (template instanceof Classifier) {
eGenericType
.setEClassifier(getEType((Classifier) template));
for (TemplateParameterSubstitution parameterSubstitution : templateBinding
.getParameterSubstitutions()) {
ParameterableElement actual = parameterSubstitution
.getActual();
if (actual == null) {
TemplateParameter formal = parameterSubstitution
.getFormal();
if (formal != null) {
actual = formal.getDefault();
}
}
if (actual instanceof Classifier) {
eTypeArguments
.add(getEGenericType((Classifier) actual));
}
}
}
}
}
}
} else {
eGenericType.setEClassifier(eType);
}
}
return eGenericType;
}
protected EClassifier getEType(TypedElement typedElement) {
return getEType(typedElement.getType());
}
protected Stereotype getAppliedEcoreStereotype(Element element,
String name) {
return element.getAppliedStereotype("Ecore" //$NON-NLS-1$
+ NamedElement.SEPARATOR + name);
}
protected boolean isEGenericType(Classifier classifier) {
return options != null
&& !OPTION__IGNORE.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))
&& getAppliedEcoreStereotype(classifier,
STEREOTYPE__E_GENERIC_TYPE) != null;
}
public static boolean isEDataType(Namespace namespace) {
return !new UMLSwitch() {
@Override
public Boolean caseClass(org.eclipse.uml2.uml.Class class_) {
return Boolean.TRUE;
}
@Override
public Boolean caseDataType(DataType dataType) {
return Boolean.TRUE;
}
@Override
public Boolean caseEnumeration(Enumeration enumeration) {
return Boolean.FALSE;
}
@Override
public Boolean caseInterface(Interface interface_) {
return Boolean.TRUE;
}
@Override
public Boolean caseNamespace(Namespace namespace) {
return Boolean.FALSE;
}
@Override
public Boolean casePrimitiveType(PrimitiveType primitiveType) {
return Boolean.FALSE;
}
@Override
public Boolean doSwitch(EObject eObject) {
return eObject == null
? Boolean.FALSE
: super.doSwitch(eObject);
}
}.doSwitch(namespace).booleanValue();
}
protected boolean isEClass(Namespace namespace) {
return !isEDataType(namespace);
}
@Override
public Object caseClass(org.eclipse.uml2.uml.Class class_) {
if (!isEGenericType(class_) && !class_.isTemplateParameter()) {
org.eclipse.uml2.uml.Package package_ = class_
.getNearestPackage();
if (package_ != null) {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
elementToEModelElementMap.put(class_, eClass);
EPackage ePackage = (EPackage) doSwitch(package_);
ePackage.getEClassifiers().add(eClass);
setName(eClass, class_);
eClass.setAbstract(class_.isAbstract());
defaultCase(class_);
return eClass;
}
}
return super.caseClass(class_);
}
@Override
public Object caseComment(Comment comment) {
String body = comment.getBody();
if (!isEmpty(body) && options != null
&& !OPTION__IGNORE.equals(options.get(OPTION__COMMENTS))) {
for (Element annotatedElement : comment.getAnnotatedElements()) {
EModelElement eModelElement = (EModelElement) doSwitch(annotatedElement);
if (eModelElement != null) {
processComment(eModelElement, body, options,
diagnostics, context);
}
}
}
return super.caseComment(comment);
}
@Override
public Object caseConstraint(Constraint constraint) {
Namespace constraintContext = constraint.getContext();
if (constraintContext != null) {
EModelElement eModelElement = (EModelElement) doSwitch(constraintContext);
if (eModelElement != null) {
if (eModelElement instanceof EClassifier
&& options != null
&& !OPTION__IGNORE.equals(options
.get(OPTION__INVARIANT_CONSTRAINTS))) {
eModelElement = processInvariantConstraint(
(EClassifier) eModelElement, constraint, options,
diagnostics, context);
}
ValueSpecification specification = constraint
.getSpecification();
if (specification != null
&& !(eModelElement instanceof EOperation
&& options != null && OPTION__PROCESS
.equals(options.get(OPTION__OPERATION_BODIES)))) {
addDocumentation(eModelElement, specification
.stringValue());
}
return eModelElement;
}
}
return super.caseConstraint(constraint);
}
@Override
public Object caseDataType(DataType dataType) {
if (!isEGenericType(dataType) && !dataType.isTemplateParameter()) {
org.eclipse.uml2.uml.Package package_ = dataType
.getNearestPackage();
if (package_ != null) {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
elementToEModelElementMap.put(dataType, eClass);
EPackage ePackage = (EPackage) doSwitch(package_);
ePackage.getEClassifiers().add(eClass);
setName(eClass, dataType);
defaultCase(dataType);
return eClass;
}
}
return super.caseDataType(dataType);
}
@Override
public Object caseEModelElement(EModelElement eModelElement) {
return eModelElement;
}
@Override
public Object caseEnumeration(Enumeration enumeration) {
org.eclipse.uml2.uml.Package package_ = enumeration
.getNearestPackage();
if (package_ != null) {
EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum();
elementToEModelElementMap.put(enumeration, eEnum);
EPackage ePackage = (EPackage) doSwitch(package_);
ePackage.getEClassifiers().add(eEnum);
setName(eEnum, enumeration);
defaultCase(enumeration);
return eEnum;
}
return super.caseEnumeration(enumeration);
}
@Override
public Object caseEnumerationLiteral(
EnumerationLiteral enumerationLiteral) {
Enumeration enumeration = enumerationLiteral.getEnumeration();
if (enumeration != null) {
EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE
.createEEnumLiteral();
elementToEModelElementMap.put(enumerationLiteral, eEnumLiteral);
EEnum eEnum = (EEnum) doSwitch(enumeration);
eEnum.getELiterals().add(eEnumLiteral);
setName(eEnumLiteral, enumerationLiteral);
int value = enumeration.getOwnedLiterals().indexOf(
enumerationLiteral);
ValueSpecification specification = enumerationLiteral
.getSpecification();
if (specification != null) {
try {
value = specification.integerValue();
} catch (Exception e) {
// ignore
}
}
eEnumLiteral.setValue(value);
defaultCase(enumerationLiteral);
return eEnumLiteral;
}
return super.caseEnumerationLiteral(enumerationLiteral);
}
@Override
public Object caseGeneralization(Generalization generalization) {
Classifier specific = generalization.getSpecific();
if (specific != null) {
EClassifier specificEClassifier = (EClassifier) doSwitch(specific);
if (specificEClassifier instanceof EClass) {
EClass specificEClass = (EClass) specificEClassifier;
Classifier general = generalization.getGeneral();
if (general != null) {
EGenericType eGenericSuperType = getEGenericType(general);
if (eGenericSuperType != null) {
EClassifier generalEClassifier = eGenericSuperType
.getERawType();
if (generalEClassifier instanceof EClass) {
EClass generalEClass = (EClass) generalEClassifier;
if (!specificEClass
.isSuperTypeOf(generalEClass)
&& !generalEClass
.isSuperTypeOf(specificEClass)) {
specificEClass.getEGenericSuperTypes().add(
eGenericSuperType);
}
}
}
}
} else if (specificEClassifier instanceof EDataType) {
EDataType specificEDataType = (EDataType) specificEClassifier;
Classifier general = generalization.getGeneral();
if (general != null) {
EClassifier generalEClassifier = (EClassifier) doSwitch(general);
if (generalEClassifier instanceof EDataType) {
ExtendedMetaData.INSTANCE.setBaseType(
specificEDataType,
(EDataType) generalEClassifier);
}
}
}
}
return super.caseGeneralization(generalization);
}
@Override
public Object caseInterfaceRealization(
InterfaceRealization interfaceRealization) {
BehavioredClassifier implementingClassifier = interfaceRealization
.getImplementingClassifier();
if (implementingClassifier != null) {
EClassifier implementingEClassifier = (EClassifier) doSwitch(implementingClassifier);
if (implementingEClassifier instanceof EClass) {
EClass implementingEClass = (EClass) implementingEClassifier;
Interface contract = interfaceRealization.getContract();
if (contract != null) {
EGenericType eGenericSuperType = getEGenericType(contract);
if (eGenericSuperType != null) {
EClassifier contractEClassifier = eGenericSuperType
.getERawType();
if (contractEClassifier instanceof EClass) {
EClass contractEClass = (EClass) contractEClassifier;
if (!implementingEClass
.isSuperTypeOf(contractEClass)) {
implementingEClass.getEGenericSuperTypes()
.add(eGenericSuperType);
}
}
}
}
}
}
return super.caseInterfaceRealization(interfaceRealization);
}
@Override
public Object caseInterface(Interface interface_) {
if (!isEGenericType(interface_)
&& !interface_.isTemplateParameter()) {
org.eclipse.uml2.uml.Package package_ = interface_
.getNearestPackage();
if (package_ != null) {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
elementToEModelElementMap.put(interface_, eClass);
EPackage ePackage = (EPackage) doSwitch(package_);
ePackage.getEClassifiers().add(eClass);
setName(eClass, interface_);
eClass.setAbstract(true);
eClass.setInterface(true);
defaultCase(interface_);
return eClass;
}
}
return super.caseInterface(interface_);
}
@Override
public Object caseMultiplicityElement(
MultiplicityElement multiplicityElement) {
Object eModelElement = elementToEModelElementMap
.get(multiplicityElement);
if (eModelElement instanceof ETypedElement) {
ETypedElement eTypedElement = (ETypedElement) eModelElement;
int upper = multiplicityElement.getUpper();
if (eTypedElement.getUpperBound() != upper) {
eTypedElement.setUpperBound(upper);
}
int lower = multiplicityElement.getLower();
if (eTypedElement.getLowerBound() != lower) {
eTypedElement.setLowerBound(lower);
}
eTypedElement.setOrdered(multiplicityElement.isOrdered());
eTypedElement.setUnique(multiplicityElement.isUnique());
return eTypedElement;
} else {
return super.caseMultiplicityElement(multiplicityElement);
}
}
@Override
public Object caseOperation(Operation operation) {
Namespace namespace = operation.getNamespace();
if (isEClass(namespace)) {
EOperation eOperation = EcoreFactory.eINSTANCE
.createEOperation();
elementToEModelElementMap.put(operation, eOperation);
EClass eClass = (EClass) doSwitch(namespace);
eClass.getEOperations().add(eOperation);
setName(eOperation, operation);
EList eGenericExceptions = eOperation
.getEGenericExceptions();
for (Type raisedException : operation.getRaisedExceptions()) {
EGenericType eGenericType = getEGenericType(raisedException);
if (eGenericType != null) {
eGenericExceptions.add(eGenericType);
}
}
eOperation
.setEGenericType(getEGenericType(operation.getType()));
int upper = operation.getUpper();
if (eOperation.getUpperBound() != upper) {
eOperation.setUpperBound(upper);
}
int lower = operation.getLower();
if (eOperation.getLowerBound() != lower) {
eOperation.setLowerBound(lower);
}
eOperation.setOrdered(operation.isOrdered());
eOperation.setUnique(operation.isUnique());
defaultCase(operation);
return eOperation;
}
return super.caseOperation(operation);
}
@Override
public Object casePackage(org.eclipse.uml2.uml.Package package_) {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
elementToEModelElementMap.put(package_, ePackage);
if (!packages.contains(package_)) {
org.eclipse.uml2.uml.Package nestingPackage = package_
.getNestingPackage();
if (nestingPackage != null) {
((EPackage) doSwitch(nestingPackage)).getESubpackages()
.add(ePackage);
}
}
setName(ePackage, package_);
if (isEmpty(ePackage.getNsPrefix())) {
EPackage eSuperPackage = ePackage.getESuperPackage();
ePackage.setNsPrefix((eSuperPackage == null
? EMPTY_STRING
: eSuperPackage.getNsPrefix() + '.') + ePackage.getName());
}
ePackage.setNsURI(package_.getURI());
if (isEmpty(ePackage.getNsURI())) {
ePackage.setNsURI("http:///" //$NON-NLS-1$
+ ePackage.getNsPrefix().replace('.', '/') + ".ecore"); //$NON-NLS-1$
}
defaultCase(package_);
return ePackage;
}
@Override
public Object caseParameter(Parameter parameter) {
Operation operation = parameter.getOperation();
if (operation != null
&& parameter.getDirection() != ParameterDirectionKind.RETURN_LITERAL) {
EParameter eParameter = EcoreFactory.eINSTANCE
.createEParameter();
elementToEModelElementMap.put(parameter, eParameter);
EOperation eOperation = (EOperation) doSwitch(operation);
eOperation.getEParameters().add(eParameter);
setName(eParameter, parameter);
caseTypedElement(parameter);
caseMultiplicityElement(parameter);
defaultCase(parameter);
return eParameter;
}
return super.caseParameter(parameter);
}
@Override
public Object caseParameterableElement(
ParameterableElement parameterableElement) {
TemplateParameter templateParameter = parameterableElement
.getTemplateParameter();
if (templateParameter != null) {
TemplateSignature signature = templateParameter.getSignature();
if (signature != null) {
EList eTypeParameters = getETypeParameters((ENamedElement) doSwitch(signature
.getTemplate()));
if (eTypeParameters != null) {
ETypeParameter eTypeParameter = EcoreFactory.eINSTANCE
.createETypeParameter();
elementToEModelElementMap.put(parameterableElement,
eTypeParameter);
int index = signature.getParameters().indexOf(
templateParameter);
if (index < eTypeParameters.size()) {
eTypeParameters.add(index, eTypeParameter);
} else {
eTypeParameters.add(eTypeParameter);
}
if (parameterableElement instanceof NamedElement) {
setName(eTypeParameter,
(NamedElement) parameterableElement);
}
if (options != null
&& !OPTION__IGNORE.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))) {
processEcoreTaggedValues(eTypeParameter,
templateParameter, options, diagnostics,
context);
}
}
}
}
return super.caseParameterableElement(parameterableElement);
}
@Override
public Object casePrimitiveType(PrimitiveType primitiveType) {
if (!isEGenericType(primitiveType)
&& !primitiveType.isTemplateParameter()) {
org.eclipse.uml2.uml.Package package_ = primitiveType
.getNearestPackage();
if (package_ != null) {
EDataType eDataType = EcoreFactory.eINSTANCE
.createEDataType();
elementToEModelElementMap.put(primitiveType, eDataType);
EPackage ePackage = (EPackage) doSwitch(package_);
ePackage.getEClassifiers().add(eDataType);
setName(eDataType, primitiveType);
eDataType.setInstanceClassName(eDataType.getName());
defaultCase(primitiveType);
return eDataType;
}
}
return super.casePrimitiveType(primitiveType);
}
@Override
public Object caseProperty(Property property) {
Namespace namespace = property.getNamespace();
if (isEClass(namespace)) {
EStructuralFeature eStructuralFeature = null;
Classifier type = (Classifier) property.getType();
if (isEClass(type)) {
EReference eReference = (EReference) (eStructuralFeature = EcoreFactory.eINSTANCE
.createEReference());
elementToEModelElementMap.put(property, eReference);
eReference.setContainment(property.isComposite()
|| type instanceof DataType);
} else {
EAttribute eAttribute = (EAttribute) (eStructuralFeature = EcoreFactory.eINSTANCE
.createEAttribute());
elementToEModelElementMap.put(property, eAttribute);
String default_ = property.getDefault();
if (default_ != null) {
if (isUnlimitedNatural(type)) {
default_ = TypesFactory.eINSTANCE.createFromString(
TypesPackage.Literals.UNLIMITED_NATURAL,
default_).toString();
}
eAttribute.setDefaultValueLiteral(default_);
}
eAttribute.setID(property.isID());
}
EClass eClass = (EClass) doSwitch(namespace);
eClass.getEStructuralFeatures().add(eStructuralFeature);
setName(eStructuralFeature, property);
eStructuralFeature.setChangeable(!property.isReadOnly());
eStructuralFeature.setDerived(property.isDerived());
Property opposite = property.getOpposite();
if (opposite != null) {
EReference eOpposite = (EReference) doSwitch(opposite);
if (eOpposite != null) {
if (property.isDerived() && !eOpposite.isDerived()) {
eOpposite.setDerived(true);
if (DEBUG) {
System.out.println("Made opposite " //$NON-NLS-1$
+ getQualifiedText(eOpposite) + " derived"); //$NON-NLS-1$
}
}
((EReference) eStructuralFeature)
.setEOpposite(eOpposite);
}
}
caseTypedElement(property);
caseMultiplicityElement(property);
defaultCase(property);
return eStructuralFeature;
}
return super.caseProperty(property);
}
@Override
public Object caseTemplateParameter(TemplateParameter templateParameter) {
return defaultCase(templateParameter);
}
@Override
public Object caseTemplateSignature(TemplateSignature templateSignature) {
return defaultCase(templateSignature);
}
@Override
public Object caseTypedElement(TypedElement typedElement) {
Object eModelElement = elementToEModelElementMap.get(typedElement);
if (eModelElement instanceof ETypedElement) {
ETypedElement eTypedElement = (ETypedElement) eModelElement;
eTypedElement.setEGenericType(getEGenericType(typedElement
.getType()));
return eTypedElement;
}
return super.caseTypedElement(typedElement);
}
@Override
public Object defaultCase(EObject eObject) {
for (EObject eContent : eObject.eContents()) {
doSwitch(eContent);
}
return super.defaultCase(eObject);
}
@Override
public Object doSwitch(EObject eObject) {
if (!elementToEModelElementMap.containsKey(eObject)) {
super.doSwitch(eObject);
}
return elementToEModelElementMap.get(eObject);
}
private static char parseChar(String c) {
if (c == null) {
throw new IllegalArgumentException("null"); //$NON-NLS-1$
}
if ("\\b".equals(c)) { //$NON-NLS-1$
return '\b';
} else if ("\\t".equals(c)) { //$NON-NLS-1$
return '\t';
} else if ("\\n".equals(c)) { //$NON-NLS-1$
return '\n';
} else if ("\\f".equals(c)) { //$NON-NLS-1$
return '\f';
} else if ("\\r".equals(c)) { //$NON-NLS-1$
return '\r';
} else if ("\\\"".equals(c)) { //$NON-NLS-1$
return '\"';
} else if ("\\\'".equals(c)) { //$NON-NLS-1$
return '\'';
} else if ("\\\\".equals(c)) { //$NON-NLS-1$
return '\\';
}
if (c.startsWith("\\u") && c.length() == 6) { //$NON-NLS-1$
int i = Integer.parseInt(c.substring(2), 16);
if (i >= Character.MIN_VALUE && i <= Character.MAX_VALUE) {
return (char) i;
}
} else if (c.length() >= 2 && c.length() <= 4
&& c.charAt(0) == '\\') {
int i = Integer.parseInt(c.substring(1), 8);
if (i >= Character.MIN_VALUE && i <= Character.MAX_VALUE) {
return (char) i;
}
}
if (c.length() != 1) {
throw new IllegalArgumentException(c);
}
return c.charAt(0);
}
private static String parseString(String s) {
if (s == null) {
return null;
}
int length = s.length();
StringBuilder result = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == '\\' && length > i + 1) {
if ("btnfr\"\'\\".indexOf(s.charAt(i + 1)) != -1) { //$NON-NLS-1$
c = parseChar(s.substring(i, i + 2));
i++;
} else if (s.charAt(i + 1) == 'u' && length > i + 5) {
c = parseChar(s.substring(i, i + 6));
i += 5;
} else {
int j;
for (j = i + 1; j < length && j - i < 4; j++) {
char digit = s.charAt(j);
if (digit < '0' || digit > '7') {
break;
}
}
c = parseChar(s.substring(i, j));
i = j - 1;
}
}
result.append(c);
}
return result.toString();
}
private static List parseName(String name, char separator,
String regex) {
List result = new ArrayList();
if (name != null) {
for (String wordString : name.split(regex)) {
StringBuilder currentWord = new StringBuilder();
boolean lastIsLower = false;
for (int index = 0, length = wordString.length(); index < length; index++) {
char curChar = wordString.charAt(index);
if (Character.isUpperCase(curChar)
|| (!lastIsLower && Character.isDigit(curChar))
|| curChar == separator) {
if (lastIsLower && currentWord.length() > 1
|| curChar == separator
&& currentWord.length() > 0) {
result.add(currentWord.toString());
currentWord = new StringBuilder();
}
lastIsLower = false;
} else {
if (!lastIsLower) {
int currentWordLength = currentWord.length();
if (currentWordLength > 1) {
char lastChar = currentWord
.charAt(--currentWordLength);
currentWord.setLength(currentWordLength);
result.add(currentWord.toString());
currentWord = new StringBuilder();
currentWord.append(lastChar);
}
}
lastIsLower = true;
}
if (curChar != separator) {
currentWord.append(curChar);
}
}
result.add(currentWord.toString());
}
}
return result;
}
protected void processEcoreTaggedValue(EModelElement eModelElement,
EStructuralFeature eStructuralFeature, Element element,
Stereotype stereotype, String propertyName,
Map options, DiagnosticChain diagnostics,
Map context) {
if (element.hasValue(stereotype, propertyName)) {
Object value = element.getValue(stereotype, propertyName);
if (OPTION__PROCESS.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eModelElement, getTagDefinition(
stereotype, propertyName),
value)),
new Object[]{eModelElement}));
}
if (eStructuralFeature != null) {
eModelElement
.eSet(
eStructuralFeature,
eStructuralFeature == EcorePackage.Literals.ENAMED_ELEMENT__NAME
? getValidJavaIdentifier((String) value)
: value);
} else {
if (propertyName == TAG_DEFINITION__XML_CONTENT_KIND) {
Enumeration contentKindEnumeration = ((EnumerationLiteral) value)
.getEnumeration();
if (value == contentKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__EMPTY)) {
ExtendedMetaData.INSTANCE.setContentKind(
(EClass) eModelElement,
ExtendedMetaData.EMPTY_CONTENT);
} else if (value == contentKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__SIMPLE)) {
ExtendedMetaData.INSTANCE.setContentKind(
(EClass) eModelElement,
ExtendedMetaData.SIMPLE_CONTENT);
} else if (value == contentKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__MIXED)) {
ExtendedMetaData.INSTANCE.setContentKind(
(EClass) eModelElement,
ExtendedMetaData.MIXED_CONTENT);
} else if (value == contentKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__ELEMENT_ONLY)) {
ExtendedMetaData.INSTANCE.setContentKind(
(EClass) eModelElement,
ExtendedMetaData.ELEMENT_ONLY_CONTENT);
}
} else if (propertyName == TAG_DEFINITION__XML_FEATURE_KIND) {
Enumeration featureKindEnumeration = ((EnumerationLiteral) value)
.getEnumeration();
if (value == featureKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__SIMPLE)) {
ExtendedMetaData.INSTANCE.setFeatureKind(
(EStructuralFeature) eModelElement,
ExtendedMetaData.SIMPLE_FEATURE);
} else if (value == featureKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__ATTRIBUTE)) {
ExtendedMetaData.INSTANCE.setFeatureKind(
(EStructuralFeature) eModelElement,
ExtendedMetaData.ATTRIBUTE_FEATURE);
} else if (value == featureKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__ATTRIBUTE_WILDCARD)) {
ExtendedMetaData.INSTANCE
.setFeatureKind(
(EStructuralFeature) eModelElement,
ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE);
} else if (value == featureKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__ELEMENT)) {
ExtendedMetaData.INSTANCE.setFeatureKind(
(EStructuralFeature) eModelElement,
ExtendedMetaData.ELEMENT_FEATURE);
} else if (value == featureKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__ELEMENT_WILDCARD)) {
ExtendedMetaData.INSTANCE.setFeatureKind(
(EStructuralFeature) eModelElement,
ExtendedMetaData.ELEMENT_WILDCARD_FEATURE);
} else if (value == featureKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__GROUP)) {
ExtendedMetaData.INSTANCE.setFeatureKind(
(EStructuralFeature) eModelElement,
ExtendedMetaData.GROUP_FEATURE);
}
} else if (propertyName == TAG_DEFINITION__XML_NAME) {
if (eModelElement instanceof EClassifier) {
ExtendedMetaData.INSTANCE
.setName((EClassifier) eModelElement,
(String) value);
} else if (eModelElement instanceof EStructuralFeature) {
ExtendedMetaData.INSTANCE.setName(
(EStructuralFeature) eModelElement,
(String) value);
}
} else if (propertyName == TAG_DEFINITION__XML_NAMESPACE) {
ExtendedMetaData.INSTANCE.setNamespace(
(EStructuralFeature) eModelElement,
(String) value);
} else if (propertyName == TAG_DEFINITION__VISIBILITY) {
Enumeration visibilityKindEnumeration = ((EnumerationLiteral) value)
.getEnumeration();
if (eModelElement instanceof EOperation) {
if (value == visibilityKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__NONE)) {
EcoreUtil.setSuppressedVisibility(
(EOperation) eModelElement, true);
}
} else {
eStructuralFeature = (EStructuralFeature) eModelElement;
boolean isChangeable = eStructuralFeature
.isChangeable();
boolean isMany = eStructuralFeature.isMany();
boolean isUnsettable = eStructuralFeature
.isUnsettable();
if (value == visibilityKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__NONE)) {
EcoreUtil
.setSuppressedVisibility(
eStructuralFeature, EcoreUtil.GET,
true);
if (isChangeable && !isMany) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature, EcoreUtil.SET,
true);
}
if (isUnsettable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.IS_SET, true);
if (isChangeable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.UNSET, true);
}
}
} else if (value == visibilityKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__READ_ONLY)) {
if (!isMany && isChangeable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature, EcoreUtil.SET,
true);
}
if (isUnsettable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.IS_SET, true);
if (isChangeable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.UNSET, true);
}
}
} else if (value == visibilityKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__READ_WRITE)) {
if (isUnsettable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.IS_SET, true);
if (isChangeable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.UNSET, true);
}
}
} else if (value == visibilityKindEnumeration
.getOwnedLiteral(ENUMERATION_LITERAL__READ_ONLY_UNSETTABLE)) {
if (!isMany && isChangeable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature, EcoreUtil.SET,
true);
}
if (isUnsettable && isChangeable) {
EcoreUtil.setSuppressedVisibility(
eStructuralFeature,
EcoreUtil.UNSET, true);
}
}
}
} else if (propertyName == TAG_DEFINITION__ANNOTATIONS) {
@SuppressWarnings("unchecked")
EList annotations = (EList) value;
for (String annotation : annotations) {
Matcher matcher = ANNOTATION_PATTERN
.matcher(annotation);
if (matcher.find()) {
EAnnotation eAnnotation = getEAnnotation(
eModelElement, parseString(matcher
.group(1)), true);
for (Matcher detailMatcher = ANNOTATION_DETAIL_PATTERN
.matcher(matcher.group(2)); detailMatcher
.find();) {
eAnnotation.getDetails()
.put(
parseString(detailMatcher
.group(1)),
parseString(detailMatcher
.group(4)));
}
}
}
}
if (propertyName == TAG_DEFINITION__KEYS) {
EList eKeys = ((EReference) eModelElement)
.getEKeys();
@SuppressWarnings("unchecked")
EList keys = (EList) value;
for (Property key : keys) {
if (!isEClass((Classifier) key.getType())) {
eKeys.add((EAttribute) doSwitch(key));
}
}
}
}
} else if (OPTION__REPORT.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eModelElement, getTagDefinition(
stereotype, propertyName), value)),
new Object[]{eModelElement}));
}
}
}
protected void processEcoreTaggedValues(EClassifier eClassifier,
final Element element, final Map options,
final DiagnosticChain diagnostics,
final Map context) {
Stereotype eClassifierStereotype = new EcoreSwitch() {
@Override
public Stereotype caseEClass(EClass eClass) {
Stereotype eClassStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_CLASS);
if (eClassStereotype != null) {
processEcoreTaggedValue(eClass,
EcorePackage.Literals.ENAMED_ELEMENT__NAME,
element, eClassStereotype,
TAG_DEFINITION__CLASS_NAME, options, diagnostics,
context);
processEcoreTaggedValue(eClass, null, element,
eClassStereotype, TAG_DEFINITION__XML_CONTENT_KIND,
options, diagnostics, context);
}
return eClassStereotype;
}
@Override
public Stereotype caseEDataType(EDataType eDataType) {
Stereotype eDataTypeStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_DATA_TYPE);
if (eDataTypeStereotype != null) {
processEcoreTaggedValue(eDataType,
EcorePackage.Literals.ENAMED_ELEMENT__NAME,
element, eDataTypeStereotype,
TAG_DEFINITION__DATA_TYPE_NAME, options,
diagnostics, context);
}
return eDataTypeStereotype;
}
}.doSwitch(eClassifier);
if (eClassifierStereotype != null) {
processEcoreTaggedValue(eClassifier, null, element,
eClassifierStereotype, TAG_DEFINITION__XML_NAME, options,
diagnostics, context);
processEcoreTaggedValue(eClassifier,
EcorePackage.Literals.ECLASSIFIER__INSTANCE_TYPE_NAME,
element, eClassifierStereotype,
TAG_DEFINITION__INSTANCE_CLASS_NAME, options, diagnostics,
context);
processEcoreTaggedValue(eClassifier, null, element,
eClassifierStereotype, TAG_DEFINITION__ANNOTATIONS,
options, diagnostics, context);
}
}
protected void processEcoreTaggedValues(EEnum eEnum, Element element,
Map options, DiagnosticChain diagnostics,
Map context) {
Stereotype eEnumStereotype = getAppliedEcoreStereotype(element,
STEREOTYPE__E_ENUM);
if (eEnumStereotype != null) {
processEcoreTaggedValue(eEnum,
EcorePackage.Literals.ENAMED_ELEMENT__NAME, element,
eEnumStereotype, TAG_DEFINITION__ENUM_NAME, options,
diagnostics, context);
processEcoreTaggedValue(eEnum, null, element, eEnumStereotype,
TAG_DEFINITION__XML_NAME, options, diagnostics, context);
processEcoreTaggedValue(eEnum, null, element, eEnumStereotype,
TAG_DEFINITION__ANNOTATIONS, options, diagnostics, context);
}
}
protected void processEcoreTaggedValues(EEnumLiteral eEnumLiteral,
Element element, Map options,
DiagnosticChain diagnostics, Map context) {
Stereotype eEnumLiteralStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_ENUM_LITERAL);
if (eEnumLiteralStereotype != null) {
processEcoreTaggedValue(eEnumLiteral,
EcorePackage.Literals.ENAMED_ELEMENT__NAME, element,
eEnumLiteralStereotype, TAG_DEFINITION__ENUM_LITERAL_NAME,
options, diagnostics, context);
processEcoreTaggedValue(eEnumLiteral, null, element,
eEnumLiteralStereotype, TAG_DEFINITION__ANNOTATIONS,
options, diagnostics, context);
processEcoreTaggedValue(eEnumLiteral,
EcorePackage.Literals.EENUM_LITERAL__LITERAL, element,
eEnumLiteralStereotype, TAG_DEFINITION__LITERAL, options,
diagnostics, context);
}
}
protected void processEcoreTaggedValues(EGenericType eGenericType,
Element element, Map options,
DiagnosticChain diagnostics, Map context) {
Stereotype eGenericTypeStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_GENERIC_TYPE);
if (eGenericTypeStereotype != null) {
if (element.hasValue(eGenericTypeStereotype,
TAG_DEFINITION__LOWER_BOUND)) {
Classifier value = (Classifier) element.getValue(
eGenericTypeStereotype, TAG_DEFINITION__LOWER_BOUND);
if (OPTION__PROCESS.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eGenericType,
getTagDefinition(
eGenericTypeStereotype,
TAG_DEFINITION__LOWER_BOUND),
value)),
new Object[]{eGenericType}));
}
eGenericType.setELowerBound(getEGenericType(value));
} else if (OPTION__REPORT.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eGenericType, getTagDefinition(
eGenericTypeStereotype,
TAG_DEFINITION__LOWER_BOUND),
value)), new Object[]{eGenericType}));
}
}
if (element.hasValue(eGenericTypeStereotype,
TAG_DEFINITION__UPPER_BOUND)) {
Classifier value = (Classifier) element.getValue(
eGenericTypeStereotype, TAG_DEFINITION__UPPER_BOUND);
if (OPTION__PROCESS.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eGenericType,
getTagDefinition(
eGenericTypeStereotype,
TAG_DEFINITION__UPPER_BOUND),
value)),
new Object[]{eGenericType}));
}
eGenericType.setEUpperBound(getEGenericType(value));
} else if (OPTION__REPORT.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eGenericType, getTagDefinition(
eGenericTypeStereotype,
TAG_DEFINITION__UPPER_BOUND),
value)), new Object[]{eGenericType}));
}
}
}
}
protected void processEcoreTaggedValues(EOperation eOperation,
Element element, Map options,
DiagnosticChain diagnostics, Map context) {
Stereotype eOperationStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_OPERATION);
if (eOperationStereotype != null) {
processEcoreTaggedValue(eOperation,
EcorePackage.Literals.ENAMED_ELEMENT__NAME, element,
eOperationStereotype, TAG_DEFINITION__OPERATION_NAME,
options, diagnostics, context);
processEcoreTaggedValue(eOperation, null, element,
eOperationStereotype, TAG_DEFINITION__ANNOTATIONS, options,
diagnostics, context);
processEcoreTaggedValue(eOperation, null, element,
eOperationStereotype, TAG_DEFINITION__VISIBILITY, options,
diagnostics, context);
}
}
protected void processEcoreTaggedValues(EPackage ePackage,
Element element, Map options,
DiagnosticChain diagnostics, Map context) {
Stereotype ePackageStereotype = getAppliedEcoreStereotype(element,
STEREOTYPE__E_PACKAGE);
if (ePackageStereotype != null) {
processEcoreTaggedValue(ePackage,
EcorePackage.Literals.ENAMED_ELEMENT__NAME, element,
ePackageStereotype, TAG_DEFINITION__PACKAGE_NAME, options,
diagnostics, context);
processEcoreTaggedValue(ePackage,
EcorePackage.Literals.EPACKAGE__NS_PREFIX, element,
ePackageStereotype, TAG_DEFINITION__NS_PREFIX, options,
diagnostics, context);
if (isEmpty(ePackage.getNsPrefix())) {
processEcoreTaggedValue(ePackage,
EcorePackage.Literals.EPACKAGE__NS_PREFIX, element,
ePackageStereotype, TAG_DEFINITION__BASE_PACKAGE,
options, diagnostics, context);
String nsPrefix = ePackage.getNsPrefix();
if (!isEmpty(nsPrefix)) {
ePackage.setNsPrefix(nsPrefix + '.'
+ ePackage.getName());
}
}
processEcoreTaggedValue(ePackage,
EcorePackage.Literals.EPACKAGE__NS_URI, element,
ePackageStereotype, TAG_DEFINITION__NS_URI, options,
diagnostics, context);
processEcoreTaggedValue(ePackage, null, element,
ePackageStereotype, TAG_DEFINITION__ANNOTATIONS, options,
diagnostics, context);
}
}
protected void processEcoreTaggedValues(EParameter eParameter,
Element element, Map options,
DiagnosticChain diagnostics, Map context) {
Stereotype eParameterStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_PARAMETER);
if (eParameterStereotype != null) {
processEcoreTaggedValue(eParameter,
EcorePackage.Literals.ENAMED_ELEMENT__NAME, element,
eParameterStereotype, TAG_DEFINITION__PARAMETER_NAME,
options, diagnostics, context);
processEcoreTaggedValue(eParameter, null, element,
eParameterStereotype, TAG_DEFINITION__ANNOTATIONS, options,
diagnostics, context);
}
}
protected void processEcoreTaggedValues(
EStructuralFeature eStructuralFeature, final Element element,
final Map options,
final DiagnosticChain diagnostics,
final Map context) {
Stereotype eStructuralFeatureStereotype = new EcoreSwitch() {
@Override
public Stereotype caseEAttribute(EAttribute eAttribute) {
Stereotype eAttributeStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_ATTRIBUTE);
if (eAttributeStereotype != null) {
processEcoreTaggedValue(eAttribute,
EcorePackage.Literals.ENAMED_ELEMENT__NAME,
element, eAttributeStereotype,
TAG_DEFINITION__ATTRIBUTE_NAME, options,
diagnostics, context);
processEcoreTaggedValue(eAttribute,
EcorePackage.Literals.EATTRIBUTE__ID, element,
eAttributeStereotype, TAG_DEFINITION__IS_ID,
options, diagnostics, context);
}
return eAttributeStereotype;
}
@Override
public Stereotype caseEReference(EReference eReference) {
Stereotype eReferenceStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_REFERENCE);
if (eReferenceStereotype != null) {
processEcoreTaggedValue(eReference,
EcorePackage.Literals.ENAMED_ELEMENT__NAME,
element, eReferenceStereotype,
TAG_DEFINITION__REFERENCE_NAME, options,
diagnostics, context);
processEcoreTaggedValue(eReference,
EcorePackage.Literals.EREFERENCE__RESOLVE_PROXIES,
element, eReferenceStereotype,
TAG_DEFINITION__IS_RESOLVE_PROXIES, options,
diagnostics, context);
processEcoreTaggedValue(eReference, null, element,
eReferenceStereotype, TAG_DEFINITION__KEYS,
options, diagnostics, context);
}
return eReferenceStereotype;
}
}.doSwitch(eStructuralFeature);
if (eStructuralFeatureStereotype != null) {
processEcoreTaggedValue(eStructuralFeature,
EcorePackage.Literals.ESTRUCTURAL_FEATURE__TRANSIENT,
element, eStructuralFeatureStereotype,
TAG_DEFINITION__IS_TRANSIENT, options, diagnostics, context);
processEcoreTaggedValue(eStructuralFeature,
EcorePackage.Literals.ESTRUCTURAL_FEATURE__UNSETTABLE,
element, eStructuralFeatureStereotype,
TAG_DEFINITION__IS_UNSETTABLE, options, diagnostics,
context);
processEcoreTaggedValue(eStructuralFeature,
EcorePackage.Literals.ESTRUCTURAL_FEATURE__VOLATILE,
element, eStructuralFeatureStereotype,
TAG_DEFINITION__IS_VOLATILE, options, diagnostics, context);
processEcoreTaggedValue(eStructuralFeature, null, element,
eStructuralFeatureStereotype, TAG_DEFINITION__XML_NAME,
options, diagnostics, context);
processEcoreTaggedValue(eStructuralFeature, null, element,
eStructuralFeatureStereotype,
TAG_DEFINITION__XML_NAMESPACE, options, diagnostics,
context);
processEcoreTaggedValue(eStructuralFeature, null, element,
eStructuralFeatureStereotype,
TAG_DEFINITION__XML_FEATURE_KIND, options, diagnostics,
context);
processEcoreTaggedValue(eStructuralFeature, null, element,
eStructuralFeatureStereotype, TAG_DEFINITION__VISIBILITY,
options, diagnostics, context);
processEcoreTaggedValue(eStructuralFeature, null, element,
eStructuralFeatureStereotype, TAG_DEFINITION__ANNOTATIONS,
options, diagnostics, context);
}
}
protected void processEcoreTaggedValues(ETypeParameter eTypeParameter,
Element element, final Map options,
final DiagnosticChain diagnostics,
final Map context) {
Stereotype eTypeParameterStereotype = getAppliedEcoreStereotype(
element, STEREOTYPE__E_TYPE_PARAMETER);
if (eTypeParameterStereotype != null
&& element.hasValue(eTypeParameterStereotype,
TAG_DEFINITION__BOUNDS)) {
@SuppressWarnings("unchecked")
EList value = (EList) element.getValue(
eTypeParameterStereotype, TAG_DEFINITION__BOUNDS);
if (OPTION__PROCESS.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eTypeParameter, getTagDefinition(
eTypeParameterStereotype,
TAG_DEFINITION__BOUNDS), value)),
new Object[]{eTypeParameter}));
}
EList eBounds = eTypeParameter.getEBounds();
for (Classifier bound : value) {
eBounds.add(getEGenericType(bound));
}
} else if (OPTION__REPORT.equals(options
.get(OPTION__ECORE_TAGGED_VALUES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
ECORE_TAGGED_VALUE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportEcoreTaggedValue_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eTypeParameter, getTagDefinition(
eTypeParameterStereotype,
TAG_DEFINITION__BOUNDS), value)),
new Object[]{eTypeParameter}));
}
}
}
protected void processEcoreTaggedValues(
final Map options,
final DiagnosticChain diagnostics,
final Map context) {
for (final Map.Entry entry : elementToEModelElementMap
.entrySet()) {
EModelElement eModelElement = entry.getValue();
new EcoreSwitch() {
@Override
public Object caseEClassifier(EClassifier eClassifier) {
processEcoreTaggedValues(eClassifier, entry.getKey(),
options, diagnostics, context);
return eClassifier;
}
@Override
public Object caseEEnum(EEnum eEnum) {
processEcoreTaggedValues(eEnum, entry.getKey(),
options, diagnostics, context);
return eEnum;
}
@Override
public Object caseEEnumLiteral(EEnumLiteral eEnumLiteral) {
processEcoreTaggedValues(eEnumLiteral, entry.getKey(),
options, diagnostics, context);
return eEnumLiteral;
}
@Override
public Object caseEOperation(EOperation eOperation) {
processEcoreTaggedValues(eOperation, entry.getKey(),
options, diagnostics, context);
return eOperation;
}
@Override
public Object caseEPackage(EPackage ePackage) {
processEcoreTaggedValues(ePackage, entry.getKey(),
options, diagnostics, context);
return ePackage;
}
@Override
public Object caseEParameter(EParameter eParameter) {
processEcoreTaggedValues(eParameter, entry.getKey(),
options, diagnostics, context);
return eParameter;
}
@Override
public Object caseEStructuralFeature(
EStructuralFeature eStructuralFeature) {
processEcoreTaggedValues(eStructuralFeature, entry
.getKey(), options, diagnostics, context);
return eStructuralFeature;
}
}.doSwitch(eModelElement);
}
}
protected void processRedefiningOperations(Map options,
DiagnosticChain diagnostics, Map context) {
for (Map.Entry entry : elementToEModelElementMap
.entrySet()) {
Element element = entry.getKey();
EModelElement eModelElement = entry.getValue();
if (eModelElement instanceof EOperation
&& element instanceof Operation) {
Operation operation = (Operation) element;
for (Operation redefinedOperation : operation
.getRedefinedOperations()) {
EOperation eOperation = (EOperation) elementToEModelElementMap
.get(redefinedOperation);
if (DEBUG) {
System.out.println(getQualifiedText(eModelElement)
+ " redefines " + getQualifiedText(eOperation)); //$NON-NLS-1$
}
if (OPTION__PROCESS.equals(options
.get(OPTION__REDEFINING_OPERATIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
REDEFINING_OPERATION,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessRedefiningOperation_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eModelElement,
eOperation)), new Object[]{
eModelElement, eOperation}));
}
getEAnnotation(eModelElement,
ANNOTATION__REDEFINES, true).getReferences()
.add(eOperation);
} else if (OPTION__REPORT.equals(options
.get(OPTION__REDEFINING_OPERATIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
REDEFINING_OPERATION,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportRedefiningOperation_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eModelElement, eOperation)),
new Object[]{eModelElement, eOperation}));
}
}
}
}
}
protected void processRedefiningProperties(Map options,
DiagnosticChain diagnostics, Map context) {
for (Map.Entry entry : elementToEModelElementMap
.entrySet()) {
Element element = entry.getKey();
EModelElement eModelElement = entry.getValue();
if (eModelElement instanceof EStructuralFeature
&& element instanceof Property) {
Property property = (Property) element;
for (Property redefinedProperty : property
.getRedefinedProperties()) {
if (redefinedProperty.getOwningAssociation() == null) {
EStructuralFeature eStructuralFeature = (EStructuralFeature) elementToEModelElementMap
.get(redefinedProperty);
if (DEBUG) {
System.out
.println(getQualifiedText(eModelElement)
+ " redefines " //$NON-NLS-1$
+ getQualifiedText(eStructuralFeature));
}
if (OPTION__PROCESS.equals(options
.get(OPTION__REDEFINING_PROPERTIES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
REDEFINING_PROPERTY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessRedefiningProperty_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eModelElement,
eStructuralFeature)),
new Object[]{eModelElement,
eStructuralFeature}));
}
getEAnnotation(eModelElement,
ANNOTATION__REDEFINES, true)
.getReferences().add(eStructuralFeature);
} else if (OPTION__REPORT.equals(options
.get(OPTION__REDEFINING_PROPERTIES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
REDEFINING_PROPERTY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportRedefiningProperty_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eModelElement,
eStructuralFeature)),
new Object[]{eModelElement,
eStructuralFeature}));
}
}
}
}
}
}
protected boolean isCompositeSubset(Property property) {
for (Property subsettedProperty : property.getSubsettedProperties()) {
if (subsettedProperty.isComposite()
|| isCompositeSubset(subsettedProperty)) {
return true;
}
}
return false;
}
protected void processSubsettingProperties(Map options,
DiagnosticChain diagnostics, Map context) {
for (Map.Entry entry : elementToEModelElementMap
.entrySet()) {
Element element = entry.getKey();
EModelElement eModelElement = entry.getValue();
if (eModelElement instanceof EStructuralFeature
&& element instanceof Property) {
Property property = (Property) element;
for (Property subsettedProperty : property
.getSubsettedProperties()) {
if (subsettedProperty.getOwningAssociation() == null) {
EStructuralFeature subsettedEStructuralFeature = (EStructuralFeature) elementToEModelElementMap
.get(subsettedProperty);
if (DEBUG) {
System.out
.println(getQualifiedText(eModelElement)
+ " subsets " //$NON-NLS-1$
+ getQualifiedText(subsettedEStructuralFeature));
}
if (OPTION__PROCESS.equals(options
.get(OPTION__SUBSETTING_PROPERTIES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
SUBSETTING_PROPERTY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessSubsettingProperty_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eModelElement,
subsettedEStructuralFeature)),
new Object[]{eModelElement,
subsettedEStructuralFeature}));
}
if (!subsettedEStructuralFeature.isDerived()
&& subsettedEStructuralFeature instanceof EReference) {
EReference subsettedEReference = (EReference) subsettedEStructuralFeature;
EReference eReference = (EReference) eModelElement;
if (subsettedEReference.isContainment()
|| isCompositeSubset(subsettedProperty)) {
eReference.setContainment(false);
}
if (!eReference.isContainment()) {
eReference
.setResolveProxies(subsettedEReference
.isResolveProxies());
}
}
getEAnnotation(eModelElement,
ANNOTATION__SUBSETS, true).getReferences()
.add(
elementToEModelElementMap
.get(subsettedProperty));
} else if (OPTION__REPORT.equals(options
.get(OPTION__SUBSETTING_PROPERTIES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
SUBSETTING_PROPERTY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportSubsettingProperty_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eModelElement,
subsettedEStructuralFeature)),
new Object[]{eModelElement,
subsettedEStructuralFeature}));
}
}
}
}
}
}
protected void processUnionProperties(Map options,
DiagnosticChain diagnostics, Map context) {
for (Map.Entry entry : elementToEModelElementMap
.entrySet()) {
Element element = entry.getKey();
EModelElement eModelElement = entry.getValue();
if (eModelElement instanceof EStructuralFeature
&& element instanceof Property
&& ((Property) element).isDerivedUnion()) {
EStructuralFeature eStructuralFeature = (EStructuralFeature) eModelElement;
if (DEBUG) {
System.out.println(getQualifiedText(eStructuralFeature)
+ " is a union"); //$NON-NLS-1$
}
if (OPTION__PROCESS.equals(options
.get(OPTION__UNION_PROPERTIES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
UNION_PROPERTY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessUnionProperty_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eStructuralFeature)),
new Object[]{eStructuralFeature}));
}
getEAnnotation(eStructuralFeature, ANNOTATION__UNION,
true);
eStructuralFeature.setChangeable(false);
eStructuralFeature.setTransient(true);
eStructuralFeature.setVolatile(true);
} else if (OPTION__REPORT.equals(options
.get(OPTION__UNION_PROPERTIES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
UNION_PROPERTY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportUnionProperty_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eModelElement)),
new Object[]{eModelElement}));
}
}
}
}
protected void processDerivedFeatures(Map options,
DiagnosticChain diagnostics, Map context) {
for (EModelElement eModelElement : elementToEModelElementMap
.values()) {
if (eModelElement instanceof EStructuralFeature) {
EStructuralFeature.Internal eStructuralFeature = (EStructuralFeature.Internal) eModelElement;
if (eStructuralFeature.isDerived()
&& (eStructuralFeature.isContainment() || !eStructuralFeature
.isVolatile())) {
if (OPTION__PROCESS.equals(options
.get(OPTION__DERIVED_FEATURES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
DERIVED_FEATURE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessDerivedFeature_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eStructuralFeature)),
new Object[]{eStructuralFeature}));
}
if (eStructuralFeature instanceof EReference) {
((EReference) eStructuralFeature)
.setContainment(false);
}
eStructuralFeature.setTransient(true);
eStructuralFeature.setVolatile(true);
} else if (OPTION__REPORT.equals(options
.get(OPTION__DERIVED_FEATURES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
DERIVED_FEATURE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportDerivedFeature_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eStructuralFeature)),
new Object[]{eStructuralFeature}));
}
}
}
}
}
protected void ensureConformity(ETypedElement eTypedElement,
ETypedElement otherETypedElement) {
if (eTypedElement.isRequired() != otherETypedElement.isRequired()) {
int lowerBound = eTypedElement.getLowerBound();
int otherLowerBound = otherETypedElement.getLowerBound();
int lesserLowerBound = getLesserLowerBound(otherLowerBound,
lowerBound);
if (lesserLowerBound != otherLowerBound) {
if (DEBUG) {
System.err.println("Changed lower bound of " //$NON-NLS-1$
+ getQualifiedText(otherETypedElement) + " from " //$NON-NLS-1$
+ otherLowerBound + " to " //$NON-NLS-1$
+ lesserLowerBound);
}
otherETypedElement.setLowerBound(lesserLowerBound);
}
if (lesserLowerBound != lowerBound) {
if (DEBUG) {
System.out.println("Changed lower bound of " //$NON-NLS-1$
+ getQualifiedText(eTypedElement) + " from " //$NON-NLS-1$
+ lowerBound + " to " //$NON-NLS-1$
+ lesserLowerBound);
}
eTypedElement.setLowerBound(lesserLowerBound);
}
}
boolean isMany = eTypedElement.isMany();
boolean otherIsMany = otherETypedElement.isMany();
if (isMany != otherIsMany) {
int upperBound = eTypedElement.getUpperBound();
int otherUpperBound = otherETypedElement.getUpperBound();
int greaterUpperBound = getGreaterUpperBound(otherUpperBound,
upperBound);
if (greaterUpperBound != otherUpperBound) {
if (DEBUG) {
System.err.println("Changed upper bound of " //$NON-NLS-1$
+ getQualifiedText(otherETypedElement) + " from " //$NON-NLS-1$
+ otherUpperBound + " to " //$NON-NLS-1$
+ greaterUpperBound);
}
otherETypedElement.setUpperBound(greaterUpperBound);
}
if (greaterUpperBound != upperBound) {
if (DEBUG) {
System.out.println("Changed upper bound of " //$NON-NLS-1$
+ getQualifiedText(eTypedElement) + " from " //$NON-NLS-1$
+ upperBound + " to " //$NON-NLS-1$
+ greaterUpperBound);
}
eTypedElement.setUpperBound(greaterUpperBound);
}
}
if (!isMany && !otherIsMany) {
EClassifier eType = eTypedElement.getEType();
EClassifier otherEType = otherETypedElement.getEType();
EClassifier commonEType = getCommonEType(otherEType, eType);
if (commonEType != otherEType) {
if (DEBUG) {
System.err.println("Changed type of " //$NON-NLS-1$
+ getQualifiedText(otherETypedElement)
+ " from " //$NON-NLS-1$
+ getQualifiedText(otherEType)
+ " to " + getQualifiedText(commonEType)); //$NON-NLS-1$
}
otherETypedElement.setEType(commonEType);
}
if (commonEType != eType) {
if (DEBUG) {
System.out.println("Changed type of " //$NON-NLS-1$
+ getQualifiedText(eTypedElement)
+ " from " //$NON-NLS-1$
+ getQualifiedText(eType)
+ " to " + getQualifiedText(commonEType)); //$NON-NLS-1$
}
eTypedElement.setEType(commonEType);
}
}
eTypedElement.setOrdered(otherETypedElement.isOrdered());
eTypedElement.setUnique(otherETypedElement.isUnique());
}
protected void qualifyName(ENamedElement eNamedElement) {
EObject eContainer = eNamedElement.eContainer();
if (eContainer instanceof ENamedElement) {
qualifyName(eNamedElement, ((ENamedElement) eContainer)
.getName());
}
}
protected void qualifyName(ENamedElement eNamedElement, String qualifier) {
String qualifiedName = qualifier + '_' + eNamedElement.getName();
if (DEBUG) {
System.err.println("Qualified " //$NON-NLS-1$
+ getQualifiedText(eNamedElement) + " as " //$NON-NLS-1$
+ qualifiedName);
}
eNamedElement.setName(qualifiedName);
}
protected void processDuplicateOperations(Map options,
DiagnosticChain diagnostics, Map context) {
List operationsToDuplicate = new UniqueEList.FastCompare();
for (EModelElement eModelElement : elementToEModelElementMap
.values()) {
if (eModelElement instanceof EClass) {
EClass eClass = (EClass) eModelElement;
for (Iterator eOperations = eClass
.getEOperations().iterator(); eOperations.hasNext();) {
EOperation eOperation = eOperations.next();
for (EOperation otherEOperation : eClass
.getEAllOperations()) {
if (otherEOperation == eOperation) {
break;
} else if (new SignatureMatcher(eOperation)
.matches(otherEOperation)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__DUPLICATE_OPERATIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_OPERATION,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessDuplicateOperation_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eOperation,
otherEOperation)),
new Object[]{eClass,
otherEOperation}));
}
operationsToDuplicate.add(eOperation);
ensureConformity(eOperation,
otherEOperation);
List redefinedOperations = getEAnnotation(
eOperation, ANNOTATION__REDEFINES, true)
.getReferences();
if (!redefinedOperations
.contains(otherEOperation)) {
redefinedOperations
.add(otherEOperation);
}
} else if (OPTION__DISCARD.equals(options
.get(OPTION__DUPLICATE_OPERATIONS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_OPERATION,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_DiscardDuplicateOperation_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eOperation,
otherEOperation)),
new Object[]{eClass,
otherEOperation}));
}
eOperations.remove();
break;
} else if (OPTION__REPORT.equals(options
.get(OPTION__DUPLICATE_OPERATIONS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_OPERATION,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportDuplicateOperation_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eOperation,
otherEOperation)),
new Object[]{eOperation,
otherEOperation}));
}
}
}
}
}
}
for (EOperation eOperation : operationsToDuplicate) {
getEAnnotation(eOperation.getEContainingClass(),
ANNOTATION__DUPLICATES, true).getContents().add(eOperation);
}
}
protected void processDuplicateOperationInheritance(
Map options, DiagnosticChain diagnostics,
Map context) {
for (EModelElement eModelElement : elementToEModelElementMap
.values()) {
if (eModelElement instanceof EClass) {
EClass eClass = (EClass) eModelElement;
if (eClass.getESuperTypes().size() > 1) {
Iterator eSuperTypes = eClass.getESuperTypes()
.iterator();
eSuperTypes.next();
while (eSuperTypes.hasNext()) {
EClass mixinEClass = eSuperTypes.next();
mixinEOperationLoop : for (EOperation mixinEOperation : mixinEClass
.getEAllOperations()) {
for (EOperation eOperation : eClass
.getEAllOperations()) {
if (eOperation == mixinEOperation) {
break;
} else if (new SignatureMatcher(
mixinEOperation).matches(eOperation)) {
if (OPTION__PROCESS
.equals(options
.get(OPTION__DUPLICATE_OPERATION_INHERITANCE))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_OPERATION_INHERITANCE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessDuplicateOperationInheritance_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eClass,
eOperation,
mixinEOperation)),
new Object[]{eClass,
eOperation,
mixinEOperation}));
}
qualifyName(mixinEOperation);
List redefinedOperations = getEAnnotation(
mixinEOperation,
ANNOTATION__REDEFINES, true)
.getReferences();
if (!redefinedOperations
.contains(eOperation)) {
redefinedOperations
.add(eOperation);
}
} else if (OPTION__DISCARD
.equals(options
.get(OPTION__DUPLICATE_OPERATION_INHERITANCE))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_OPERATION_INHERITANCE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_DiscardDuplicateOperationInheritance_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eClass,
eOperation,
mixinEOperation)),
new Object[]{eClass,
eOperation,
mixinEOperation}));
}
eSuperTypes.remove();
break mixinEOperationLoop;
} else if (OPTION__REPORT
.equals(options
.get(OPTION__DUPLICATE_OPERATION_INHERITANCE))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_OPERATION_INHERITANCE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportDuplicateOperationInheritance_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eClass,
eOperation,
mixinEOperation)),
new Object[]{eClass,
eOperation,
mixinEOperation}));
}
}
}
}
}
}
}
}
}
protected void processDuplicateFeatures(Map options,
DiagnosticChain diagnostics, Map context) {
EList featuresToDuplicate = new UniqueEList.FastCompare();
EList featuresToRemove = new UniqueEList.FastCompare();
for (EModelElement eModelElement : elementToEModelElementMap
.values()) {
if (eModelElement instanceof EClass) {
EClass eClass = (EClass) eModelElement;
for (Iterator eStructuralFeatures = eClass
.getEStructuralFeatures().iterator(); eStructuralFeatures
.hasNext();) {
EStructuralFeature.Internal eStructuralFeature = (EStructuralFeature.Internal) eStructuralFeatures
.next();
for (EStructuralFeature otherEStructuralFeature : eClass
.getEAllStructuralFeatures()) {
if (otherEStructuralFeature == eStructuralFeature) {
break;
} else if (new NameMatcher(eStructuralFeature)
.matches(otherEStructuralFeature)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__DUPLICATE_FEATURES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_FEATURE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessDuplicateFeature_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eStructuralFeature,
otherEStructuralFeature)),
new Object[]{
eStructuralFeature,
otherEStructuralFeature}));
}
int lowerBound = eStructuralFeature
.getLowerBound();
int upperBound = eStructuralFeature
.getUpperBound();
EClassifier eType = eStructuralFeature
.getEType();
if (!featuresToDuplicate
.contains(eStructuralFeature)) {
EStructuralFeature.Internal duplicateEStructuralFeature = otherEStructuralFeature
.isDerived()
&& !eStructuralFeature.isDerived()
? (EStructuralFeature.Internal) otherEStructuralFeature
: eStructuralFeature;
if (DEBUG
&& duplicateEStructuralFeature == otherEStructuralFeature) {
System.err
.println("Non-derived feature " //$NON-NLS-1$
+ getQualifiedText(eStructuralFeature)
+ " is a duplicate of derived feature " //$NON-NLS-1$
+ getQualifiedText(otherEStructuralFeature));
}
featuresToDuplicate
.add(duplicateEStructuralFeature);
ensureConformity(eStructuralFeature,
otherEStructuralFeature);
}
EAnnotation redefinesAnnotation = getEAnnotation(
eStructuralFeature,
ANNOTATION__REDEFINES, true);
EList redefinedFeatures = redefinesAnnotation
.getReferences();
if (!redefinedFeatures
.contains(otherEStructuralFeature)) {
redefinedFeatures
.add(otherEStructuralFeature);
}
EMap redefinitionDetails = redefinesAnnotation
.getDetails();
if (eStructuralFeature.getLowerBound() != lowerBound) {
redefinitionDetails
.put(
EcorePackage.Literals.ETYPED_ELEMENT__LOWER_BOUND
.getName(), String
.valueOf(lowerBound));
}
if (eStructuralFeature.getUpperBound() != upperBound) {
redefinitionDetails
.put(
EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND
.getName(), String
.valueOf(upperBound));
}
if (eStructuralFeature.getEType() != eType) {
redefinitionDetails
.put(
EcorePackage.Literals.ETYPED_ELEMENT__ETYPE
.getName(),
getQualifiedName(eType,
NamedElement.SEPARATOR));
}
} else if (OPTION__DISCARD.equals(options
.get(OPTION__DUPLICATE_FEATURES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_FEATURE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_DiscardDuplicateFeature_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eStructuralFeature,
otherEStructuralFeature)),
new Object[]{eClass,
otherEStructuralFeature}));
}
EReference eOpposite = eStructuralFeature
.getEOpposite();
if (eOpposite != null) {
featuresToRemove.add(eOpposite);
}
eStructuralFeatures.remove();
break;
} else if (OPTION__REPORT.equals(options
.get(OPTION__DUPLICATE_FEATURES))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_FEATURE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportDuplicateFeature_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eStructuralFeature,
otherEStructuralFeature)),
new Object[]{eStructuralFeature,
otherEStructuralFeature}));
}
}
}
}
}
}
for (EStructuralFeature.Internal eStructuralFeature : featuresToDuplicate) {
EAnnotation duplicatesAnnotation = getEAnnotation(
eStructuralFeature.getEContainingClass(),
ANNOTATION__DUPLICATES, true);
duplicatesAnnotation.getContents().add(eStructuralFeature);
EAnnotation redefinesAnnotation = eStructuralFeature
.getEAnnotation(ANNOTATION__REDEFINES);
if (redefinesAnnotation != null) {
EMap redefinitionDetails = redefinesAnnotation
.getDetails();
if (!redefinitionDetails.isEmpty()) {
getEAnnotation(duplicatesAnnotation,
eStructuralFeature.getName(), true).getDetails()
.putAll(redefinitionDetails);
redefinitionDetails.clear();
}
}
EReference eOpposite = eStructuralFeature.getEOpposite();
if (eOpposite != null
&& !featuresToDuplicate.contains(eOpposite)) {
eOpposite.setEOpposite(null);
if (eStructuralFeature.isContainment()) {
eOpposite.setChangeable(false);
eOpposite.setTransient(true);
}
eOpposite.setVolatile(true);
}
}
for (EStructuralFeature eStructuralFeature : featuresToRemove) {
EClass eContainingClass = eStructuralFeature
.getEContainingClass();
if (eContainingClass != null) {
eContainingClass.getEStructuralFeatures().remove(
eStructuralFeature);
}
}
}
protected void processDuplicateFeatureInheritance(
Map options, DiagnosticChain diagnostics,
Map context) {
for (EModelElement eModelElement : elementToEModelElementMap
.values()) {
if (eModelElement instanceof EClass) {
EClass eClass = (EClass) eModelElement;
if (eClass.getESuperTypes().size() > 1) {
Iterator eSuperTypes = eClass.getESuperTypes()
.iterator();
eSuperTypes.next();
while (eSuperTypes.hasNext()) {
EClass mixinEClass = eSuperTypes.next();
mixinEStructuralFeatureLoop : for (EStructuralFeature mixinEStructuralFeature : mixinEClass
.getEAllStructuralFeatures()) {
for (EStructuralFeature eStructuralFeature : eClass
.getEAllStructuralFeatures()) {
if (eStructuralFeature == mixinEStructuralFeature) {
break;
} else if (new NameMatcher(
mixinEStructuralFeature)
.matches(eStructuralFeature)) {
if (OPTION__PROCESS
.equals(options
.get(OPTION__DUPLICATE_FEATURE_INHERITANCE))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_FEATURE_INHERITANCE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessDuplicateFeatureInheritance_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eClass,
eStructuralFeature,
mixinEStructuralFeature)),
new Object[]{eClass,
eStructuralFeature,
mixinEStructuralFeature}));
}
qualifyName(mixinEStructuralFeature);
EList redefinedFeatures = getEAnnotation(
mixinEStructuralFeature,
ANNOTATION__REDEFINES, true)
.getReferences();
if (!redefinedFeatures
.contains(eStructuralFeature)) {
redefinedFeatures
.add(eStructuralFeature);
}
} else if (OPTION__DISCARD
.equals(options
.get(OPTION__DUPLICATE_FEATURE_INHERITANCE))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_FEATURE_INHERITANCE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_DiscardDuplicateFeatureInheritance_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eClass,
eStructuralFeature,
mixinEStructuralFeature)),
new Object[]{eClass,
eStructuralFeature,
mixinEStructuralFeature}));
}
eSuperTypes.remove();
break mixinEStructuralFeatureLoop;
} else if (OPTION__REPORT
.equals(options
.get(OPTION__DUPLICATE_FEATURE_INHERITANCE))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.ERROR,
UMLValidator.DIAGNOSTIC_SOURCE,
DUPLICATE_FEATURE_INHERITANCE,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportDuplicateFeatureInheritance_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eClass,
eStructuralFeature,
mixinEStructuralFeature)),
new Object[]{eClass,
eStructuralFeature,
mixinEStructuralFeature}));
}
}
}
}
}
}
}
}
}
protected void processSuperClassOrder(Map options,
DiagnosticChain diagnostics, Map context) {
Comparator eClassComparator = new Comparator() {
public int compare(EClass eClass, EClass otherEClass) {
int eAllStructuralFeaturesSize = eClass
.getEAllStructuralFeatures().size();
int otherEAllStructuralFeaturesSize = otherEClass
.getEAllStructuralFeatures().size();
return eAllStructuralFeaturesSize < otherEAllStructuralFeaturesSize
? 1
: (otherEAllStructuralFeaturesSize < eAllStructuralFeaturesSize
? -1
: CommonPlugin.INSTANCE.getComparator().compare(
eClass.getName(), otherEClass.getName()));
}
};
for (Map.Entry entry : elementToEModelElementMap
.entrySet()) {
Element key = entry.getKey();
EModelElement value = entry.getValue();
if (key instanceof Classifier && value instanceof EClass) {
EClass eClass = (EClass) value;
EList eSuperTypes = eClass.getESuperTypes();
List extendSuperClasses = new ArrayList();
List unspecifiedSuperClasses = new ArrayList();
List mixinSuperClasses = new ArrayList();
for (Generalization generalization : ((Classifier) key)
.getGeneralizations()) {
Classifier general = generalization.getGeneral();
if (general != null) {
EModelElement eModelElement = elementToEModelElementMap
.get(general);
if (eSuperTypes.contains(eModelElement)) {
if (generalization.hasKeyword("extend")) { //$NON-NLS-1$
extendSuperClasses
.add((EClass) eModelElement);
} else if (generalization.hasKeyword("mixin")) { //$NON-NLS-1$
mixinSuperClasses
.add((EClass) eModelElement);
} else {
unspecifiedSuperClasses
.add((EClass) eModelElement);
}
}
}
}
Collections.sort(extendSuperClasses, eClassComparator);
Collections.sort(unspecifiedSuperClasses, eClassComparator);
Collections.sort(mixinSuperClasses, eClassComparator);
List superClasses = new UniqueEList.FastCompare(
extendSuperClasses);
superClasses.addAll(unspecifiedSuperClasses);
superClasses.addAll(mixinSuperClasses);
if (!superClasses.equals(eSuperTypes)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__SUPER_CLASS_ORDER))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
SUPER_CLASS_ORDER,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessSuperClassOrder_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eClass)),
new Object[]{eClass}));
}
for (ListIterator sc = superClasses
.listIterator(); sc.hasNext();) {
EClass superClass = sc.next();
eSuperTypes
.move(sc.previousIndex(), superClass);
}
}
if (OPTION__REPORT.equals(options
.get(OPTION__SUPER_CLASS_ORDER))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
SUPER_CLASS_ORDER,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportSuperClassOrder_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eClass)), new Object[]{eClass}));
}
}
}
}
}
protected void processComment(EModelElement eModelElement,
String comment, final Map options,
final DiagnosticChain diagnostics,
final Map context) {
if (OPTION__PROCESS.equals(options.get(OPTION__COMMENTS))) {
if (diagnostics != null) {
diagnostics.add(new BasicDiagnostic(Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE, COMMENT,
UMLPlugin.INSTANCE.getString(
"_UI_UML2EcoreConverter_ProcessComment_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context, eModelElement)),
new Object[]{eModelElement}));
}
addDocumentation(eModelElement, comment);
} else if (OPTION__REPORT.equals(options.get(OPTION__COMMENTS))
&& diagnostics != null) {
diagnostics.add(new BasicDiagnostic(Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE, COMMENT, UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportComment_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context, eModelElement)),
new Object[]{eModelElement}));
}
}
protected void processOperationBody(EOperation eOperation,
EList languages, EList bodies,
Map options, DiagnosticChain diagnostics,
Map context) {
int languagesSize = languages.size();
int bodiesSize = bodies.size();
for (int i = 0; i < (languagesSize == bodiesSize
? bodiesSize
: (bodiesSize == 1
? 1
: 0)); i++) {
String language = i < languagesSize
? languages.get(i)
: LANGUAGE__OCL;
if (OPTION__PROCESS.equals(options
.get(OPTION__OPERATION_BODIES))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
OPERATION_BODY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessOperationBody_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eOperation, language)),
new Object[]{eOperation}));
}
String source = UML2_GEN_MODEL_PACKAGE_1_1_NS_URI;
if (LANGUAGE__OCL.equals(language)
&& OPTION__PROCESS.equals(options
.get(OPTION__INVOCATION_DELEGATES))) {
addInvocationDelegate(
(EPackage) getContainingEObject(eOperation,
EcorePackage.Literals.EPACKAGE, true),
OCL_DELEGATE_URI);
source = OCL_DELEGATE_URI;
} else if (LANGUAGE__JAVA.equals(language)) {
source = EMF_GEN_MODEL_PACKAGE_NS_URI;
}
EcoreUtil.setAnnotation(eOperation, source,
ANNOTATION_DETAIL__BODY, bodies.get(i));
} else if (OPTION__REPORT.equals(options
.get(OPTION__OPERATION_BODIES)) && diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
OPERATION_BODY,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportOperationBody_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eOperation, language)),
new Object[]{eOperation}));
}
}
}
protected void processOperationBodies(Map options,
DiagnosticChain diagnostics, Map context) {
for (Map.Entry entry : elementToEModelElementMap
.entrySet()) {
Element key = entry.getKey();
EModelElement value = entry.getValue();
if (key instanceof Operation && value instanceof EOperation) {
Operation operation = (Operation) key;
EOperation eOperation = (EOperation) value;
for (Behavior method : operation.getMethods()) {
if (method instanceof OpaqueBehavior) {
OpaqueBehavior body = (OpaqueBehavior) method;
processOperationBody(eOperation, body
.getLanguages(), body.getBodies(), options,
diagnostics, context);
}
}
Constraint bodyCondition = operation.getBodyCondition();
if (bodyCondition != null) {
ValueSpecification specification = bodyCondition
.getSpecification();
if (specification instanceof OpaqueExpression) {
OpaqueExpression body = (OpaqueExpression) specification;
processOperationBody(eOperation, body
.getLanguages(), body.getBodies(), options,
diagnostics, context);
}
}
}
}
}
protected void processInvariantBody(EOperation eOperation,
EList languages, EList bodies,
Map options, DiagnosticChain diagnostics,
Map context) {
int languagesSize = languages.size();
int bodiesSize = bodies.size();
for (int i = 0; i < (languagesSize == bodiesSize
? bodiesSize
: (bodiesSize == 1
? 1
: 0)); i++) {
String language = i < languagesSize
? languages.get(i)
: LANGUAGE__OCL;
if (LANGUAGE__OCL.equals(language)) {
addValidationDelegate(
(EPackage) getContainingEObject(eOperation,
EcorePackage.Literals.EPACKAGE, true),
OCL_DELEGATE_URI);
EcoreUtil.setAnnotation(eOperation, OCL_DELEGATE_URI,
ANNOTATION_DETAIL__BODY, bodies.get(i));
}
}
}
protected void processConstraintBody(EClassifier eClassifier,
String name, EList languages, EList bodies,
Map options, DiagnosticChain diagnostics,
Map context) {
int languagesSize = languages.size();
int bodiesSize = bodies.size();
for (int i = 0; i < (languagesSize == bodiesSize
? bodiesSize
: (bodiesSize == 1
? 1
: 0)); i++) {
String language = i < languagesSize
? languages.get(i)
: LANGUAGE__OCL;
if (LANGUAGE__OCL.equals(language)) {
addValidationDelegate(
(EPackage) getContainingEObject(eClassifier,
EcorePackage.Literals.EPACKAGE, true),
OCL_DELEGATE_URI);
EcoreUtil.setAnnotation(eClassifier, OCL_DELEGATE_URI,
name, bodies.get(i));
}
}
}
protected EModelElement processInvariantConstraint(
EClassifier eClassifier, Constraint constraint,
Map options, DiagnosticChain diagnostics,
Map context) {
String name = constraint.getName();
if (!isEmpty(name)) {
if (OPTION__PROCESS.equals(options
.get(OPTION__INVARIANT_CONSTRAINTS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
INVARIANT_CONSTRAINT,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessInvariantConstraint_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eClassifier, name)),
new Object[]{eClassifier}));
}
if (eClassifier instanceof EClass) {
EOperation eOperation = EcoreFactory.eINSTANCE
.createEOperation();
elementToEModelElementMap.put(constraint, eOperation);
((EClass) eClassifier).getEOperations().add(eOperation);
setName(eOperation, name, true);
eOperation.setEType(EcorePackage.Literals.EBOOLEAN);
EParameter eParameter = EcoreFactory.eINSTANCE
.createEParameter();
eOperation.getEParameters().add(eParameter);
setName(eParameter, "diagnostics", false); //$NON-NLS-1$
addDocumentation(eParameter,
"The chain of diagnostics to which problems are to be appended."); //$NON-NLS-1$
eParameter
.setEType(EcorePackage.Literals.EDIAGNOSTIC_CHAIN);
eParameter = EcoreFactory.eINSTANCE.createEParameter();
eOperation.getEParameters().add(eParameter);
setName(eParameter, "context", false); //$NON-NLS-1$
addDocumentation(eParameter,
"The cache of context-specific information."); //$NON-NLS-1$
EGenericType eGenericType = EcoreFactory.eINSTANCE
.createEGenericType();
eGenericType.setEClassifier(EcorePackage.Literals.EMAP);
EGenericType eGenericKeyType = EcoreFactory.eINSTANCE
.createEGenericType();
eGenericKeyType
.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eGenericType.getETypeArguments().add(eGenericKeyType);
EGenericType eGenericValueType = EcoreFactory.eINSTANCE
.createEGenericType();
eGenericValueType
.setEClassifier(EcorePackage.Literals.EJAVA_OBJECT);
eGenericType.getETypeArguments().add(eGenericValueType);
eParameter.setEGenericType(eGenericType);
ValueSpecification specification = constraint
.getSpecification();
if (specification instanceof OpaqueExpression) {
OpaqueExpression body = (OpaqueExpression) specification;
if (OPTION__PROCESS.equals(options
.get(OPTION__VALIDATION_DELEGATES))) {
processInvariantBody(eOperation,
body.getLanguages(), body.getBodies(),
options, diagnostics, context);
} else {
processOperationBody(eOperation,
body.getLanguages(), body.getBodies(),
options, diagnostics, context);
}
}
defaultCase(constraint);
return eOperation;
} else {
if (addConstraint(eClassifier, name)
&& OPTION__PROCESS.equals(options
.get(OPTION__VALIDATION_DELEGATES))) {
ValueSpecification specification = constraint
.getSpecification();
if (specification instanceof OpaqueExpression) {
OpaqueExpression body = (OpaqueExpression) specification;
processConstraintBody(eClassifier, name,
body.getLanguages(), body.getBodies(),
options, diagnostics, context);
}
}
}
} else if (OPTION__REPORT.equals(options
.get(OPTION__INVARIANT_CONSTRAINTS)) && diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
INVARIANT_CONSTRAINT,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportInvariantConstraint_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(context,
eClassifier, name)),
new Object[]{eClassifier}));
}
}
return eClassifier;
}
protected void processAnnotationDetails(
final Map options,
final DiagnosticChain diagnostics,
final Map context) {
for (final Map.Entry entry : elementToEModelElementMap
.entrySet()) {
EModelElement eModelElement = entry.getValue();
if (eModelElement != null) {
Element element = entry.getKey();
for (EAnnotation eAnnotation : element.getEAnnotations()) {
if (!UML2_UML_PACKAGE_2_0_NS_URI.equals(eAnnotation
.getSource())) {
EMap details = eAnnotation
.getDetails();
if (!details.isEmpty()) {
if (OPTION__PROCESS.equals(options
.get(OPTION__ANNOTATION_DETAILS))) {
if (diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.INFO,
UMLValidator.DIAGNOSTIC_SOURCE,
ANNOTATION_DETAILS,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ProcessAnnotationDetails_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context,
eModelElement,
eAnnotation
.getSource())),
new Object[]{eModelElement}));
}
getEAnnotation(eModelElement,
eAnnotation.getSource(), true)
.getDetails().putAll(details.map());
} else if (OPTION__REPORT.equals(options
.get(OPTION__ANNOTATION_DETAILS))
&& diagnostics != null) {
diagnostics
.add(new BasicDiagnostic(
Diagnostic.WARNING,
UMLValidator.DIAGNOSTIC_SOURCE,
ANNOTATION_DETAILS,
UMLPlugin.INSTANCE
.getString(
"_UI_UML2EcoreConverter_ReportAnnotationDetails_diagnostic", //$NON-NLS-1$
getMessageSubstitutions(
context, eModelElement,
eAnnotation.getSource())),
new Object[]{eModelElement}));
}
}
}
}
}
}
}
protected void processOptions(Map options,
DiagnosticChain diagnostics, Map context) {
if (!OPTION__IGNORE.equals(options.get(OPTION__DERIVED_FEATURES))) {
processDerivedFeatures(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__UNION_PROPERTIES))) {
processUnionProperties(options, diagnostics, context);
}
if (!OPTION__IGNORE
.equals(options.get(OPTION__ECORE_TAGGED_VALUES))) {
processEcoreTaggedValues(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__REDEFINING_OPERATIONS))) {
processRedefiningOperations(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__REDEFINING_PROPERTIES))) {
processRedefiningProperties(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__SUBSETTING_PROPERTIES))) {
processSubsettingProperties(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__DUPLICATE_OPERATIONS))) {
processDuplicateOperations(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__DUPLICATE_OPERATION_INHERITANCE))) {
processDuplicateOperationInheritance(options, diagnostics,
context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__DUPLICATE_FEATURES))) {
processDuplicateFeatures(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options
.get(OPTION__DUPLICATE_FEATURE_INHERITANCE))) {
processDuplicateFeatureInheritance(options, diagnostics,
context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__SUPER_CLASS_ORDER))) {
processSuperClassOrder(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__ANNOTATION_DETAILS))) {
processAnnotationDetails(options, diagnostics, context);
}
if (!OPTION__IGNORE.equals(options.get(OPTION__OPERATION_BODIES))) {
processOperationBodies(options, diagnostics, context);
}
}
public Collection extends EObject> convert(
Collection extends EObject> eObjects,
Map options, DiagnosticChain diagnostics,
Map context) {
packages = EcoreUtil.getObjectsByType(eObjects,
UMLPackage.Literals.PACKAGE);
this.options = options;
this.diagnostics = diagnostics;
this.context = context;
for (org.eclipse.uml2.uml.Package package_ : packages) {
doSwitch(package_);
}
if (options != null) {
processOptions(options, diagnostics, context);
}
return getRootContainers(EcoreUtil. getObjectsByType(
elementToEModelElementMap.values(),
EcorePackage.Literals.EPACKAGE));
}
}
/**
* A converter that converts UML profiles to representative Ecore packages.
*/
public static class Profile2EPackageConverter
extends UML2EcoreConverter {
/**
* The option for handling cases where foreign profile definitions are
* encountered. Supported choices are OPTION__IGNORE
and
* OPTION__PROCESS
.
*/
public static final String OPTION__FOREIGN_DEFINITIONS = "FOREIGN_DEFINITIONS"; //$NON-NLS-1$
@Override
public Object casePackage(org.eclipse.uml2.uml.Package package_) {
if (packages.contains(package_.containingProfile())) {
return super.casePackage(package_);
} else {
EPackage ePackage = (EPackage) doSwitch(packages.iterator()
.next());
elementToEModelElementMap.put(package_, ePackage);
return ePackage;
}
}
@Override
public Object caseProfile(Profile profile) {
EPackage ePackage = (EPackage) casePackage(profile);
if (packages.contains(profile)) {
String profileName = ePackage.getName();
ePackage.setNsPrefix(profileName);
ePackage.setNsURI(profile.getURI());
if (isEmpty(ePackage.getNsURI())) {
org.eclipse.uml2.uml.Package nestingPackage = profile
.getNestingPackage();
String profileParentQualifiedName = nestingPackage == null
? EMPTY_STRING
: getQualifiedName(nestingPackage, "."); //$NON-NLS-1$
String version = String.valueOf(0);
EPackage definition = profile.getDefinition();
if (definition != null) {
try {
String nsURI = definition.getNsURI();
int lastIndex = nsURI.lastIndexOf('/');
if (lastIndex > 7) { // 2.0 format
version = String.valueOf(Integer.parseInt(nsURI
.substring(lastIndex + 1)) + 1);
} else { // 1.x format
String nsPrefix = definition.getNsPrefix();
version = String.valueOf(Integer
.parseInt(nsPrefix.substring(nsPrefix
.lastIndexOf('_') + 1)) + 1);
}
} catch (Exception e) {
// ignore
}
}
StringBuffer nsURI = new StringBuffer("http://"); //$NON-NLS-1$
nsURI.append(profileParentQualifiedName);
nsURI.append("/schemas/"); //$NON-NLS-1$
nsURI.append(profileName);
nsURI.append('/');
// ensure profiles with same name have different namespace
// URIs
nsURI.append(EcoreUtil.generateUUID());
nsURI.append('/');
nsURI.append(version);
ePackage.setNsURI(nsURI.toString());
}
}
return ePackage;
}
@Override
protected EClassifier getEType(Type type) {
EClassifier eType = getEClassifier(type);
if (eType == null
&& OPTION__PROCESS.equals(options
.get(OPTION__FOREIGN_DEFINITIONS))) {
Profile profile = (Profile) getOwningElement(type,
UMLPackage.Literals.PROFILE, true);
if (profile != null) {
eType = (EClassifier) profile.getDefinition(type);
if (eType != null) {
EList references = getEAnnotation(
(EPackage) doSwitch(packages.iterator().next()),
UML2_UML_PACKAGE_4_1_NS_URI, true).getReferences();
EPackage definition = profile.getDefinition();
if (!references.contains(definition)) {
references.add(definition);
}
}
}
}
return eType == null
? super.getEType(type)
: eType;
}
@Override
protected void processEcoreTaggedValues(EPackage ePackage,
Element element, Map options,
DiagnosticChain diagnostics, Map context) {
if (packages.contains(((org.eclipse.uml2.uml.Package) element)
.containingProfile())) {
super.processEcoreTaggedValues(ePackage, element, options,
diagnostics, context);
}
}
@Override
protected void setName(final ENamedElement eNamedElement,
NamedElement namedElement) {
new UMLSwitch() {
@Override
public Object caseClassifier(Classifier classifier) {
setName(eNamedElement, packages.contains(classifier
.getPackage().containingProfile())
? classifier.getName()
: getQualifiedName(classifier, "_"), true); //$NON-NLS-1$
return classifier;
}
@Override
public Object caseEnumerationLiteral(
EnumerationLiteral enumerationLiteral) {
setName(eNamedElement, enumerationLiteral.getName(), false);
return enumerationLiteral;
}
@Override
public Object caseNamedElement(NamedElement namedElement) {
setName(eNamedElement, namedElement.getName(), true);
return namedElement;
}
}.doSwitch(namedElement);
}
@Override
public Object doSwitch(EObject eObject) {
EObject eModelElement = (EObject) super.doSwitch(eObject);
String source = eModelElement instanceof EClassifier
? UML2_UML_PACKAGE_2_0_NS_URI
: (eModelElement instanceof EPackage && !packages
.contains(eObject))
? UML2_UML_PACKAGE_4_0_NS_URI
: null;
if (source != null) {
EList references = getEAnnotation(
(EModelElement) eModelElement, source, true)
.getReferences();
if (references.isEmpty()) {
references.add(eObject);
}
}
return eModelElement;
}
}
/**
* A converter that converts Ecore model elements to representative UML
* elements.
*/
public static class Ecore2UMLConverter
extends EcoreSwitch
implements Converter {
protected class ParameterSubstitutionMatcher
extends EClassMatcher {
protected ParameterSubstitutionMatcher(
TemplateBinding templateBinding) {
super(templateBinding);
}
@Override
public boolean matches(EObject otherEObject) {
EList