Skip to content
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

Merged

Conversation

pvojtechovsky
Copy link
Collaborator

@pvojtechovsky pvojtechovsky commented May 8, 2017

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:

  • it allows searching for subtypes of more then one super type
  • it visits each type of spoon model only once, during inheritance hierarchy checking.
  • if new super type is added (configured), then next scanning always returns only newly found sub types

This new mapping function is used by #1291, which

  • needs to scan sub inheritance hierarchy of more types in more iterations, where each iteration needs to scan similar sub hierarchy, but with some new types.
  • each next iteration has to return only newly found subtypes
  • it should be fast, because I need to refactor nearly all methods of model of my project.

@pvojtechovsky pvojtechovsky force-pushed the feat_SubInheritanceHierarchyFunction branch 2 times, most recently from 839929f to 354298f Compare May 8, 2017 17:38
@monperrus
Copy link
Collaborator

monperrus commented May 10, 2017

It seems that this function takes a type as input, and optionally a package. What about designing it the other way (CtConsumableFunction<CtTypeInformation>):

public class SubInheritanceHierarchyFunction implements CtConsumableFunction<CtTypeInformation>, CtQueryAware {
public SubInheritanceHierarchyFunction() // default to RootPackage
public SubInheritanceHierarchyFunction(CtPackage)
public void apply(CtTypeInformation input, final CtConsumer<Object> outputConsumer) 

The tests would be clearer this way.

@pvojtechovsky
Copy link
Collaborator Author

What about designing it the other way (CtConsumableFunction):

then it does not fit to my needs. But I agree that clients will think same like you, 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

@pvojtechovsky pvojtechovsky changed the title review3: feature sub inheritance hierarchy function review: feature sub inheritance hierarchy function May 10, 2017
@monperrus
Copy link
Collaborator

monperrus commented May 10, 2017 via email

@pvojtechovsky pvojtechovsky force-pushed the feat_SubInheritanceHierarchyFunction branch 2 times, most recently from 364e2cf to 8fb7fd9 Compare May 10, 2017 18:43
@pvojtechovsky
Copy link
Collaborator Author

Move and rename done. Seems to be OK from my point of view. Please fix my documentation/English ;-) Thanks!

@pvojtechovsky pvojtechovsky changed the title review: feature sub inheritance hierarchy function WiP: feature sub inheritance hierarchy function May 10, 2017
@pvojtechovsky
Copy link
Collaborator Author

Let's fix #1292 first. This PR depends on it, so refactoring will be easier without it.

@pvojtechovsky pvojtechovsky force-pushed the feat_SubInheritanceHierarchyFunction branch from 8fb7fd9 to 5b56ace Compare May 15, 2017 20:15
@pvojtechovsky pvojtechovsky changed the title WiP: feature sub inheritance hierarchy function review2: feature sub inheritance hierarchy function May 15, 2017
@monperrus
Copy link
Collaborator

rebase?

@pvojtechovsky pvojtechovsky force-pushed the feat_SubInheritanceHierarchyFunction branch from 5b56ace to 73b43f3 Compare May 16, 2017 06:06
* 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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private?

Copy link
Collaborator Author

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.

@pvojtechovsky pvojtechovsky force-pushed the feat_SubInheritanceHierarchyFunction branch 2 times, most recently from 62aab98 to 2824c03 Compare May 16, 2017 19:59
@pvojtechovsky pvojtechovsky changed the title review2: feature sub inheritance hierarchy function review: feature sub inheritance hierarchy function May 16, 2017
@pvojtechovsky
Copy link
Collaborator Author

Now the SubInheritanceHierarchyFunction is stateless. Is such solution acceptable?
It is ready for merge from my point of view... please check java doc as usually...

@monperrus
Copy link
Collaborator

monperrus commented May 16, 2017 via email

@pvojtechovsky
Copy link
Collaborator Author

pvojtechovsky commented May 17, 2017

private

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.

@pvojtechovsky
Copy link
Collaborator Author

Other question: most boolean flags in SubInheritanceHierarchyFunction and
SubInheritanceHierarchyResolver are not tested.
Do you need them all?

I do not need them now/yet, but they copy the pattern of other mapping functions. For example

  • boolean includingSelf - is same in: CtScannerFunction, OverriddenMethodFilter, OverridingMethodFilter, ParentFunction, SiblingsFunction, SubtypeFilter
    other boolean switches are with similar pattern and makes the queries based on these functions more flexible/powerful.

@monperrus
Copy link
Collaborator

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.

@pvojtechovsky
Copy link
Collaborator Author

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

  1. it needs more computation
  2. it needs more complex client code, because client has to filter out already found sub types.

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

@pvojtechovsky
Copy link
Collaborator Author

On the boolean flags, I'm not against them, I only much prefer specified/tested code.

sure, I will add tests after we found a compromize between size of API and contracts of SubInheritanceHiearchyResolver.
I do not want to takeover your changes into my workspace, because it causes compilation problems in my code.

@monperrus
Copy link
Collaborator

monperrus commented May 18, 2017 via email

@monperrus monperrus force-pushed the feat_SubInheritanceHierarchyFunction branch from 31ff93f to 2824c03 Compare May 18, 2017 19:35
@monperrus
Copy link
Collaborator

removed my last commit

@pvojtechovsky pvojtechovsky force-pushed the feat_SubInheritanceHierarchyFunction branch from 2824c03 to 2d875aa Compare May 19, 2017 12:59
@pvojtechovsky
Copy link
Collaborator Author

Rebase done but, build server has problem:

Error while storing the mojo status: No space left on device

@surli
Copy link
Collaborator

surli commented May 19, 2017

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.

@monperrus monperrus merged commit 4c9a637 into INRIA:master May 19, 2017
@monperrus
Copy link
Collaborator

thanks!

@pvojtechovsky pvojtechovsky deleted the feat_SubInheritanceHierarchyFunction branch May 20, 2017 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants