@Test public void should_compile_methods() throws Exception { LexerlessGrammarBuilder b = spy(LexerlessGrammarBuilder.create()); GrammarRuleKey ruleKey = mock(GrammarRuleKey.class); Method method = DelayedRuleInvocationExpressionTest.class.getDeclaredMethod("FOO"); GrammarBuilderInterceptor grammarBuilderInterceptor = mock(GrammarBuilderInterceptor.class); when(grammarBuilderInterceptor.ruleKeyForMethod(method)).thenReturn(ruleKey); DelayedRuleInvocationExpression expression = new DelayedRuleInvocationExpression(b, grammarBuilderInterceptor, method); CompilationHandler compiler = mock(CompilationHandler.class); expression.compile(compiler); verify(b).rule(ruleKey); ArgumentCaptor<ParsingExpression> ruleExpression = ArgumentCaptor.forClass(ParsingExpression.class); verify(compiler).compile(ruleExpression.capture()); assertThat(ruleExpression.getAllValues()).hasSize(1); assertThat(((MutableParsingRule) ruleExpression.getValue()).getRuleKey()).isSameAs(ruleKey); }
@Override public Instruction[] compile(CompilationHandler compiler) { if (ruleKey == null) { ruleKey = grammarBuilderInterceptor.ruleKeyForMethod(method); if (ruleKey == null) { throw new IllegalStateException("Cannot find the rule key corresponding to the invoked method: " + toString()); } } try { b.rule(ruleKey); return compiler.compile((MutableParsingRule) ((Map) DEFINITIONS_FIELD.get(b)).get(ruleKey)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
DelayedRuleInvocationExpression implements ParsingExpression { @Override public Instruction[] compile(CompilationHandler compiler) { if (ruleKey == null) { ruleKey = grammarBuilderInterceptor.ruleKeyForMethod(method); if (ruleKey == null) { throw new IllegalStateException("Cannot find the rule key corresponding to the invoked method: " + toString()); } } try { b.rule(ruleKey); return compiler.compile((MutableParsingRule) ((Map) DEFINITIONS_FIELD.get(b)).get(ruleKey)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }
DelayedRuleInvocationExpression implements ParsingExpression { @Override public Instruction[] compile(CompilationHandler compiler) { if (ruleKey == null) { ruleKey = grammarBuilderInterceptor.ruleKeyForMethod(method); if (ruleKey == null) { throw new IllegalStateException("Cannot find the rule key corresponding to the invoked method: " + toString()); } } try { b.rule(ruleKey); return compiler.compile((MutableParsingRule) ((Map) DEFINITIONS_FIELD.get(b)).get(ruleKey)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } DelayedRuleInvocationExpression(LexerlessGrammarBuilder b, GrammarRuleKey ruleKey);  DelayedRuleInvocationExpression(LexerlessGrammarBuilder b, GrammarBuilderInterceptor grammarBuilderInterceptor, Method method); }
DelayedRuleInvocationExpression implements ParsingExpression { @Override public Instruction[] compile(CompilationHandler compiler) { if (ruleKey == null) { ruleKey = grammarBuilderInterceptor.ruleKeyForMethod(method); if (ruleKey == null) { throw new IllegalStateException("Cannot find the rule key corresponding to the invoked method: " + toString()); } } try { b.rule(ruleKey); return compiler.compile((MutableParsingRule) ((Map) DEFINITIONS_FIELD.get(b)).get(ruleKey)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } DelayedRuleInvocationExpression(LexerlessGrammarBuilder b, GrammarRuleKey ruleKey);  DelayedRuleInvocationExpression(LexerlessGrammarBuilder b, GrammarBuilderInterceptor grammarBuilderInterceptor, Method method); @Override Instruction[] compile(CompilationHandler compiler); @Override String toString(); }
DelayedRuleInvocationExpression implements ParsingExpression { @Override public Instruction[] compile(CompilationHandler compiler) { if (ruleKey == null) { ruleKey = grammarBuilderInterceptor.ruleKeyForMethod(method); if (ruleKey == null) { throw new IllegalStateException("Cannot find the rule key corresponding to the invoked method: " + toString()); } } try { b.rule(ruleKey); return compiler.compile((MutableParsingRule) ((Map) DEFINITIONS_FIELD.get(b)).get(ruleKey)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } DelayedRuleInvocationExpression(LexerlessGrammarBuilder b, GrammarRuleKey ruleKey);  DelayedRuleInvocationExpression(LexerlessGrammarBuilder b, GrammarBuilderInterceptor grammarBuilderInterceptor, Method method); @Override Instruction[] compile(CompilationHandler compiler); @Override String toString();  }