void () { // Example from JLS 18.5.5 PsiFile file = myFixture.configureByText("Test.java", """ import java.util.function.UnaryOperator; record Mapper<T>(T in, T out) implements UnaryOperator<T> { public T apply(T arg) { return in.equals(arg) ? out : null; } } void test(UnaryOperator<? extends CharSequence> op) { if (op instanceof Mapper(var in, var out)) { boolean shorter = out.length() < in.length(); } } """); Collection<PsiPatternVariable> variables = PsiTreeUtil.collectElementsOfType(file, PsiPatternVariable.class); for (PsiPatternVariable variable : variables) { assertEquals("java.lang.CharSequence", variable.getType().getCanonicalText()); } }