-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
feat: Add CtExecutable.addParameterAt #3902
Conversation
…utable Signed-off-by: Aman Sharma <[email protected]>
Signed-off-by: Aman Sharma <[email protected]>
Signed-off-by: Aman Sharma <[email protected]>
CtParameter<?> first = factory.createParameter(); | ||
CtTypeReference<String> firstType = factory.Type().stringType(); | ||
first.setSimpleName("x"); | ||
first.setType((CtTypeReference) firstType); |
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.
Passing the argument as is (without type casting) was throwing a compilation error.
incompatible types: spoon.reflect.reference.CtTypeReference<java.lang
.String> cannot be converted to spoon.reflect.reference.CtTypeReference<capture#1 of ?>
I was getting confused with the types as it wasn't even allowing it to type cast to CtTypeReference<String>
so I just used a raw type for now. Need help resolving this :)
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.
The type parameters must match between CtParameter
and CtTypeReference
.
CtParameter<String> first = factory.createParameter();
CtTypeReference<String> firstType = factory.Type().stringType();
first.setSimpleName("y");
first.setType(secondType);
The reason you can't cast to CtTypeReference<String>
is that casting is a runtime thing, and the type parameter of a generic type is erased at compile time. That is to say, the JVM does not know the parameterization of a generic type. It's the same reason you can't do stuff like list instanceof List<String>
. You can read about type erasure here. It's quite fascinating, and massively annoying.
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.
You can read about type erasure here. It's quite fascinating, and massively annoying.
😂. I shall read about it. I remember you mentioned this concept in one of our meetings.
By the way, can you run the workflow for this PR? I will be able to resolve if anything breaks.
Do we need to write a test case for it? We can test if the unit test throws an Exception. |
be3d7ca
to
002708a
Compare
Signed-off-by: Aman Sharma <[email protected]>
002708a
to
b43c039
Compare
That's an Also, @monperrus approve workflow run please :) |
Yes. Let me know if they are still tested. Logically speaking, the test should be written (if it does not exist) for the decorator itself so we don't need to repeat it here. |
Signed-off-by: Aman Sharma <[email protected]>
Signed-off-by: Aman Sharma <[email protected]>
FYI waiting for workflow run approval from @monperrus before review. |
run approved! |
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 looks excellent to me.
The overall architecture has the same problem with code duplication as mentioned in #3896, but it's not really the place of either of these PRs to fix that. So I think we should merge this, and deal with the code duplication (which was there to begin with) separately.
@monperrus I vote for merge.
Thanks @algomaster! In Spoon, we have one comment line per test that states the test intention, the contract that is being tested. By convention, it starts with
Could you add this contract line in each new test? |
Signed-off-by: Aman Sharma <[email protected]>
@monperrus I added the contract for each test case in this PR. |
Thanks a lot. LGTM, will merge. |
Thanks a lot for your contribution! |
@algomaster99 Congrats on your first contribution to Spoon! |
Thanks a lot! :) I will move ahead and use this API in diffmin. How can I find the SNAPSHOT version? |
@algomaster99 The snapshot version is already used in diffmin. When you specify 9.1.0-SNAPSHOT, Maven will fetch the latest snapshot for 9.1.0. We publish a snapshot on each push to master in Spoon, so it should be up by now. |
#3884
This PR provides an API to add a parameter in
CtExecutable
s at a specified position. Since there are few classed which inherit fromCtExecutableImpl
, we should test this API for all those classes.- CtAnonymousExecutable(cannot add parameters to an anonymous class in Java)