Search code examples
intellij-ideaintellij-plugin

The PsiLambdaExpression in the IntelliJ IDEA


Is there a ready-made solution (utility) to get the lambda interface (Function, Predicate, Supplier, Consumer, etc.) from PsiLambdaExpression?


Solution

  • import com.intellij.psi.LambdaUtil;
    
    PsiType functionalInterfaceType = LambdaUtil.getFunctionalInterfaceType(expression, true); // expression: Map<Object, Object> map -> map.get(1)
    functionalInterfaceType.getCanonicalText(); // java.util.function.Function<? super java.util.HashMap<java.lang.Object,java.lang.Object>,?>
    

    or

    expression.getFunctionalInterfaceType();