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: CtTypeParameter#getTypeErasure() #1216

Merged
merged 2 commits into from
Apr 3, 2017

Conversation

pvojtechovsky
Copy link
Collaborator

@pvojtechovsky pvojtechovsky commented Mar 11, 2017

Adds new method:

  • CtTypeParamer#getTypeErasure() - returns type erasure of generic parameter

This method and #1225 are needed to correctly detect whether method overrides another method following specification

@pvojtechovsky pvojtechovsky changed the title WiP: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo review: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo Mar 12, 2017
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.6.0-20170311.234506-76

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

Detected changes: 2.

Change 1

Name Element
Old none
New method spoon.reflect.reference.CtTypeReference spoon.reflect.declaration.CtTypeParameter::getTypeAdaptedTo(spoon.reflect.declaration.CtType)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking, source: breaking, semantic: potentially_breaking

Change 2

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

@pvojtechovsky pvojtechovsky changed the title review: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo review 2: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo Mar 13, 2017
@pvojtechovsky pvojtechovsky force-pushed the TypeParameter branch 2 times, most recently from 3ce9647 to addfd6a Compare March 14, 2017 17:45
@pvojtechovsky pvojtechovsky changed the title review 2: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo review 1: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo Mar 14, 2017
@monperrus
Copy link
Collaborator

getTypeErasure is an excellent idea, thanks.

To me, the type erasure is computed when the type parameter is used not defined. This means that getTypeErasure should rather be in CtTypeParameterReference. What do you think?

(also could we split the discussion of getTypeErasure and of getTypeAdaptedTo in two separate PRs?)

@pvojtechovsky
Copy link
Collaborator Author

Computing whether method A overrides method B uses type erasure. So it is not linked to CtTypeParameterReference. But we can have this method on both CtTypeParameter and CtTypeParameterReference. I personally need it on CtTypeParameter

split the discussion of getTypeErasure and of getTypeAdaptedTo in two separate PRs

I will check if it can be split

@monperrus
Copy link
Collaborator

monperrus commented Mar 15, 2017 via email

@pvojtechovsky
Copy link
Collaborator Author

There are two types of type erasures. Till now I though only about this case:

class<A extends InputStream> {
    A stream;
    <B extends Reader> void setReaderLike(B reader) {}
}

Such typed parameters naturally computes erasure using code on CtTypeParameter (like it was in this PR till now).

Note that

  • both CtTypeParameter and CtTypeParameterReference directly contains superClass/superType, which represents their bound.
  • only CtTypeParameter has declaringType.

The bound and declaringType are needed to compute type erasure. So from that point of view thos code belongs 1st to CtTypeParameter. And from client's point of view it makes sense life easier if API for CtTypeParameterReference exists too.

But thanks to your note, I see now that there is another place where type erasure makes sense:

class X {
   void processList(List<? extends Reader> list) {};
}

In this case there is no CtTypeParameter or CtTypeParameterReference involved at all. In this case we need new method CtTypeReference#getTypeErasure()

So I suggest these steps:

  1. to merge this PR with CtTypeParameter#getTypeErasure() only. (I will remove getTypeAdaptedTo)
  2. to create another PR, which handles type erasures on all type references CtTypeReference#getTypeErasure(). This code will sometime call CtTypeParameter#getTypeErasure() and sometime it will use new algorithm, which is not implemented yet.

OK?

@pvojtechovsky pvojtechovsky changed the title review 1: feature: CtTypeParamer#getTypeErasure, getTypeAdaptedTo review 1: feature: CtTypeParameter#getTypeErasure() Mar 15, 2017
@pvojtechovsky
Copy link
Collaborator Author

Now this PR contains only plain CtTypeParameter#getTypeErasure().

Please review. Thank you!

@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.6.0-20170315.164827-83

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

Detected changes: 1.

Change 1

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

@pvojtechovsky pvojtechovsky changed the title review 1: feature: CtTypeParameter#getTypeErasure() WiP: feature: CtTypeParameter#getTypeErasure() Mar 16, 2017
@pvojtechovsky
Copy link
Collaborator Author

I have to think/learn more about generics and parameters. May be you are right that CtTypeReferences has to be involved more in the Type erasure process...

@pvojtechovsky pvojtechovsky force-pushed the TypeParameter branch 3 times, most recently from aa61e27 to 8bbef27 Compare April 2, 2017 18:32
@pvojtechovsky
Copy link
Collaborator Author

I have simplified computing of type erasure and I added CtTypeParameterReference#getTypeErasure too. Is such implementation OK, or did you expected something more for CtTypeParameterReference#getTypeErasure ?

@pvojtechovsky pvojtechovsky changed the title WiP: feature: CtTypeParameter#getTypeErasure() review1: feature: CtTypeParameter#getTypeErasure() Apr 2, 2017
@monperrus
Copy link
Collaborator

The signature CtTypeReference<?> getTypeErasure() is clear.

However, I'm not sure about the location.
What about putting this method in CtTypeReference? or even maybe in CtTypeInformation?

@pvojtechovsky
Copy link
Collaborator Author

I like this idea!
I implemented it as CtTypeInformation#getTypeErasure()

@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170403.163958-30

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

Detected changes: 1.

Change 1

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

@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170403.191725-31

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

Detected changes: 1.

Change 1

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

@monperrus monperrus merged commit 11d500f into INRIA:master Apr 3, 2017
@monperrus
Copy link
Collaborator

Thanks Pavel.

@pvojtechovsky
Copy link
Collaborator Author

Thanks Martin.

@pvojtechovsky pvojtechovsky deleted the TypeParameter branch April 3, 2017 20:23
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