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

review1: feature: CtMethod#isOverriding(CtMethod) #1220

Merged

Conversation

pvojtechovsky
Copy link
Collaborator

New API CtMethod#isOverriding(CtMethod), which works better on generic methods, then legacy CtExecutableReference#isOverriding(CtExecutableReference)

This PR actually fails on wrong legacy implementation of CtExecutableReference#isOverriding(CtExecutableReference)

I would like to discuss with you: "How to fix that legacy implementation?"

I did not understood:

  1. why isOverriding method was implemented on CtExecutableReference and not on CtMethod since beginning?
  2. how Template engine works with CtExecutableReference#isOverriding ... I do not know how to replace that code with CtMethod#isOverriding ... because I do not understand that code yet...

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch 3 times, most recently from ed17f5e to 5d5fc3b Compare March 14, 2017 20:33
@monperrus
Copy link
Collaborator

do we close this one?

@pvojtechovsky
Copy link
Collaborator Author

No. I think it makes sense to have CtMethod#isOverriding or something similar. Actually there is needed CtExecutableReference to be able to check isOverriding and I think it is inefficient/wrong. I will make a PR based on current code this or next week.

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from 5d5fc3b to 47af98d Compare April 27, 2017 20:03
@pvojtechovsky pvojtechovsky changed the title WiP: feature: CtMethod#isOverriding(CtMethod) review2: feature: CtMethod#isOverriding(CtMethod) Apr 27, 2017
@pvojtechovsky
Copy link
Collaborator Author

pvojtechovsky commented Apr 27, 2017

First commit comes from #1275. I will rebase after it is merged.
Then each commit can be understood as small PR

  1. implements CtMethod#isOverriding(CtMethod)
  2. use of CtMethod#isOverriding(CtMethod) in existing code - this one might be extracted as special PR. Just let me know if you think it makes sense.
  3. very simple test - extension of existing test
  4. complex test of CtMethod#isOverriding(CtMethod) - this one originally found problems fixed by review1: fix generic type adapting #1275

I think CtMethod#isOverriding(CtMethod) makes more sense then legacy CtExecutableReference#isOverriding(CtExecutableReference). WDYT?

@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170427.191244-62

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking semantic: potentially_breaking, source: breaking, binary: non_breaking

@monperrus
Copy link
Collaborator

I think it makes sense to have CtMethod#isOverriding or something similar.

I agree

why isOverriding method was implemented on CtExecutableReference and not on CtMethod since beginning?

To be able to do analyses on calls on library methods (which are not in the source classpath).

However, it's not relevant anymore because now that we create the spoon model of library classes as well through "shadow classes" (see getTypeDeclaration, getExecutableDeclaration).

How to fix that legacy implementation?

By simply delegating execRef#isOverriding to execRef.getExecutableDeclaration().isOverriding?

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from 47af98d to 23439b0 Compare April 30, 2017 18:19
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170429.224534-66

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking, source: breaking, semantic: potentially_breaking

@pvojtechovsky
Copy link
Collaborator Author

If the tests pass then this PR is done from my point of view

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from 7e30b1c to 4c201ba Compare May 1, 2017 08:34
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170430.224618-67

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking semantic: potentially_breaking, source: breaking, binary: non_breaking

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from 4c201ba to da41bd3 Compare May 1, 2017 09:01
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170430.224618-67

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking source: breaking, binary: non_breaking, semantic: potentially_breaking

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from c2d18af to 33d568b Compare May 1, 2017 09:15
@pvojtechovsky
Copy link
Collaborator Author

I removed OverriddenMethodFilter and OverridingMethodFilter from this PR to make it simpler.
I made another PR for them #1276.

@pvojtechovsky pvojtechovsky changed the title review2: feature: CtMethod#isOverriding(CtMethod) review1: feature: CtMethod#isOverriding(CtMethod) May 1, 2017
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170430.224618-67

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking source: breaking, binary: non_breaking, semantic: potentially_breaking

1 similar comment
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170430.224618-67

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking source: breaking, binary: non_breaking, semantic: potentially_breaking

@@ -234,7 +234,8 @@ public boolean isConstructor() {
@Override
public boolean isOverriding(CtExecutableReference<?> executable) {
CtExecutable<?> exec = executable.getDeclaration();
if (exec == null) {
CtExecutable<?> thisExec = getDeclaration();
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not getExecutableDeclaration? (better, incl shadow classes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why? Because I used same approach like old code.
Anyway you are right. So I have replaced that on 3 places. Now it uses better getExecutableDeclaration

private void checkMethodOverride(BiFunction<CtMethod<?>, CtMethod<?>, Boolean> isOverriding) {
Factory factory = ModelUtils.build(new File("src/test/java/spoon/test/method_overriding/testclasses").listFiles());
Map<String, List<CtMethod>> methodsByName = new HashMap<>();
factory.getModel().getRootPackage().filterChildren(new TypeFilter<>(CtMethod.class)).forEach((CtMethod m)->{
Copy link
Collaborator

Choose a reason for hiding this comment

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

need one assert to check that we go at least once through the loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170503.161928-72

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking source: breaking

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from 6a6cda1 to 62599d9 Compare May 3, 2017 19:53
@monperrus
Copy link
Collaborator

rebase?

@pvojtechovsky pvojtechovsky force-pushed the TestOfIsSubTypeOfTypeParameter branch from 62599d9 to f3a5d55 Compare May 4, 2017 08:51
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170504.085207-75

New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT

Detected changes: 1.

Change 1

Name Element
Old none
New method boolean spoon.reflect.declaration.CtMethod::isOverriding(spoon.reflect.declaration.CtMethod<?>)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking source: breaking,

@monperrus monperrus merged commit 9e5e8a8 into INRIA:master May 4, 2017
@monperrus
Copy link
Collaborator

Thanks Pavel.

By the way, test method checkMethodOverride(BiFunction<CtMethod<?>, CtMethod<?>, Boolean> isOverriding) is really hard to understand.

A simpler checkMethodOverride(CtMethod , CtMethod) and checkMethod**NOT**Override(CtMethod , CtMethod) would be easier to understand and maintain.

@pvojtechovsky pvojtechovsky deleted the TestOfIsSubTypeOfTypeParameter branch May 5, 2017 16:52
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