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: refactor: CtScanner to report CtRole of scanned element #1632

Merged
merged 7 commits into from
Oct 31, 2017

Conversation

pvojtechovsky
Copy link
Collaborator

This is an alternative to #1631 which directly modifies CtScanner ... to see how much Spoon will be broken...

@pvojtechovsky
Copy link
Collaborator Author

Only these tests fails:

CtGenerationTest.testGenerateCloneVisitor:113 » ClassCast spoon.support.reflec...
CtGenerationTest.testGenerateCtBiScanner:75 » ClassCast spoon.support.reflect....
CtGenerationTest.testGenerateReplacementVisitor:43 » ClassCast spoon.support.r...

It is fixable. WDYT? Will we go this way?

@monperrus
Copy link
Collaborator

I really like this solution, which can probably be 100% backward compatible, without any API change (incl the one detected by Revapi).

@pvojtechovsky
Copy link
Collaborator Author

I am glad to hear that we are on the same side ;-)

The little problem is that refactored CtScanner is harder for maintenance, because we have to actually manually take care about consistency of CtRole and method call pairs.

It would be cool if CtScanner might be generated from Spoon model. But actually there are missing annotations, which would define scanning order. Let's discuss it in #1634

@monperrus
Copy link
Collaborator

monperrus commented Oct 21, 2017 via email

@pvojtechovsky
Copy link
Collaborator Author

pvojtechovsky commented Oct 21, 2017

I agree, it is not big problem ... it can be covered by test, which checks that CtRole is matching method.
I will implement this test soon.

@INRIA INRIA deleted a comment from spoon-bot Oct 21, 2017
@INRIA INRIA deleted a comment from spoon-bot Oct 21, 2017
@pvojtechovsky
Copy link
Collaborator Author

I have implemented the test which checks whether correct role is user in CtScanner. But that test does not work well, because it is based on existing test CtScannerTest#testScannerCallsAllProperties, which is buggy - some methods are not checked. For example CtActualTypeContainer#getActualTypeArguments()

@monperrus Could you please have a look at it and fix the origin test?

@pvojtechovsky
Copy link
Collaborator Author

  1. The CtBiScanner knows CtRole now too - @monperrus WDYT?

  2. there are some problems with definition of @derived properties in Spoon model. The problems are visible after the bug in SpoonTestHelpers is fixed.
    A) CtScannerTest is wrong
    B) Spoon model is missing some @derived annotations
    C) A+B ;-)

There is also bug in CtScanner#visitCtAnnotationFieldAccess, which calls derived scan(CtRole.TYPE, annotationFieldAccess.getType());

@pvojtechovsky
Copy link
Collaborator Author

It actually fails on inconsistency in @DerivedProperty.

Problem:
Till now the detection of whether property is derived or not was based mainly on interfaces. But that is not correct, because implementation class can inherit from more super interfaces and each of them can declare @DerivedProperty in different way.
I guess the correct is to check annotations on the method which really implements the behavior.
But in the case of CtBlockImpl#getLastStatement() there is missing @DerivedProperty annotation.

WDYT? should check @DerivedProperty on implementation classes and not on intefaces?
If yes, then we can fix CtBlockImpl#getLastStatement(). If not, then what do you suggest?

@pvojtechovsky
Copy link
Collaborator Author

This PR now uses new SpoonMetaModel and it's detection of isDerived field.
I have fixed some inconsistencies in spoon model.

@monperrus, Now I stuck on scanning of COMMENT field. It is missing many CtScanner.visitXxx methods. Is it intentional???

@pvojtechovsky
Copy link
Collaborator Author

ping @monperrus I need your answer to continue here. Thanks! ;-)

@tdurieux
Copy link
Collaborator

@monperrus, Now I stuck on scanning of COMMENT field. It is missing many CtScanner.visitXxx methods. Is it intentional???

I don't remember there was any discussion, I had very quickly the support of comment, I probably forgot to add some scanner.
@surli also added some elements in CtComment.

@surli
Copy link
Collaborator

surli commented Oct 24, 2017

@surli also added some elements in CtComment.

Actually I started to work on it but I stopped and I never created any PR, so I'm not sure I can really help here :)

@monperrus
Copy link
Collaborator

Now I stuck on scanning of COMMENT field. It is missing many CtScanner.visitXxx methods. Is it intentional???

Yes, it is. As far as I remember, the main idea is that comments are not part of equality checking. Since EqualVisitor is derived from CtScanner we explicitly exclude all calls to getComments

@pvojtechovsky
Copy link
Collaborator Author

we explicitly exclude all calls to getComments

You are not right, or it must be a misunderstanding, because there are already 65 calls of getComments and only 8 are missing.

@pvojtechovsky
Copy link
Collaborator Author

Something bad happened to CI? Please check it.

@pvojtechovsky pvojtechovsky changed the title WiP: refactor: CtScanner to report CtRole of scanned element review: refactor: CtScanner to report CtRole of scanned element Oct 31, 2017
@tdurieux
Copy link
Collaborator

there is a problem with travis: https://www.traviscistatus.com/incidents/4vdl52d28hz3

@pvojtechovsky
Copy link
Collaborator Author

This PR is ready for merge from my point of view

@monperrus
Copy link
Collaborator

Is it possible to keep spoon.reflect.visitor.CtScanner::scan(java.lang.Object) to be 100% backward compatible?

@pvojtechovsky
Copy link
Collaborator Author

Done. It should work like this. I am done here

@INRIA INRIA deleted a comment from spoon-bot Oct 31, 2017
@INRIA INRIA deleted a comment from spoon-bot Oct 31, 2017
@pvojtechovsky
Copy link
Collaborator Author

I have found that this PR contained some changes in SpoonTestHelpers, which are not needed for this PR. I have rolled back these changes. I am done here.

@monperrus monperrus merged commit 9688f49 into INRIA:master Oct 31, 2017
@monperrus
Copy link
Collaborator

thanks Pavel!

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.

4 participants