-
-
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 MethodTyingContext#isOverriding #1292
Comments
the same applies to public |
I understand, you are right. Let's discuss first refactoring of
CtExecutable<?> scopeMethod;
List<CtTypeReference<?>> actualTypeArguments; which represents an method and it's actual type arguments... It is easy and fast operation to create But ClassTypingContext is more heavy (it's building needs much more operations), so it makes sense to design the API by way the ClassTypingContext can be reused. I1) So the idea is to move methods isOverriding, isSubSignature, isSameSignature and adaptMethod of MethodTypingContext somewhere else ... But where? I2) I guess one is clear: P1) The problem of remaining 3 methods is also with arguments ...
But does these arguments makes sense? I3) I would say that only this makes sense:
I4) And may be CtExecutable, might be reduced to P2) It is actually bad idea/nonsense to create MethodTypingContext using CtInvocation and then call method I5) MethodTypingContext created using CtInvocation and CtExecutableReference makes sense only for method I suggest following changes: C2) to move adaptMethod into ClassTypingContext C3) to implement new package protected AbstractSignatureMethodFilter. The most of the code of MethodTypingContext would be moved there. C4) to implement (refactor existing) OverriddenMethodFilter, by extending AbstractSignatureMethodFilter C5) to implement SubSignatureMethodFilter, by extending AbstractSignatureMethodFilter C6) to implement SameSignatureMethodFilter, by extending AbstractSignatureMethodFilter WDYT? |
Awesome.
Let's split the 6 changes C1..C6 into smaller PRs.
We start by C1+C3?
|
|
Thanks :-)
|
I tried to move method signature related methods from
new OverridenMethodFilter(anMethod1).matches(anMethod2) is not much better then new MethodTypingContext().setMethod(anMethod1).isOverriding(anMethod2) and brings only other problems, like it is hard to provide ClassTypingContext to the OverridenMethodFilter, etc... Also necessary change of class OverriddenMethodFilter implements Filter<CtMethod<?>> to class OverriddenMethodFilter implements Filter<CtExecutable<?>> is incompatible and produced many compilation errors in spoon tests and would cause compilation errors by spoon clients too. So it looks like classes like OverriddenMethodFilter are not good low level substitution for isOverriding, isSubSignature, isSameSignature of MethodTypingContext. What about another solution for isOverriding, isSubSignature, isSameSignature? What about new class MethodContext in same package like MethodTypingContext?
And again (same like MethodTypingContext), this MethodContext would be technical/internal class, which is powerful enough to efficiently solve needs of spoon API methods, but is not expected to be DIRECTLY used by normal spoon clients - so it does not have to be 100% intuitive. Another solution would be to move all that code into CtExecutableImpl. But then I would need an instance of ClassTypingContext directly in CtTypeImpl to keep good performance - to be able reuse once created ClassTypingContext... but simple solution would eat much more memory ... so it would need a pool of ClassTypingContexts ... and it would be really not KISS. WDYT? |
What about moving these 3 methods into ClassTypingContext? The contract would be: Does method1 overides method2 in context of class X?
|
What about moving these 3 methods into ClassTypingContext? The contract would be: Does method1
overides method2 in context of class X?
The method names on ClassTypingContext would be
* isOverriding(CtExecutable, CtExecutable)
* isSameSignature(CtExecutable, CtExecutable)
* isSubSignature(CtExecutable, CtExecutable)
WDYT?
It looks like a good idea.
|
And again (same like MethodTypingContext), this MethodContext would be technical/internal class,
which is powerful enough to efficiently solve needs of spoon API methods, but is not expected to
be DIRECTLY used by normal spoon clients - so it does not have to be 100% intuitive.
IMHO
- Internal classes are important for minimizing the API surface, so it's always a good idea to have them
- However, I'd say that good design (intuitive, testable) is as important for internal classes and
API classes.
|
What about rename of If not, then what do you suggest? |
What about |
Personally I do not like the idea of adding extra useless parameter x1, which just decreases readability, performance, understanding ... Your suggestion is based on wrong understanding of contract of ClassTypingContext. |
done per 0743b5a which fixes most of the problems. since neither Pavel nor me can find a good solution to isSubtypeOf, I suggest to close this one for the moment and move on. |
public method
MethodTyingContext#isOverriding
is really hard to understand. Intuitively, a context cannot override a method (which is what Context#isOverriding suggests) and one would expect a second parameterThe text was updated successfully, but these errors were encountered: