Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » isAttribute always returns false
isAttribute always returns false [message #1052848] Tue, 30 April 2013 17:15 Go to next message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
Hi,

Shouldn't the output of isAttribute be "true" on the following code, or is it that I don't understand the meaning of isAttribute. I'm using UML 4.0.2. Thanks!

Property p = UMLFactory.eINSTANCE.createProperty();
Class c = UMLFactory.eINSTANCE.createClass();

c.getOwnedAttributes().add(p);
System.out.println(c.getAttributes().contains(p)); // true
System.out.println(p.isAttribute(p)); // false

--
Hector
Re: isAttribute always returns false [message #1052935 is a reply to message #1052848] Wed, 01 May 2013 13:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The manual code for the OCL: result = Classifier.allInstances->exists(c
| c.attribute->includes(p))
is:

public static boolean isAttribute(Property property, Property p) {

for (EStructuralFeature.Setting nonNavigableInverseReference :
getNonNavigableInverseReferences(p)) {
EObject eObject = nonNavigableInverseReference.getEObject();

if (eObject instanceof Classifier
&& ((Classifier) eObject).getAttributes().contains(p)) {

return true;
}
}

return false;
}

expects p to be well-formed in order to use non-navigable navigation
rather than a brute force allInstances. You have omitted the
Property.type definitions, so the navigation fails. (I'm unclear how
well navigable associations will work; you might want to nraise a Bugzilla.)

Regards

Ed Willink



On 30/04/2013 18:15, Hector Chavez wrote:
> Hi,
>
> Shouldn't the output of isAttribute be "true" on the following code,
> or is it that I don't understand the meaning of isAttribute. I'm using
> UML 4.0.2. Thanks!
>
> Property p = UMLFactory.eINSTANCE.createProperty();
> Class c = UMLFactory.eINSTANCE.createClass();
>
> c.getOwnedAttributes().add(p);
> System.out.println(c.getAttributes().contains(p)); // true
> System.out.println(p.isAttribute(p)); // false
> --
> Hector
Re: isAttribute always returns false [message #1052960 is a reply to message #1052935] Wed, 01 May 2013 15:19 Go to previous messageGo to next message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
Thanks Ed,

I modified the example to have well formed properties and I still get the same result. Do you know of any case of a non-navigable attribute that would make isAttribute return true?

...

Class car = rootPackage.createOwnedClass("Car", false);
Class gas = rootPackage.createOwnedClass("Gas", false);

PrimitiveType type = rootPackage.createOwnedPrimitiveType("String");
Property name = car.createOwnedAttribute("name", type, 1, 1);

System.out.println(name.isAttribute(name)); // false

Association assoc = car.createAssociation(true,
			AggregationKind.NONE_LITERAL, "needs", 0, 1, gas, false,
			AggregationKind.NONE_LITERAL, "car", 0, 1);

Property car_needs = assoc.getMemberEnd("needs", gas);
Property gas_car = assoc.getMemberEnd("car", car);

System.out.println(car_needs.isAttribute(car_needs)); //false
System.out.println(gas_car.isAttribute(gas_car)); //false


Thanks.
Re: isAttribute always returns false [message #1052962 is a reply to message #1052960] Wed, 01 May 2013 15:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

My comment on navigability was just based on reading the code without
following up the specifications of the called routines.

It looks as if the assumption was that no one would call isAttribute for
navigable attributes since that would be redundant. This seems wrong
with respect to UML 2.5; hence my suggestion to raise a Bugzilla.

Regards

Ed Willink


On 01/05/2013 16:19, Hector Chavez wrote:
> Thanks Ed,
>
> I modified the example to have well formed properties and I still get
> the same result. Do you know of any case of a non-navigable attribute
> that would make isAttribute return true?
>
> ..
>
> Class car = rootPackage.createOwnedClass("Car", false);
> Class gas = rootPackage.createOwnedClass("Gas", false);
>
> PrimitiveType type = rootPackage.createOwnedPrimitiveType("String");
> Property name = car.createOwnedAttribute("name", type, 1, 1);
>
> System.out.println(name.isAttribute(name)); // false
>
> Association assoc = car.createAssociation(true,
> AggregationKind.NONE_LITERAL, "needs", 0, 1, gas, false,
> AggregationKind.NONE_LITERAL, "car", 0, 1);
>
> Property car_needs = assoc.getMemberEnd("needs", gas);
> Property gas_car = assoc.getMemberEnd("car", car);
>
> System.out.println(car_needs.isAttribute(car_needs)); //false
> System.out.println(gas_car.isAttribute(gas_car)); //false
>
>
> Thanks.
Re: isAttribute always returns false [message #1053015 is a reply to message #1052962] Wed, 01 May 2013 23:26 Go to previous message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
Thanks, I just submitted the bug report.
Previous Topic:creating association in uml profiles
Next Topic:Specifying an action of a transition
Goto Forum:
  


Current Time: Sat Apr 20 04:04:55 GMT 2024

Powered by FUDForum. Page generated in 0.03545 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top