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

Baby PR: SubInheritanceHierarchyResolver #1309

Merged
merged 4 commits into from
May 19, 2017

Conversation

monperrus
Copy link
Collaborator

baby PR for #1290

@monperrus monperrus changed the title Feat sub inheritance hierarchy resolver Baby PR: SubInheritanceHierarchyResolver May 18, 2017
@monperrus
Copy link
Collaborator Author

@pvojtechovsky WDYT?

@monperrus monperrus force-pushed the feat_SubInheritanceHierarchyResolver branch from 1931b3a to c9530f1 Compare May 18, 2017 19:48
@pvojtechovsky
Copy link
Collaborator

Martin, thanks for Your effort. It looks quite good. Such implementation probably fits to needs of #1291 too. So I like it!

I have only minor notes. I will add them into code

* Send them to outputConsumer and add then as targetSuperTypes too, to perform faster with detection of next sub types.
*/
if (!targetSuperTypes.contains(typeRef.getQualifiedName())) {
targetSuperTypes.add(typeRef.getQualifiedName());
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (!targetSuperTypes.contains(typeRef.getQualifiedName())) {
   targetSuperTypes.add(typeRef.getQualifiedName());

can be replaced by

if (targetSuperTypes.add(typeRef.getQualifiedName())) {

You have seen that in my origin code, and you changed it, so you probably think it as not understandable. So I at least suggest

String qName = typeRef.getQualifiedName();
if (!targetSuperTypes.contains(qName)) {
   targetSuperTypes.add(qName);

... spoon is already not fastest so why to wast time again?
I have feeling (not measured) like this code is in middle of often repeated algorithm. I plan to refactor 10 000 methods of 6000 classes and I need to search many many inheritance hiearchies of all these classes for all methods ... it can end with a big number of calls ;-)

private boolean failOnClassNotFound = false;

public SubInheritanceHierarchyResolver(CtPackage input) {
inputPackage = input;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about no package at all?
The default (root) inputPackage might be taken from the factory of CtTypeInformation delivered by first call of #addSuperType.
And if somebody ever needs to search in different then root package, then we can add #setStartPackage(CtPackage) method.
That setStartPackage is better then constructor, because it can be used to recursively scan on different packages... But I personally do not need that, so I vote for removing constructor parameter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default (root) inputPackage might be taken from the factory of CtTypeInformation delivered by first call of #addSuperType.

This would be implicit and not regular.

then we can add #setStartPackage(CtPackage) method.

setter = state = mutability = bad. the current design is append-only which is much better.

@pvojtechovsky
Copy link
Collaborator

That's all. Thanks!

@monperrus
Copy link
Collaborator Author

You have seen that in my origin code, and you changed it, so you probably think it as not understandable

yes! maintainability always comes first :-)

optimization is just fine, but should come with very long and detailed comments to still be readable and maintainable.

@monperrus
Copy link
Collaborator Author

OK. Let's wait for @surli to review and merge this one, probably tomorrow.

@pvojtechovsky
Copy link
Collaborator

This PR is OK for me. Thanks!

@monperrus
Copy link
Collaborator Author

monperrus commented May 19, 2017 via email

@surli
Copy link
Collaborator

surli commented May 19, 2017

I'm reading the code, it seems OK but I have some questions as I'm still not really familiar with all changes introduced by Pavel :)

.setListener(new CtScannerListener() {
@Override
public ScanningMode enter(CtElement element) {
final CtTypeReference<?> typeRef = (CtTypeReference<?>) element;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to be sure: this cast here is always right because of the typeFilter and classFilter you're using above which guarantee you'll obtain CtTypeReference, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This case is always right because SuperInheritanceHierarchyFunction by default always returns TypeReferences. My origin code declared it explicitly on line 145 where was

//internally it works always with references
.returnTypeReferences(true)

but Martin cleared that ;-)

* FOUND! we are in super inheritance hierarchy, which extends from an searched super type(s).
* All `currentSubTypes` are sub types of searched super type
*/
while (currentSubTypes.size() > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, this part remains unclear to me: as far as I understand, you assume that the elements are returned with the following order: first the leaves, and then the superclasses/interfaces, right? This is a contract of the SuperInheritanceHierarchyFunction? Because I'm not sure to understand that when I'm reading its documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

first the leaves, and then the superclasses/interfaces, right?

right. it is the contract of SuperInheritanceHierarchyFunction. It should be written in javadoc of SuperInheritanceHierarchyFunction class.

@surli
Copy link
Collaborator

surli commented May 19, 2017

Ok then thanks @pvojtechovsky for the explanations :)

@surli surli merged commit dcdbe37 into INRIA:master May 19, 2017
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