-
-
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
review: feature: add support for implicit / explicit modifiers (CtExtendedModifier) #1649
review: feature: add support for implicit / explicit modifiers (CtExtendedModifier) #1649
Conversation
I have a semantic problem here: technically a field declared in an interface like I did: int MY_CONSTANT = 42; does not have an explicit modifier. So should we put the information in modifier, and then we should be able to use WDYT @monperrus @pvojtechovsky ? |
What about this:
WDYT? |
I agree on the first one:
For the second one, it means to add isPublic, isStatic, isFinal, at least. |
it is acceptable for me too. Actually I have feeling like isPublic, isFinal, ... methods would be easier to implement and easier to user for clients too. Anyway both solutions are OK for me. WDYT? |
Easier to implement, no because they're already implemented in fact: the changes I made here should be applied to effective modifiers, and I should use the old behaviour to source modifiers. And for client, I'm mixed: it's easier to find a method called |
I would disagree. This would be against one of the core design principle of Spoon: it provides an abstract AST close to the semantic of the program, it does not simply / only reflect the source code. |
therefore we suggest to create new isPublic, isFinal, ..., (or getEffectiveModifiers) whose results would be always computed following semantic of the program. But please keep origin methods unchanged
|
we suggest to create new isPublic, isFinal, ..., whose results would
be always computed following semantic of the program
that's indeed a good idea, created #1657
But please keep original behavior unchanged
I'm not sure about this, There is a bug in the model itself for
modifiers of interface members. Could you elaborate on how fixing the
bug would break your code?
|
What bug? Do you mean that getModifiers() does not return PUBLIC on the field of interface? So then I like solution with getModifiers() and getSourceModifiers(), where new getSourceModifiers() would return modifiers which were really used in source code. WDYT? |
Excellent, we're on the same wavelength.
That's a good idea, added to #1657 |
Indeed. The javadoc of CtModifiable#getModifiers confirms that: |
In order to avoid breaking lot of tests, I decided to directly put I still had to make lot of changes:
Tell me if those design choices are OK. If so I continue by checking in the different |
I would say that we should not have setSourceModifiers in the interface. This notion of "source" make only sense fo JDTTreeBuilder and is meaningless to be set for clients. Actually, I really see here a risk of maintaining some state twice, which is really hard. Having the notion of implicitness on top of modifier kinds would be better and avoid to maintain state and consistency. |
no. It makes sense for pretty printing too. I think that clients want to have control on whether the "public" keyword is printed for interface field or not. I am one of these clients too. Same like they want to have control on extra new lines between statements. It is not maintaining of double state. We will keep one state - source modifiers - and compute the effective state from the context. |
We agree that we don't want to maintain twice the same state. What I don't like with "source" is that it is ambiguous: does it refer to input source or output source. I'd propose to call that "ExtendedModifier" What about this:
WDYT? |
I'm ok with that changes. Ok too @pvojtechovsky ? |
I like this solution too. But please do not implement it before we merge all the CtRole and CtScanner ... related PRs, because it would break them - heavy merging would be needed. |
09b6fce
to
87889ca
Compare
Thanks a lot @surli, we have a good solution here. For the code review, it's hard to see the new tests and the modified assertions, because the tests changed too much. Did you add the tests related to the bug and the JUnit regression? My only concern is about the new factory method |
That's because I renamed the old test file and reuse the old name for a new test case: the diff is badly displayed. I will put back the old name for the proper test file to have a better diff.
I created #1690 for the problem related to JUnit, as I wasn't completely sure it was related to this one. Once this one is merged, I will rebase #1690 to check if the test is passing or if it's another bug.
ok with that |
I will put back the old name for the proper test file to have a better diff.
super, thanks.
|
public class TestInterfaceWithoutSetup { | ||
@Test | ||
public void testModifierFromInterfaceFieldAndMethod() { | ||
// contract: methods defined in interface are all public and fields are all public and static |
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.
add assertions in isImplicit?
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.
add assertions on pretty-printing implicit modifiers?
… implicit and explicit modifierKind
…spoon into fix-bug-field-method-itf-modifier
@monperrus just fix the test and code. For me it's ready. |
Thanks. Could you:
|
Done. |
Detected changes by Revapi: 3. Old API: fr.inria.gforge.spoon:spoon-core:jar:6.0.0-20171107.084259-149 New API: fr.inria.gforge.spoon:spoon-core:jar:6.0.0-SNAPSHOT
|
thanks |
No description provided.