-
-
Notifications
You must be signed in to change notification settings - Fork 346
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 sub inheritance hierarchy function #1290
review: feature sub inheritance hierarchy function #1290
Conversation
839929f
to
354298f
Compare
It seems that this function takes a type as input, and optionally a package. What about designing it the other way (
The tests would be clearer this way. |
then it does not fit to my needs. But I agree that clients will think same like you, so what about:
|
so what about:
1. to move code of |SubInheritanceHierarchyFunction| to different (more internal) package, to
rename it to something like |SubInheritanceHiearchyResolver| and to not inherit from
CtConsumableFunction ... because it's contract does not fits to contract of other mapping
functions.
2. to create new simple mapping function, which will behave like you suggested and which will
internally use new |SubInheritanceHiearchyResolver|
perfect!
…--Martin
|
364e2cf
to
8fb7fd9
Compare
Move and rename done. Seems to be OK from my point of view. Please fix my documentation/English ;-) Thanks! |
Let's fix #1292 first. This PR depends on it, so refactoring will be easier without it. |
8fb7fd9
to
5b56ace
Compare
rebase? |
5b56ace
to
73b43f3
Compare
* So repeated call with same input package returns nothing. | ||
* Create and use new instance of {@link SubInheritanceHierarchyResolver} if you need to scan the subtype hierarchy again. | ||
*/ | ||
public class SubInheritanceHierarchyResolver { |
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.
OK for the responsibility of this class. On the design, I'd suggest a stateless one (stateless is often better).
What about the following:
- REMOVE field targetSuperTypes, constructor SubInheritanceHierarchyResolver(CtTypeInformation), method addSuperType
- ADD a new parameter to method forEachSubTypeInPackage which represents a collection of CtTypeInformation
WDYT?
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.
interesting idea!
... but my new solution is kind of compromise ;-), because I need to call forEachSubTypeInPackage several times using same state, to search for next set of sub types after new super type(s) is/are added.
Anyway this solution is more understandable then origin one, because now it is clear whether client starts a new search or continues searching using existing state.
* if true then we have to check if type is a subtype of superClass or superInterfaces too | ||
* if false then it is enough to search in superClass hierarchy only (faster) | ||
*/ | ||
boolean hasSuperInterface = false; |
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.
private?
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.
thanks! I forgot to mark it private.
62aab98
to
2824c03
Compare
Now the SubInheritanceHierarchyFunction is stateless. Is such solution acceptable? |
Thanks Pavel for the changes.
Here are a couple of changes to reduce the API surface and increase encapsulation by putting put a
lot of things private. It still compiles and the tests run.
Are you OK with this?
Other question: most boolean flags in SubInheritanceHierarchyFunction and
SubInheritanceHierarchyResolver are not tested.
Do you need them all?
|
These private methods make implementation of #1291 much harder and less efficient (worse performance). I need these methods there, so I do not like the idea to make them private. Please have a look at algorithm of that PR, so it is understandable what I am speaking about. |
I do not need them now/yet, but they copy the pattern of other mapping functions. For example
|
Hi Pavel, On the private methods, I've privatized 4 of them. Do you need them all? Which ones do you really need? On the boolean flags, I'm not against them, I only much prefer specified/tested code. AFAIU, most of those flags are untested. |
Hi Martin, On the private methods, they were an implementation of the contract: to be able to search for other (not yet found) sub types of newly added super types. Note that java class hierarchies often share their supertypes so it makes sense to keep the results of previous sub type search and to search only for new sub types. Without these methods (which you made private) the algorithm has to scan whole model for sub types again and will return before found sub types (duplicities), so
May be the algorithm I am describing is specific for #1291 so the private methods might be switched to package protected ... but I do not vote for this solution. Think about contract of SubInheritanceHierarchyFunction and SubInheritanceHiearchyResolver. What is the difference between them after you make these methods private? Nearly nothing. So if I would agree with private methods, then we might simplify it even more and keep only SubInheritanceHierarchyFunction ... But then I miss main contract of SubInheritanceHiearchyResolver - to be able to search for extended set of sub types after new super type(s) is/are added. and I would be not able to implement #1291 efficiently |
sure, I will add tests after we found a compromize between size of API and contracts of SubInheritanceHiearchyResolver. |
I see. We have again a baby PR problem here because we have three things:
- SubInheritanceHierarchyFunction
- SubInheritanceHierarchyResolver and its core responsibility and contracts
- the various boolean options
As we're now used to, let's split the problem so as to facilitate convergence and merge.
I propose to start with SubInheritanceHierarchyResolver (without any other class). Thanks to your
explanation, I start to better understand what you mean, the responsibility and contract you need
I'll isolate SubInheritanceHierarchyResolver in one separate PR, and try to test it to see whether
it corresponds to your plan.
|
31ff93f
to
2824c03
Compare
removed my last commit |
2824c03
to
2d875aa
Compare
Rebase done but, build server has problem:
|
I just had the same issue, it should be ok now. You can do a minor change or a an empty commit to trigger the CI. |
thanks! |
The
SubInheritanceHierarchyFunction
is created and configured with one or more types. This mapping function returns all sub types of configured types, which are found in packages, which are input for this mapping function.This mapping function is more efficient then filtering all types using 'SubtypeFilter', because:
This new mapping function is used by #1291, which