-
-
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
How to resolve CtTypeParameter using Actual type arguments? #1233
Comments
The advantages of the current behavior is that:
What you propose makes sense, probably in a new method WDYT? |
ok, I agree.
Yes, spoon needs that support, because it is really not trivial operation to detect, which value is assigned to which type parameter.
I would say that we need something else. The problem of resolving value of type parameters is not only about super class. Spoon should have a way how to resolve type parameter everywhere ... in superInterfaces, methods, parameters, statements, ... nearly everywhere where is CtType may be a CtTypeParameter, which needs to be resolved. So the API should solve this use case: Client has a But there are some open points in this "design". For example: How to define the
All these three cases might share common structure, which defines actual type arguments of any hierarchy (e.g.: method/inner class1/inner class2/class) of formal type declarers. IdentityHashMap<CtFormalTypeDeclarer, List<CtTypeReference<?>>> But that structure is ugly from client's point of view. It needs some wrapper... May be API like this would be more user friendly:
WDYT? |
May be an API might be implemented as //the holder of actual type arguments. Points for example to `List<String>`
CtTypeReference typeRef = ...
//to be resolved type parameter. Point for example to 'T' of `interface List<T> {}`
CtType(Parameter)(Reference) anType = ...
CtTypeReference resolvedTypeRef = anType.map(new TypeParameterResolvingFunction(typeRef)).first()
//resolvedTypeRef points to `String' This solution has one advantage. The type parameter resolving may need a lot of computation (searching in classes hierarchies of sub type to super type) and the result of this computation might be cached by instance of |
CtTypeReference trListOfString = ... //refers to List<String>
CtTypeReference trListOfInteger = ... //refers to List<Integer>
//Do you agree that Spoon should return false here?
assertFalse(trListOfString.isSubtypeOf(trListOfInteger)) Would you accept such implementation? |
yes |
I agree that there are a number of case to consider. I would still recommend baby steps. What about starting with However, before starting, recall that JDT already infers a number of types for us. According to this thread, it seems that they are not resolved and that we need to do this by hand. Correct? Maybe we could simply improve JDTTreeBuilder so that all types are resolved? |
It looks like a misunderstanding. I have not found any case when I would need "Type inference". The JDT compiler infers types correctly. All my work related to resolving of CtTypeParameter have two targets:
So I need two functions:
I see no relation to Type inference. May be I or you just use wrong term?
I do my best ... but even the smaller BS, seems to be quite big till now. But I am not finished. I will check how it can be split to smaller parts - as usually :-) |
OK. Maybe we don't even have to add new methods, but just to improve |
It is probably possible. I can put most of the code into an helper model structure, which will be able to adapt type parameters, compute type erasure and then detect if type is subtype of another type and if method overrides another method. Then we can use this model structure instead of origin implementation of isSubtypeOf and IsOverriding |
it sounds like a good plan.
|
closed with 5e7ee76 |
I would like to fix #1160 and I came to an idea how to improve handling of actual type arguments of CtTypeReference during some operations, like
CtTypeReference#getSuperclass()
,CtTypeReference#getSuperInterfaces()
, ...?There is a test case, which shows how it might behave in future.
The idea is
Simple example:
Please think about this and give me feedback if such change of Spooon behavior is acceptable. I would like to base further PRs on that too. Or if it is not acceptable, then I suggest to add an new API method, which will behave like this. Please suggest how it should look like then.
The text was updated successfully, but these errors were encountered: