-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
review: feat: support to parse CtType
, CtClass
and CtField
from JDK element CtPath.toString()
#4989
base: master
Are you sure you want to change the base?
Conversation
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).
} | ||
} | ||
if (filtered.isEmpty() && ctType != null) filtered.add(ctType); | ||
} | ||
return (List<T>) filtered; |
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.
💬 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 ]
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.
Thanks, I have a few remarks :)
*/ | ||
@DerivedProperty | ||
@PropertyGetter(role = CONSTRUCTOR) | ||
CtConstructor<T> getConstructorBySignature(String signature); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This is duplicated in a few places in spoon
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -145,7 +145,8 @@ private String parseArgumentValue(Tokenizer tokenizer, String argName, CtPathEle | |||
} | |||
} 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
fix #4984
getMethodBySignature(String signature)
.getConstructorBySignature(String signature)
.getJdkClass
.evaluateOn
, search for jdk elements when no root parameter is given.