Giter Site home page Giter Site logo

Comments (9)

mukulbindal avatar mukulbindal commented on June 18, 2024 1

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.

mukulbindal avatar mukulbindal commented on June 18, 2024

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.

jlerbsc avatar jlerbsc commented on June 18, 2024

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.

mukulbindal avatar mukulbindal commented on June 18, 2024

@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.

jlerbsc avatar jlerbsc commented on June 18, 2024

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.

mukulbindal avatar mukulbindal commented on June 18, 2024

@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.

jlerbsc avatar jlerbsc commented on June 18, 2024

This is curious because the getAction method does not exist in the source code being analysed.

from javaparser.

mukulbindal avatar mukulbindal commented on June 18, 2024

@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.

jlerbsc avatar jlerbsc commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.