Finding out the inferred type in a Lambda using Psi model


I am trying to write a plugin which allows bidirection navigation between a broadcast method of a Guava eventbus wrapper and the receiving methods (marked with @Subscribe):


public class Sender {
    public void method() {
        NotificationBus.get().broadcast(new Notification());

public class Receiver {
    public void method(Notification n) {

Now I found an open source intellij plugin which does a good job of supporting Otto and EventBus and I have used their code as an example to work from.

When filtering out usages to display it uses an Instance of BusPostDecider which returns true if the usage is a method call to NotificationBus.get().broadcast() with an argument type matching the point you are navigating from:

public class BusPostDecider implements Decider {

public class LambdaSender {
    public void lambdaMethod() {
        NotificationBus.get().broadcast(new Notification());
        Stream.of(1).map(i -> new Notification()).forEach(NotificationBus.get()::broadcast);

Is there a way of working out what the incoming argument is to this method reference in the Psi tree so that the shouldShow() method can return true?

Many thanks for any help,
Jeff Philp

1 comment
Comment actions Permalink

Hi Jeff,

PsiLambdaExpression/PsiMethodReferenceExpression have types PsiLambdaType/PsiMethodReferenceType, thier super type PsiFunctionalInterface has getFunctionalInterfaceType which would return inferred type for the expression.

I didn't check  PsiConsultantImpl.getClass(expressionType) but I would suggest to check PsiUtil.resolveClassInType.



Please sign in to leave a comment.