New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bringing Umple's APIs to the metamodel and runtime #962
Comments
Another concern might be the size of the model at the runtime. I think this can be dealt later with some optimization. It might not be even an issue with the current advance in technology. |
Sounds interesting, but I think explaining what you mean by example would be important. Give an example trivial umple model with two classes, an association and an attribute, and describe the effect of what you would like to see |
This is in the direction relationship with issue #462 |
Consider the following example,
Umple generates API for the attribute
This example points out that the client of I believe this a great step for reducing dependency on code generators and have more concrete metamodel. If Umple wants one day in the future to have its own binary code, so there won't be any issue regarding the APIs. |
@vahdat-ab I have started trying to orient myself with some of the compiler code, and I want to make sure I am on the right track. I found the method analyzeAttribute in UmpleInternalParser_CodeClass.ump. Is this the correct point to identify attributes to add API methods for? |
@katcavers yes. this is the place Analyzer analyzes the abstract syntax tree |
@vahdat-ab I remember saying that we wanted the generation of the API methods to remain in the generators. So, I have added an additional type, fAutoAPI, to the Source enum of the Method class and set the get method's source to this. Then, I check in the Java generator class_MethodDeclaration.ump and if the source of the method is fAutoAPI I skip generating this method. Is this the right approach? |
To me, it looks ok. I wonder if you detected for what reason fAuto is used? I thin it's there for this purpose. |
let's go in the way you describe. If we want to do any modification later it will be at the code generation level. You just make sure you do all required checkings at then modeling level. |
Sounds good.I think eventually implementing the auto-generated methods to be generated by the generators makes sense. This would just be a huge change to the code generation side, so it is easier to do this step first. |
I am having an issue with my changes and the Ruby generator. Many of the test cases are failing because empty lines are being inserted. I believe it may be due to the fact that we skip over autogenerated API methods, but somehow a new line is still inserted. For example, I have attached two files; the expected vs actual Ruby code. |
@vahdat-ab I also have two more questions. First, in our initial discussion for this project, we talked about constructors. Would you be able to expand again on whether I should be creating/modifying constructors when an attribute is encountered in the model? |
@ahmedvc ----> The issue Resolved
I wonder if you can comment on this? How can we remove those empty lines generated because of passing some conditions? |
yes. This is a critical issue. You should create a constructor and feed its parameters.
The method should have a parameter such as an attribute or association and then remove related auto-generated APIs. You can also implement a method that removes all of them. This is going to be easy because there is a property that specifies which methods are auto-generated. |
I think I actually just figured out why it's happening. Before, there were no methods in the model for this specific case. But now there are, as I am adding get and set API methods at the model level. In the generator, a check is done on the class being processed is done; if the class has methods, it then iterates through all the methods and at the end appends to the string builder two new lines. For this case, the if statement used to prove false, but now it is true because of the API methods I add at the model level. So even though no code is generated for these methods, those two new lines are added. |
Thanks Vahdat, I will continue working on these. |
@katcavers great. |
@vahdat-ab For the methods to remove autogenerated methods, I believe it makes sense to add these methods to the UmpleClassifier class in Umple.ump. Do you agree, or is there some other place you had in mind? Thanks! |
why do yo want to have it in |
Ah, actually, yes your way does make more sense. I think I was thinking to have it at the higher level of the hierarchy, but UmpleClass is the only one to have attributes, so adding it there is the better way to go. |
@vahdat-ab Hi Vahdat! I have submitted now to my PR the functionality for constructors. I am now going to be moving on to Associations. There are a lot more autogenerated API methods for associations, so I am thinking I should start first with simple get and set again? |
OK. Thanks. do it as you wish :-) |
For associations we have get, set and add (among many). I wouldn't add set unless I also added add, otherwise it will be a bit off-balance; set is used for '1' ended associations and add for '*'. |
@vahdat-ab Hi Vahdat, I am currently trying to make tests for the autogenerated association methods. After our meeting last Friday, I went and looked at all the tests there are for the generators. This really opened my eyes to how many cases there are. I am looking at the tests in cruise.umple.test.implementaion (ManyToManySubclassTest, all the way down to UnidirectionalOptionalOneTest). It's a huge number of tests! Up until now, my approach has been to parse an umple file, get the UmpleClass object, and assert that it has the correct methods (an example of which you could find here: bf008d7). This approach was fine for attributes, because the number of cases was much smaller. I could still use this approach for associations, but there are so many more cases/tests, and so many more methods that I have to check for. Do you have any suggestions/ideas of what I could do to make testing more efficient? I want to write tests first, as I think this will make the implementation go much faster. Thanks! |
Yes, as I mentioned in the meeting last Friday, the API generated for associations is considerating, and the logic for determine what will be generated is non-trivial (there are I think about 14 cominations of multiplicity, but there are also other factors that change the API). This took a whole PhD (Andrew Forward) and has been evolved since then to add features and fix bugs. I think that doing this manually will be a challenge. The logic for the set of methods to be generated is already encapsulated in the generator; you would either need to reverse engineer this and hence create a module that somehow duplicates it, although the module will not be as complex as the generators since you do not care about the contents of the bodies. In the long run it will be necessary to constantly verify that whatever is generated matches the signatures found in the model. Otherwise changes may result in mismatches creeping in. We can take advantage of that by right now starting wtth that verifier: Instrument the Java generator to emit a message (only in a debugging mode) when it generates a method that does not have a corresponding method in the model, and vice-versa. i.e. it checks methods off lists are they are generated and then spits out the difference. Next you start adding the methods to the model and watch the above list of messages about mismatches getting smaller and smaller. You won't be able to be perfect in the week or so you have left, but you can get part way, and leave it for another student to finish. |
@TimLethbridge Thanks for the clarification Tim. I will start doing as you have suggested. Do you know of anywhere in the Umple project where something similar, in terms of debugging trace statements, has been done that I could take a look at? |
@vahdat-ab After looking more into the Trace capabilities (I looked at both the code and user manual), I do not think I will be able to use it. While many of the ideas are shared between Trace elements and what I need, I think that I would be using the Umple Trace in a way it was not necessarily intended, and would have to make changes to it that would not be in line with its purpose. I am going to go forward with creating my own implementation of debug statements to verify autogenerated methods. |
Ok. That's fine.
|
@vahdat-ab Hi Vahdat, I have finished putting in my debug statements and am now setting up tests for the autogenerated associations. However, I noticed there are a large number of files in the UmpleTL folder of UmpleToJava which do not seem to be used. For example, association_SetOneToOptionalN.ump. I did a search for their code in the project in Eclipse (including generated code), and nothing came up. I want to make sure that I am not missing anything as I will be relying somewhat on these debug statements. Are these just old files that were once used, and just haven't been deleted? Or are they being used somewhere other than the generator? |
@katcavers I'm not aware of them. |
Hmmm. I don't know. You say 'a large number'. If it was a few I would think they might have been left behind. But I would be rather surprised if it is a large number. One strategy would be to delete them temporarily and do a full build and see what happens! remember that these files are compiled separately; then the generated code is transferred from their directory to the general umple generated code directory. |
@TimLethbridge @vahdat-ab After your comments, I realized last night that I had missed files used in JavaSpecGenerator - I went and added the debug statements to the files there, and the number of unused files is a small one now. Oops! And thanks! :) |
@TimLethbridge @vahdat-ab Documentation has been added: https://github.com/umple/umple/wiki/Adding-Autogenerated-Methods-at-the-Model-Level I am in the middle of exams, so I will keep adding to it as I have time and think of what else I should write. |
NOTE: Read above wiki page. All work for associations has been done in branch issue962. |
I will attempt to replace the previous testing method that was implemented with a second one, both are explained on the wiki page. |
Progress on #962 Adds some associations autogenerated methods to the model and adds testing
Progress on #962 Adds autogenerated methods to the model for associations, attributes and state machines
Umple generates a hand full of useful APIs for attributes and association. Currently, those methods are generated by UmpleTL. It means they are not available in the runtime model of Umple systems. This limits us regarding many analysis we can do at the runtime and causes to have duplication in UmpleTL's template files. Furthermore, This will be a great base for the future extensions such as using Language Server Protocol.
One of the concerns is how to deal with the executable body of these methods. I think we can create those APIs (their signature at the modeling level) and then tag them as auto-generated. Then code generated will know how to deal with that.
This idea can be extended in an advance form to state machines.
More info about those APIs can be found here
The text was updated successfully, but these errors were encountered: