A syntax error when setting an attribute as a key, and this attribute is defined in a parent class #1026

Closed
ahmedvc opened this Issue Mar 30, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@ahmedvc
Contributor

ahmedvc commented Mar 30, 2017

1- Define an attribute, id for example, in a parent class.
2- Extends this parent class, and set this id attribute to be a key at the subclass as shown in the model below.
3- Generate the model and you will get a syntax error in the Java code.

The reason is that in the code generated, we access the field directly, which is private at the children levels. In order to overcome this issue, we should use the getter methods instead.

class Test{
id;
}

class Sub{
isA Test;
key {id}
}

@JoshuaMcManus

This comment has been minimized.

Show comment
Hide comment
@JoshuaMcManus

JoshuaMcManus Sep 19, 2017

The issue is in this file: equals.ump

The java produced is trying to access the variable instead of using a get method for inherited private variables. I have replaced the code generation to only use get() methods, but I believe that the issue has to do with how Keys are instantiated.

The umple code is looking to see if the Attribute is derived, and if it is, it should use the get function (but it doesn't). That leads me to believe that the isDerived setting for the Key Attribute is not set for inherited Attributes.

I am going to continue to look into this as I believe it would be better to add that to the Key when it is generated rather than force a function call on all keys (regardless if the key's variable is inherited or not)

The issue is in this file: equals.ump

The java produced is trying to access the variable instead of using a get method for inherited private variables. I have replaced the code generation to only use get() methods, but I believe that the issue has to do with how Keys are instantiated.

The umple code is looking to see if the Attribute is derived, and if it is, it should use the get function (but it doesn't). That leads me to believe that the isDerived setting for the Key Attribute is not set for inherited Attributes.

I am going to continue to look into this as I believe it would be better to add that to the Key when it is generated rather than force a function call on all keys (regardless if the key's variable is inherited or not)

JoshuaMcManus pushed a commit that referenced this issue Sep 19, 2017

Josh McManus
Fixes issue 1026
The equals() and hash() functions for keys within a class now exclusively call get methods
This prevents the issue of trying to access private inherited members directly while also keeping a consistent format

#1026

JoshuaMcManus pushed a commit that referenced this issue Sep 23, 2017

Josh McManus
Fixes issue 1026
The equals() and hash() functions for keys within a class now exclusively call get methods
This prevents the issue of trying to access private inherited members directly while also keeping a consistent format

#1026

TimLethbridge added a commit that referenced this issue Sep 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment