MethodBehavior { public Stream<ExceptionalYield> exceptionalPathYields() { return yields.stream() .filter(y -> y instanceof ExceptionalYield) .map(ExceptionalYield.class::cast); } MethodBehavior(String signature, boolean varArgs); void addYield(MethodYield yield); void createYield(ExplodedGraph.Node node); ExceptionalYield createExceptionalCheckBasedYield(SymbolicValue target, ExplodedGraph.Node node, String exceptionType, SECheck check); boolean isMethodVarArgs(); int methodArity(); List<MethodYield> yields(); Stream<ExceptionalYield> exceptionalPathYields(); Stream<HappyPathYield> happyPathYields(); void addParameter(SymbolicValue sv); List<SymbolicValue> parameters(); boolean isComplete(); void completed(); boolean isVisited(); void visited(); String signature(); void setVarArgs(boolean varArgs); List<String> getDeclaredExceptions(); void setDeclaredExceptions(List<String> declaredExceptions); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test void anonymous_classes_used_as_exception_should_be_resolved_to_supertype() { Pair<SymbolicExecutionVisitor, Sema> visitorAndSemantic = createSymbolicExecutionVisitorAndSemantic( "src/test/java/org/sonar/java/resolve/targets/TestExceptionSupertypeResolution.java"); SymbolicExecutionVisitor sev = visitorAndSemantic.a; Sema semanticModel = visitorAndSemantic.b; MethodBehavior mb = getMethodBehavior(sev, "throwException"); List<ExceptionalYield> exceptionYields = mb.exceptionalPathYields().collect(Collectors.toList()); assertThat(exceptionYields).hasSize(3); assertThat(exceptionYields.stream() .map(ey -> ey.exceptionType(semanticModel)) .map(exceptionType -> (exceptionType == null || exceptionType.isUnknown() ? null : exceptionType.fullyQualifiedName())) .collect(Collectors.toSet())) .containsOnly("org.sonar.java.resolve.targets.TestExceptionSupertypeResolution$Foo", "java.lang.Exception", null); }