-
-
Notifications
You must be signed in to change notification settings - Fork 357
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: MethodTypingContext#adaptMethod #1288
Conversation
0fdadba
to
2f32060
Compare
CtClass<?> ctClassWeddingLunch = factory.Class().get(WeddingLunch.class); | ||
CtMethod<?> trWeddingLunch_eatMe = ctClassWeddingLunch.filterChildren(new NameFilter<>("eatMe")).first(); | ||
|
||
MethodTypingContext methodSTH = new MethodTypingContext().setClassTypingContext(new ClassTypingContext(ctClassWeddingLunch)); |
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.
what does this line mean? I thought a MethodTypingContext would be always with respect to a specific method
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.
yes, it is correct. But there are situations when MethodTypingContext is needed for method, which does not exist.
In the example above (first comment of this PR), it is the case when I need MethodTypingContext for method void method()' in adaption scope of class
B`
2f32060
to
72e7735
Compare
I've updated the tests. The core contract and test of adaptMethod is fine to me. After analysis, I see one major and one minor problem here. The major one is that the design and usage of |
See #1292 |
I am implementing the algorithm, which searches for all methods, which has to be modified when changing method signature (e.g. remove method parameter). This algorithm needs to be able to search in all super types of sub types of declaring type of target methods, for methods with equal
sub signature
... yes, it is tricky sentence ... so see Example:If
A#method()
has to be refactored, then that algorithm has to foundC#method()
too. But note thatC#method()
, does not overridesA#method()
, so it is not enough to use existing overriding filter.The algorithm first needs to detect that
IB#method()
is overridden byB#method()
(which does not exists, but is inherited fromA
).We can do that by new feature implemented in this PR like this:
or shortly like this:
The example above is simplified. There are no generic parameters in method, so it might be solved different way. But with generic parameters and longer type hierarchies, the adapting of method parameters is necessary, because
A#method
andC#method
might have different parameter types, but they can be still related, thanks to some generic method(s) in between ...Note: review only second commit. The first commit comes from another PR. I will rebase after first commit is merged.