ASTVarProcessor { public static Set<String> process(ASTQueryContainer ast) throws VisitorException { final Set<String> vars = new HashSet<String>(); final ASTVarProcessorVisitor v = new ASTVarProcessorVisitor(); v.visit(ast, vars); return vars; } private  ASTVarProcessor(); static Set<String> process(ASTQueryContainer ast);  }
@Test public void testASTVar() throws Exception { final String query = "SELECT * { ?s ?p [ <name> ?n ] }"; final ASTQueryContainer ast = SyntaxTreeBuilder.parseQuery(query); final String[] expectedVars = { "n", "p", "s" }; final String[] actualVars = ASTVarProcessor.process(ast).toArray(new String[0]); Arrays.sort(actualVars); assertArrayEquals(expectedVars, actualVars); }
@Test public void testPOF() throws Exception { final String query = "SELECT * { ?s < [ <name> ?n ] }"; final ASTQueryContainer ast = SyntaxTreeBuilder.parseQuery(query); final String[] expectedVars = { "?" + SyntaxTreeBuilder.PointOfFocus, "n", "s" }; final String[] actualVars = ASTVarProcessor.process(ast).toArray(new String[0]); Arrays.sort(actualVars); assertArrayEquals(expectedVars, actualVars); }