Returntype of PsiMethodCallExpression is Object

Answered

Hi,

i have the following PsiMethodCallExpression:

optObj.map(x -> new AnotherObject(anotherInput)).orElse(new AnotherObject())

When i call .getType(), the returnType is Object.

optObj is of type Optional.

Is there any way to resolve Object to "AnotherObject"?

PS doing resolveMethod().getReturnType() is get "T", since this is a generic method.

0
4 comments

Push. Anyone has an idea?

0

Hi,

It should return the type from the expression.getType(). I created a similar expression:

Optional optObj = Optional.of(“12”);
optObj.map(s -> s.chars()).orElse(IntStream.empty());

and it returns IntStream:

If it doesn't work, then please share the full context: implemented code and the example code it is tested on.

fds
0

Hi, sorry for the late answer, yes you are correct that it works when running the plugin in "prod mode" via runIde gradle task.

In my tests this is resolved to Object. Do you know why this is not working as expected in my tests?

 

PS: in my tests i have a custom optional class which behaves exactly the same. I imported this optional class via 

myFixture.configureByFiles(

For the testbase i use:

LightJavaCodeInsightFixtureTestCase

 

0

Please sign in to leave a comment.