@Override public SemanticContext evalPrecedence(Recognizer<?, ?> parser, RuleContext parserCallStack) { boolean differs = false; List<SemanticContext> operands = new ArrayList<SemanticContext>(); for (SemanticContext context : opnds) { SemanticContext evaluated = context.evalPrecedence(parser, parserCallStack); differs |= (evaluated != context); if (evaluated == null) { // The AND context is false if any element is false return null; } else if (evaluated != NONE) { // Reduce the result by skipping true elements operands.add(evaluated); } } if (!differs) { return this; } if (operands.isEmpty()) { // all elements were true, so the AND context is true return NONE; } SemanticContext result = operands.get(0); for (int i = 1; i < operands.size(); i++) { result = SemanticContext.and(result, operands.get(i)); } return result; }