Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320241

Summary: navigable associations aren't deleted properly
Product: [Modeling] MDT.UML2 Reporter: Christian Waniek <chris.waniek>
Component: CoreAssignee: UML2 Inbox <mdt-uml2-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P3 CC: Kenn.Hussey
Version: unspecifiedKeywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 320244    

Description Christian Waniek CLA 2010-07-19 07:19:29 EDT
Build Identifier: 

If you create a navigable association between two classes, the source class holds an ownedAttribute, pointing to the target class of the association. So far, everything is correct (in my opinion).
But when you delete the association, this ownedAttribute remains in its class. From an EMF-view this is correct, because the metaclass Association has no controll over features of the metaclass Class. But from an UML-view this is a bug.

As far as I see the source for this bug is, that an association is created via the Type.createAssociation(...). This calls some custom code which writes the ownedAttribute to the source class. But theres is no equivalent to delete an association, which checks whether one of the associations memeberEnds has an ownedAttribute which refers to this association.

I found this bug while fixing some bugs for the UML2 Tools.

Reproducible: Always

Steps to Reproduce:
To reproduce, use the following code-snippet and look at the created file. After this uncomment the commented line, execute again and look at the created uml-file. You'll see, that 'class ONE' still holds an ownedAttribute, which should have been deleted by deleting the association.

public static void main(String[] args) {
		// TODO Auto-generated method stub
		Package p = UMLFactory.eINSTANCE.createPackage();
		p.setName("myPackage");

		Class c1 = UMLFactory.eINSTANCE.createClass();
		c1.setPackage(p);
		c1.setName("class ONE");
		Class c2 = UMLFactory.eINSTANCE.createClass();
		c2.setPackage(p);
		c2.setName("class TWO");

		Association a = c1.createAssociation(true,
				AggregationKind.NONE_LITERAL, "end1", 0, 1, c1, false,
				AggregationKind.NONE_LITERAL, "end2", 0, 1);
		a.setPackage(p);

		// a.destroy();

		ResourceSet resourceSet = new ResourceSetImpl();

		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
				.put("uml", new XMLResourceFactoryImpl());

		URI fileURI = URI
				.createFileURI(new File("myUML.uml").getAbsolutePath());
		Resource resource = resourceSet.createResource(fileURI);

		resource.getContents().add(p);

		try {
			resource.save(null);
		} catch (IOException e) {
			System.out.println("IOException while saving model-instance.");
			e.printStackTrace();
		}
	}
Comment 1 Christian Waniek CLA 2010-07-19 07:46:56 EDT
#101607 might also be influenced by this (or vice versa)
Comment 2 Christian Waniek CLA 2010-07-19 07:49:23 EDT
to have the link cliackable: bug #101607
Comment 3 Kenn Hussey CLA 2010-07-19 09:09:21 EDT
This isn't so much a bug as it is missing functionality, i.e., the convenience method for creating an association doesn't have an analog to delete one.
Comment 4 Christian Waniek CLA 2010-07-28 08:08:21 EDT
Whether bug or not, I think this is something that should be fixed.
IMHO it doesn't have to be the job of the user to find and delete Properties which are part of an Association.
Comment 5 Christian Waniek CLA 2011-03-15 12:42:24 EDT
Although I'm still of another opinion (I think when there's a convenience method, Which works one way, there sould be another one, working the other way), I'll resolve this issue, because I can live with the status quo.
Comment 6 Kenn Hussey CLA 2011-05-31 10:37:24 EDT
Closing for Indigo release.