Comments (9)
Hi @jlerbsc . First of all thanks for all your quick suggestions. I overlooked the solution you proposed earlier:
Another solution would be to package these classes in a jar and configure it in the JarTypeSolver
There are two things to keep in mind. Only adding JarTypeSolver will not work. There is a specific order I need to follow - First goes all your third party jars, then your project jar and at last your source code. Since my original jar was a spring boot project, it didn't work when I included it in JarTypeSolver
. Later when I checked the structure of the jar, I found that it is actually a spring boot project and there is another .jar.original
file that represents my classes. Now I have renamed that file temporarily via script and I am not getting any error. Hence I am closing this issue now.
Thanks for all your support!!
from javaparser.
Even if this does not work or a bug, is there any alternative way of doing what I am trying to do here?
from javaparser.
JP's operation seems fine to me. To resolve the MyRequest type, under certain conditions, Jp escalates the search to the parent node (here SwitchEntry), which in turn tries to resolve the expression defined in the "request.getAction()" selector.
It cannot resolve this expression because the declaration of this method is generated by lombok.
What you can do is perhaps add a specialization to the ReflectionTypeSolver class by overriding the filterName(String name) method to take into account the class generated by lombok. I've never done this but I think it should work.
from javaparser.
@jlerbsc Sorry I didn't understand much. What I tried just now is - I created a new class and extended the ReflectionTypeSolver:
class SpecialReflectionTypeSolver extends ReflectionTypeSolver {
protected boolean filterName(String name) {
return super.filterName(name) || name.startsWith("lombok");
}
}
Is this what you meant? Sorry but I have no idea how this filterName()
method works.
from javaparser.
Probably something like that
class SpecialReflectionTypeSolver extends ReflectionTypeSolver {
protected boolean filterName(String name) {
return super.filterName(name) || name.startsWith("com.example.test");
}
}
Make sure that lombok actually generates java classes and that these classes are defined in the classpath of your test.
Another solution would be to package these classes in a jar and configure it in the JarTypeSolver
from javaparser.
@jlerbsc I may be wrong here, but my code is able to give correct output for request.getAction()
method call and is only failing for request.getName()
. I want to understand the difference here. If standalone request.getAction()
is recognized without any special symbol solver, why is it failing while resolving request.getName()
.
PS: I tried above both approaches, still getting same error.
from javaparser.
This is curious because the getAction method does not exist in the source code being analysed.
from javaparser.
@jlerbsc Thank you so much for your quick reply. To add more, if I modify my source code like below:
package com.example.test;
public class MyService {
public void doStuff(MyRequest request) {
var value = request.getAction();
switch(value) {
case "A":
request.getName();
break;
}
}
}
I get the same error. But if I modify it like below, it works perfectly:
package com.example.test;
public class MyService {
public void doStuff(MyRequest request) {
String value = request.getAction();
switch(value) {
case "A":
request.getName();
break;
}
}
}
The only difference between both is, in first snippet, I am storing the value of request.getAction()
in a variable initialized by var
and in second snippet, I have provided String
. Anyways I am not allowed to modify the source code. Now I am really curious to understand how calculateResolvedType()
works.
from javaparser.
In the first case, to find the concrete type of the variable 'value' JP must solve the request.getAction() expression, whereas in the second case the type of the variable is taken from the declaration.
from javaparser.
Related Issues (20)
- somtimes AssignExpr.target is wrong HOT 4
- Pattern matching for switch - JEP 441 HOT 2
- nameExpr.resolve().isField() resolves incorrectly in certain context HOT 2
- Strange error when trying to find erasure of generic type where one of two type parameters is an array HOT 2
- Unable to check equality of `ResolvedReferenceType` with a `LazyType`
- Regression from #602 HOT 6
- StackOverflowError with import static in circular dependencies HOT 1
- Question about switch statements and pattern representation HOT 4
- Children may be out of order after adding a statement HOT 4
- Jar file location for JarTypeSolver HOT 5
- Disappearing comments with LexicalPreservingPrinter HOT 1
- 【Question】Can a API be provided with a very concise judgment of whether the current variable is a local variable or a ginseng or field? HOT 2
- 【Question】Should the results of `Expression#RESOLVE` cache? HOT 1
- Record Patterns Implementation Proposal HOT 12
- Different nodes have same hashcode HOT 3
- Meaning of LanguageLevel HOT 3
- Fail to use symbol resolver HOT 8
- Arbitrary new line when refactoring HOT 4
- MethodCallExpr inside lambda in assignment expression cannot be resolved HOT 6
- JavaParser finds "." in place of first element after a yeild statement. HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javaparser.