-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
feature: Detection of model change #1168
Comments
In order to change the model, a client must actively add, remove, and modify nodes. Consequently, clients should always know about changes and should be able to handle them accordingly, shouldn't they? |
I agree, therefore I think that |
I like this feature proposal. I have a slight preference for solution 2 which seems simpler than maintaining an Observer pattern. I'd say that the cost of one long per AST node is only a little overhead compared to the memory footprint of the whole AST, but to be measured. The tests of this feature will be quite easy by piggybacking on IntercessionTest, ParentTest, ReplacementTest and the like (the parametrized tests). |
several month ago @GerardPaligot implements a stack AST change (in this branch): https://github.com/GerardPaligot/spoon/tree/feat_stack |
Thanks for that link! It is very interesting idea. Yes, it is not what I want, but it shows challenges of this issue. The nearly each method of spoon model has to be changed to implement such feature. And it is visible that it means extra effort to maintain or to understand such enhanced model.
|
AspectJ is a quite complex library. Do you thing it is worth adding it to the Spoon eco system? |
I am trying what spoon comunity likes. ;-) I have an experience with AspectJ and I know, that it would be an solution. But in case of spoon, I preffer spoon based solution. Something like
I know that you are already doing that (but without step 3)... so it is probably nothing new for you. |
Is #1417 enough for your need? |
I have not checked your latest changes, but few days ago it was exactly what I need. I guess it will fit now too. And if not then it will be only minor changes needed, which can be done by another PR. |
Ok, perfect. In the last version we change the listener hierarchy. |
The model change detection is needed when:
Requirements
For example if CtClass X changes name, then it should be possible to detect that on X
For example if an statement is added/removed/modified in body of an method then it should be possible to detect that change on all parents: CtBlock, CtMethod, CtClass, CtPackage, CtModel.
For example if method is added/removed/modified in CtClass A, then it should be possible to detect that on all classes, which directly or indirectly inherits/extends class A.
Solutions
Let's collect here the ideas how to solve that.
Solution 1 - Change events
We might fire event (call an method) on each change. The clients which needs to detect the change would listen for these events (using registered listener).
Features
The clients is informed immediately when node is changed
Problems
it can become performance problem, when it is used heavily and each change would fire many events ...
it can need a lot of memory to keep collections of listeners
Solution 2 - CtElement#modelVersion attribute
We might have this code
Features
The clients have to ask whether element was changed. The client is not informed immediately.
We have one model version counter.
Problems
Each model element has one long attribute.
The text was updated successfully, but these errors were encountered: