|
19 | 19 | import com.sun.source.tree.NewClassTree; |
20 | 20 | import com.sun.source.tree.ReturnTree; |
21 | 21 | import com.sun.source.tree.Tree; |
| 22 | +import com.sun.source.tree.Tree.Kind; |
22 | 23 | import com.sun.source.tree.TypeCastTree; |
23 | 24 | import com.sun.source.tree.VariableTree; |
24 | 25 | import com.sun.source.util.TreePath; |
@@ -4601,8 +4602,8 @@ public Pair<AnnotatedTypeMirror, AnnotatedExecutableType> getFnInterfaceFromTree |
4601 | 4602 | * @return the functional interface type or an uninferred type argument |
4602 | 4603 | */ |
4603 | 4604 | private AnnotatedTypeMirror getFunctionalInterfaceType(Tree tree) { |
4604 | | - |
4605 | | - Tree parentTree = getPath(tree).getParentPath().getLeaf(); |
| 4605 | + TreePath parentPath = getPath(tree).getParentPath(); |
| 4606 | + Tree parentTree = parentPath.getLeaf(); |
4606 | 4607 | switch (parentTree.getKind()) { |
4607 | 4608 | case PARENTHESIZED: |
4608 | 4609 | return getFunctionalInterfaceType(parentTree); |
@@ -4713,8 +4714,16 @@ private AnnotatedTypeMirror getFunctionalInterfaceType(Tree tree) { |
4713 | 4714 | AnnotatedTypes.leastUpperBound(this, trueType, falseType); |
4714 | 4715 | assertIsFunctionalInterface(conditionalType.getUnderlyingType(), parentTree, tree); |
4715 | 4716 | return conditionalType; |
| 4717 | + case CASE: |
| 4718 | + // Get the functional interface type of the whole switch expression. |
| 4719 | + Tree switchTree = parentPath.getParentPath().getLeaf(); |
| 4720 | + return getFunctionalInterfaceType(switchTree); |
4716 | 4721 |
|
4717 | 4722 | default: |
| 4723 | + if (parentTree.getKind().toString().equals("YIELD")) { |
| 4724 | + TreePath pathToCase = TreePathUtil.pathTillOfKind(parentPath, Kind.CASE); |
| 4725 | + return getFunctionalInterfaceType(pathToCase.getParentPath().getLeaf()); |
| 4726 | + } |
4718 | 4727 | throw new BugInCF( |
4719 | 4728 | "Could not find functional interface from assignment context. " |
4720 | 4729 | + "Unexpected tree type: " |
|
0 commit comments