Usage { public Set<Integer> expressionLiterals(Expression expression) { return expression.match(new Expression.MatchBlock<Set<Integer>>() { @Override public Set<Integer> _case(Add x) { final Set<Integer> results = expressionLiterals(x.left); results.addAll(expressionLiterals(x.right)); return results; } @Override public Set<Integer> _case(Variable x) { return new HashSet<Integer>(); } @Override public Set<Integer> _case(IntLiteral x) { return new HashSet<Integer>(asList(x.value)); } @Override public Set<Integer> _case(LongLiteral x) { return new HashSet<Integer>(); } }); }  Function sampleFunction(); Set<Integer> expressionLiterals(Expression expression); boolean hasReturn(List<Statement> statements);  }
@Test public void testExpressionLiterals() { final Set<Integer> emptyIntegers = usage.expressionLiterals(_LongLiteral(432L)); assertTrue("Set not empty, got " + emptyIntegers, emptyIntegers.isEmpty()); final Set<Integer> twoIntegers = usage.expressionLiterals(_Add(_Variable("Foo"), _Add(_IntLiteral(2), _IntLiteral(5)))); assertTrue("Wrong number of elements in set", twoIntegers.size() == 2); assertTrue("Set didn't have 2", twoIntegers.contains(2)); assertTrue("Set didn't have 5", twoIntegers.contains(5)); }