FlumeSpecGen { @SuppressWarnings("unchecked") public static String genEventSource(CommonTree t) throws FlumeSpecException { ASTNODE type = ASTNODE.valueOf(t.getText()); switch (type) { case SOURCE: List<CommonTree> children = new ArrayList<CommonTree>( (List<CommonTree>) t.getChildren()); String sourceType = children.remove(0).getText(); List<String> args = new ArrayList<String>(); for (CommonTree tr : children) { args.add(genArg(tr)); } return sourceType + genArgs(args, "(", ",", ")"); case MULTI: List<CommonTree> elems = (List<CommonTree>) t.getChildren(); List<String> srcs = new ArrayList<String>(); for (CommonTree tr : elems) { String src = genEventSource(tr); srcs.add(src); } return genArgs(srcs, "[", ",", "]"); default: throw new FlumeSpecException("bad parse tree! Expected source but got " + t.toStringTree()); } }  @SuppressWarnings("unchecked") static String genEventSource(CommonTree t); @SuppressWarnings("unchecked") static String genEventSink(CommonTree t); @SuppressWarnings("unchecked") static List<FlumeNodeSpec> generate(String s);  }
@Test public void testSource() throws RecognitionException, FlumeSpecException { String orig = "twitter"; CommonTree tree = FlumeBuilder.parseSource(orig); String out = FlumeSpecGen.genEventSource(tree); assertEquals(orig, out); orig = "text( \"/tmp/file\" )"; tree = FlumeBuilder.parseSource(orig); out = FlumeSpecGen.genEventSource(tree); assertEquals(orig, out); }