-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
Depends on #1238. feature: TypeFactory#createReference(type,includingFormalTypeParams) #1237
Depends on #1238. feature: TypeFactory#createReference(type,includingFormalTypeParams) #1237
Conversation
it is clearly backward-compatible. By definition, the actual type arguments would never be bound, they would only by "E" or "T" because they come from the formal definition? Correct? could you add a test? |
"Houston, we have a problem"... The test fails... because there is a problem in a spoon model. I made issue #1238 for that. |
OK, let's fix #1238 first then. |
here is a fix. WDYT? |
Revapi Analysis resultsOld API: fr.inria.gforge.spoon:spoon-core:jar:5.6.0 New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT Detected changes: 9. Change 1
Change 1
Change 2
Change 2
Change 2
Change 3
Change 3
Change 3
Change 4
Change 4
Change 5
Change 5
Change 5
Change 6
Change 7
Change 8
Change 9
|
I am not sure with these things: CtType type = ...
CtTypeReference ref = type.getReference();
assertSame(type, ref.getDeclaration());
B is correct. A makes no sense. Because every formal type parameter is valid only in scope of it's declarer and if it is out of that scope then it is invalid. class Cat<T> {}
Cat<T> cat; //makes no sense because <T> is out of it's scope. So that operation is not the way how to build a compilable/printable spoon model. It is the way how to create special structures, which are useful for analyzing of spoon model. For me B is correct. How to continue? I do not need to have this issue solved to be able to continue with other PRs. May be it would be helpful, but I can live without that too. I though it is clear and small BS, so I suggested to do it. But I see that we see that concept different so I suggest to postpone this discussion after somebody will really need it for some real use case. Your current implementation, which breaks first contract above, would be even problem for my code. So I prefer to not have it. |
Your code is kind of compromise, which tries to be working for clients whose answer for Q1 and Q2 is both A and B too. But that compromise stops working on code like this: class Dog<T>{}
class Cat<T> {
Dog<T> dog;
} If we understand that code as printable/compilable spoon model, then it is clear that |
Very interesting discussion.
Basically, for type parameters, we have two kinds of declaration. So we need an additional method in
CtTypeParameter.
Two questions.
What should be the name of the new method? I'd suggest getTypeParameterDeclaration (following the
convention of getTypeDeclaration and getExecutableDeclaration)
what should be the behavior of both?
class Dog<X>{}
class Cat<T> {
Dog<T> dog;
}
for Dog<T>, I propose that getDeclaration points to T and that getTypeParameterDeclaration points to X.
OK for you?
|
I did not got it.
What will this new method return in this context? class Cat<T>{
T field;
} Concerning dynamic lookup... I agree with you that in normal cases the dynamic lookup is correct. But there is question whether we need to switch off dynamic lookup in some situations and be able to directly point to declaration. |
See recent commit
T.getDeclaration would return the T of Cat |
Revapi Analysis resultsOld API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-20170329.224511-23 New API: fr.inria.gforge.spoon:spoon-core:jar:5.7.0-SNAPSHOT Detected changes: 1. Change 1
|
Now I noticed your commit. I understand it now. It is an interesting solution! |
I'm just trying to merge this PR which is about "TypeFactory#createReference(type,includingFormalTypeParams)", with an appropriate test. To me it's OK like this. It's probably not the perfect solution but it's a working one and we can improve it in the future in the context of another PR. WDYT? |
@@ -342,8 +356,7 @@ public CtTypeParameterReference createReference(CtTypeParameter type) { | |||
ref.addAnnotation(ctAnnotation.clone()); | |||
} | |||
ref.setSimpleName(type.getSimpleName()); | |||
//TypeParameter reference without parent is unusable. It lost information about it's declarer | |||
ref.setParent(type); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is problem for my code. Please rollback it.
Yes this solution is ok, just do not create reference without parent. It breaks basic contract of usage uf type and typeReference. Others expects that |
6883a11
to
acd4f24
Compare
Thank You. It is OK for me now. |
acd4f24
to
93d0aa3
Compare
OK, thanks! |
A baby step. The TypeFactory method which creates a CtTypeReference, which has initialized actual type arguments following formal type parameters of the input CtType.
I need it to simplify architecture of CtTypeParameter resolving algorithm. This algorithm can be theoretically applied to
A) CtTypeReference - which has actual type arguments
B) CtType - which has formal type parameters
The new method of this PR let's me simplify it to A) only, because B) can be easily covered to A) by: