review: feat: support to parse CtType, CtClass and CtField from JDK element CtPath.toString()#4989
review: feat: support to parse CtType, CtClass and CtField from JDK element CtPath.toString()#4989kaml8 wants to merge 13 commits intoINRIA:masterfrom
CtType, CtClass and CtField from JDK element CtPath.toString()#4989Conversation
| } | ||
| if (filtered.isEmpty() && ctType != null) filtered.add(ctType); | ||
| } | ||
| return (List<T>) filtered; |
There was a problem hiding this comment.
💬 2 similar findings have been found in this PR
unchecked: unchecked cast
🔎 Expand here to view all instances of this finding
| File Path | Line Number |
|---|---|
| src/main/java/spoon/reflect/path/impl/CtPathImpl.java | 38 |
| src/main/java/spoon/reflect/path/impl/CtPathImpl.java | 38 |
Visit the Lift Web Console to find more details in your report.
ℹ️ Learn about @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
| Command | Usage |
|---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
I-Al-Istannen
left a comment
There was a problem hiding this comment.
Thanks, I have a few remarks :)
| */ | ||
| @DerivedProperty | ||
| @PropertyGetter(role = CONSTRUCTOR) | ||
| CtConstructor<T> getConstructorBySignature(String signature); |
There was a problem hiding this comment.
I don't quite see how this relates to the title and scope of this PR. This should be done in a separate PR IMHO.
There was a problem hiding this comment.
As a CtConstructor has a CtPath ends with #constructor[signature=(int)], I need this function to get the CtElement.
| * @return null if does not exit | ||
| */ | ||
| @PropertyGetter(role = METHOD) | ||
| <R> CtMethod<R> getMethodBySignature(String signature); |
There was a problem hiding this comment.
I don't quite see how this relates to the title and scope of this PR. This should be done in a separate PR IMHO.
There was a problem hiding this comment.
Same to constructor, a CtMethod has a CtPath ends with #method[signature=(...)], I need this function to get the CtElement.
| return (List<T>) filtered; | ||
| } | ||
|
|
||
| private Class<?> getJdkClass(String name) { |
There was a problem hiding this comment.
Note: This is duplicated in a few places in spoon
There was a problem hiding this comment.
Yes, I found similar one: TypeFactory.get(final String qualifiedName).
However, this method doesn't support shadow elements while another reload method TypeFactory.get(Class<?> cl) does.
So the question is that we need a function that transform String to Class<?>, as the method above did,
or add extra logic in TypeFactory.get(final String qualifiedName) to process shadow elements intendly.
| if (filtered.isEmpty()) { | ||
| List<String> cls_name_list = new LinkedList<>(); | ||
| CtType<?> ctType = null; | ||
| for (CtPathElement element : elements) { |
There was a problem hiding this comment.
I am not very well versed with the CtPath API, but this seems like it re-implements existing functionality and we should instead adjust the matching logic of the path elements?
There was a problem hiding this comment.
Seeing issue #4984 , yeah I want to reuse the case that with no parameter for matching shadow elements.
The matching logic do differ, so it may also be a good idea to extract a new method evaluateOnShadowModel as you suggested.
| } else if ("]".equals(token) || ";".equals(token)) { | ||
| //finished reading of argument value | ||
| pathElement.addArgument(argName, argValue.toString()); | ||
| //[fix bug]:AbstractPathElement.getArguments([constructor with no parameters]) |
There was a problem hiding this comment.
I am not sure what this is doing here, I will need to have a look at it later. This also feels like it should be a different PR and have a test case :)
There was a problem hiding this comment.
Yes it's a small bug in method AbstractPathElement.getArguments(), when a default constructor in, it produces redundant ).
| if (!(typeMember instanceof CtConstructor)) { | ||
| continue; | ||
| } | ||
| CtConstructor<T> c = (CtConstructor<T>) typeMember; |
There was a problem hiding this comment.
unchecked: unchecked cast
ℹ️ Learn about @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
| Command | Usage |
|---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
|
@MartinWitt |
|
@kaml8 what's the status here? thanks! |
when calling `AbstractPathElement.getArguments([constructor with no parameters])` will produce redundant ')'
Test cases have passed. Now it supports to get JDK-element from CtPath(As String).
30c4b84 to
a2e2090
Compare

fix #4984
getMethodBySignature(String signature).getConstructorBySignature(String signature).getJdkClass.evaluateOn, search for jdk elements when no root parameter is given.