-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
refactor(role): add and refactor CtRole annotations of model #1606
Conversation
51829f0
to
366ac74
Compare
Some notest about changes:
See #1600
Suggested by Martin in #1582
Suggested by Martin in #1582
Suggested by Martin in #1582
Methods: CtClass#getAnonymousExecutables(), etc. were not marked with any role, because the only matching role was EXECUTABLE, which was already used for CtType@getMethods(), etc.
See #1605 - it is just small fix of a wrong use of role
Suggested by Martin in #1582 |
@@ -44,6 +45,7 @@ | |||
* Derived from {@link #getTypeMembers()} | |||
*/ | |||
@DerivedProperty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove DerivedProperty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAnonymousExecutables is not a Derived Property. We should remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what about CtClass#getConstructor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getConstructor(CtTypeReference<?>... parameterTypes)
is not a real getter for me.
It is more a "finder".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the specification @interface DerivedProperty, getConstructors()
is a derived property because the content is already scanned by getTypeMembers()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me in this case, getTypeMembers() is DerivedProperty and getConstructors, getExecutables, ... are not.
it is just an implementation decision to use getTypeMembers instead of the other methods.
Constructors, methods, ... are the real properties of the model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructors, methods, ... are the real properties of the model
I agree, but the order is defined on the level of typeMember ... so typeMember is real property too.
We need something in between ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should first try to make a conclusion of the purpose of the CtRole and definition of contract behind the CtRole. I guess each of us understands it different ;-p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So after discussion below it is probably clear that @DerivedProperty should stay there. So this PR is correct at this place.
366ac74
to
a98f199
Compare
We should add a test to check that elements are never scanned twice by two different getters
(whatever they are).
And then definition of a CoreProperty is that it is called directly by CtScanner (as opposed to a
derived property)
|
At least three usages (which make roles so interesting): the model intercession listener (by @tdurieux), the path queries, the get/setValueByRole (your current work) |
I think the main conflict is here
How to map roles on that? |
I would say on the leafs only.
But roles and DerivedProperty are orthogonal, right?
…On 10/16/17 4:09 PM, Pavel Vojtechovsky wrote:
I think the main conflict is here
Type has typeMembers.
* typeMembers
o field
o nested type
o executable
+ constructor
+ method
+ annonymousExectuable
How to map roles on that?
A) to role for each bullet
B) to have role for top |typeMember| only
C) to have role for leafs only
D) ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1606 (comment)>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAxDUtRlD6NI2m3DJ_Yy5VYu1ZfqFyq9ks5ss2OGgaJpZM4P53b->.
|
I am sorry, but I am not well trained in math/graph terms - and understanding wiki explanation of this term would need hours for me. I guess we do not have to make any relation between roles and DerivedProperty. DerivedProperty is well defined and is used for checking of scanner. Let's keep it as it is. And for roles we can do it as we want. For me it is no problem if roles will overlap, so I can live with all these roles: TYPE_MEMBER, EXECUTABLE, FIELD, METHOD, ... depending on role it will get/set appropritate values - no problem that it overlaps. |
This test already exist. See MainTest#checkModelIsTree. If any element would be visited twice then this test would fail. |
Here is current state of Type - CtRole assignments I suggest to create new role for these:
because these roles are already used with different meaning. I suggest to replace CtRole.THROWN by CtRole.EXPRESSION
because we do not need special role for that. It will be then compatible with many other commands like:
@monperrus suggested to change CtExecutableReference CtRole.PARAMETER to CtExecutableReference CtRole.PARAMETER_REF (or .PARAMETER_TYPE)
note that CtRole.TYPE_PARAMETER has similar contract
should CtActualTypeContainer CtRole.TYPE_PARAMETER be replaced too by some new role? |
I agree, I would remove the PropertyGetter on the first one (code snippets are more clever hacks than AST elements). For the second one, what role do you suggest? |
CtForEach CtRole.VARIABLE might be replaced to
|
Do you mean only getter or setter too? I guess setter too. Then there is a problem ... this will influence setter implementation on class CtCodeSnippetExpressionImpl/CtCodeSnippetStatementImpl {
...
public <C extends CtCodeSnippet> C setValue(String value) {
getFactory().getEnvironment().getModelChangeListener().onObjectUpdate(this, EXPRESSION, value, this.value);
this.value = value;
return (C) this;
} @tdurieux is it correct that model listeners will be NOT notified about changes on code snippets? May be we should keep have some new role name (instead of removing getter/setter) |
a98f199
to
46b1283
Compare
I like CtRole.FOREACH_VARIABLE
|
Revapi Analysis resultsOld API: fr.inria.gforge.spoon:spoon-core:jar:6.0.0-20171017.190052-88 New API: fr.inria.gforge.spoon:spoon-core:jar:6.0.0-SNAPSHOT Detected changes: 1. Change 1
|
Here is current report of type to role mappings - concept.txt |
@monperrus what are next steps here? Will you merge it as it is and will we add other fixes in next PR? What about other suggestions here? Ignore them for now? |
It's indeed ready to be merged. I will merge it later today or tomorrow. I believe that roles will be a super useful new feature, and this ongoing hot work is really good, thank you! |
See individual commits of this PR. Each of them might be individual PR, but they often depends on each other, so their order is relevant.
I suggest:
This PR contains commits of #1600 and #1605, because other commits depends on them.