| /******************************************************************************* |
| * Copyright (c) 2013 Obeo. |
| * 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: |
| * Obeo - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.emf.compare.uml2.internal.postprocessor.extension.clazz; |
| |
| import static com.google.common.base.Predicates.instanceOf; |
| |
| import com.google.common.base.Predicate; |
| import com.google.common.collect.Collections2; |
| import com.google.common.collect.Iterables; |
| |
| import java.util.LinkedHashSet; |
| import java.util.Set; |
| |
| import org.eclipse.emf.compare.Diff; |
| import org.eclipse.emf.compare.uml2.internal.AssociationChange; |
| import org.eclipse.emf.compare.uml2.internal.UMLCompareFactory; |
| import org.eclipse.emf.compare.uml2.internal.UMLDiff; |
| import org.eclipse.emf.compare.uml2.internal.postprocessor.AbstractUMLChangeFactory; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.util.Switch; |
| import org.eclipse.uml2.uml.Association; |
| import org.eclipse.uml2.uml.Classifier; |
| import org.eclipse.uml2.uml.Property; |
| |
| /** |
| * Factory for Association changes. |
| * |
| * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a> |
| */ |
| public class UMLAssociationChangeFactory extends AbstractUMLChangeFactory { |
| |
| /** |
| * Discriminants getter for the Association change. |
| * |
| * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a> |
| */ |
| private class AssociationDiscriminantsGetter extends DiscriminantsGetter { |
| |
| /** |
| * {@inheritDoc}<br> |
| * Discriminants are the association and properties outside of the association. |
| * |
| * @see org.eclipse.uml2.uml.util.UMLSwitch#caseAssociation(org.eclipse.uml2.uml.Association) |
| */ |
| @Override |
| public Set<EObject> caseAssociation(final Association object) { |
| Set<EObject> result = new LinkedHashSet<EObject>(); |
| result.add(object); |
| result.addAll(Collections2.filter(object.getMemberEnds(), new Predicate<Property>() { |
| public boolean apply(Property property) { |
| return property.eContainer() != object && property.getAssociation() == object; |
| } |
| })); |
| return result; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.uml2.uml.util.UMLSwitch#caseProperty(org.eclipse.uml2.uml.Property) |
| */ |
| @Override |
| public Set<EObject> caseProperty(Property object) { |
| Set<EObject> result = new LinkedHashSet<EObject>(); |
| if (object.eContainer() instanceof Association) { |
| result.addAll(caseAssociation((Association)object.eContainer())); |
| } else if (object.getAssociation() != null) { |
| result.addAll(caseAssociation(object.getAssociation())); |
| } |
| return result; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.uml2.uml.util.UMLSwitch#caseClassifier(org.eclipse.uml2.uml.Classifier) |
| */ |
| @Override |
| public Set<EObject> caseClassifier(Classifier object) { |
| Set<EObject> result = new LinkedHashSet<EObject>(); |
| for (Association association : object.getAssociations()) { |
| caseAssociation(association); |
| } |
| return result; |
| } |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#getExtensionKind() |
| */ |
| @Override |
| public Class<? extends UMLDiff> getExtensionKind() { |
| return AssociationChange.class; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#createExtension() |
| */ |
| @Override |
| public UMLDiff createExtension() { |
| return UMLCompareFactory.eINSTANCE.createAssociationChange(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.compare.uml2.internal.postprocessor.AbstractUMLChangeFactory#getDiscriminant(org.eclipse.emf.compare.Diff) |
| */ |
| @Override |
| protected EObject getDiscriminant(Diff input) { |
| return Iterables.find(getDiscriminants(input), instanceOf(Association.class), null); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.compare.uml2.internal.postprocessor.AbstractUMLChangeFactory#getDiscriminantsGetter() |
| */ |
| @Override |
| protected Switch<Set<EObject>> getDiscriminantsGetter() { |
| return new AssociationDiscriminantsGetter(); |
| } |
| |
| } |