### Question:
QueryCompilerPass2 extends AqlBaseListener { public List<I_VariableDefinition> getVariables() { return new ArrayList<>(variableStack); }  @Override void exitObjectPath(AqlParser.ObjectPathContext objectPathContext); @Override void exitSelectExpr(AqlParser.SelectExprContext selectExprContext); @Override void exitTopExpr(AqlParser.TopExprContext context); @Override void exitOrderBySeq(AqlParser.OrderBySeqContext context); @Override void exitOffset(AqlParser.OffsetContext ctx); @Override void exitLimit(AqlParser.LimitContext ctx); @Override void exitFunction(AqlParser.FunctionContext functionContext); List<I_VariableDefinition> getVariables();  }### Answer:
@Test public void getVariables() { ParseTreeWalker walker = new ParseTreeWalker(); { QueryCompilerPass2 cut = new QueryCompilerPass2(); String aql = "select e/ehr_id/value " + "from EHR e "; ParseTree tree = QueryHelper.setupParseTree(aql); walker.walk(cut, tree); List<I_VariableDefinition> variables = cut.getVariables(); assertThat(variables).size().isEqualTo(1); I_VariableDefinition variableDefinition = variables.get(0); I_VariableDefinition expected = I_VariableDefinitionHelper.build("ehr_id/value", null, "e", false, false, false); I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(variableDefinition, expected); } { QueryCompilerPass2 cut = new QueryCompilerPass2(); String aql = "select DISTINCT e/ehr_id/value " + "from EHR e "; ParseTree tree = QueryHelper.setupParseTree(aql); walker.walk(cut, tree); List<I_VariableDefinition> variables = cut.getVariables(); assertThat(variables).size().isEqualTo(1); I_VariableDefinition variableDefinition = variables.get(0); I_VariableDefinition expected = I_VariableDefinitionHelper.build("ehr_id/value", null, "e", true, false, false); I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(variableDefinition, expected); } { QueryCompilerPass2 cut = new QueryCompilerPass2(); String aql = "select e/ehr_id/value as id " + "from EHR e "; ParseTree tree = QueryHelper.setupParseTree(aql); walker.walk(cut, tree); List<I_VariableDefinition> variables = cut.getVariables(); assertThat(variables).size().isEqualTo(1); I_VariableDefinition variableDefinition = variables.get(0); I_VariableDefinition expected = I_VariableDefinitionHelper.build("ehr_id/value", "id", "e", false, false, false); I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(variableDefinition, expected); } { QueryCompilerPass2 cut = new QueryCompilerPass2(); String aql = "select e/ehr_id/value, a/context/health_care_facility/name/value, d/description[at0001]/items[at0002]/value " + "from EHR e contains COMPOSITION a[openEHR-EHR-COMPOSITION.health_summary.v1] contains ACTION d[openEHR-EHR-ACTION.immunisation_procedure.v1]"; ParseTree tree = QueryHelper.setupParseTree(aql); walker.walk(cut, tree); List<I_VariableDefinition> variables = cut.getVariables(); assertThat(variables).size().isEqualTo(3); I_VariableDefinition variableDefinition1 = variables.get(0); I_VariableDefinition expected1 = I_VariableDefinitionHelper.build("ehr_id/value", null, "e", false, false, false); I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(variableDefinition1, expected1); I_VariableDefinition variableDefinition2 = variables.get(1); I_VariableDefinition expected2 = I_VariableDefinitionHelper.build("context/health_care_facility/name/value", null, "a", false, false, false); I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(variableDefinition1, expected1); I_VariableDefinition variableDefinition3 = variables.get(1); I_VariableDefinition expected3 = I_VariableDefinitionHelper.build("description[at0001]/items[at0002]/value", null, "d", false, false, false); I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(variableDefinition1, expected1); } }