@Test public void testGetRuleFields() { List<Field> ruleFields = Grammar.getRuleFields(MyGrammar.class); assertThat(ruleFields.size()).isEqualTo(1); }
public static List<Field> getRuleFields(Class grammarClass) { Field[] fields = grammarClass.getDeclaredFields(); List<Field> ruleFields = new ArrayList<>(); for (Field field : fields) { if (Rule.class.isAssignableFrom(field.getType())) { ruleFields.add(field); } } return ruleFields; }
Grammar { public static List<Field> getRuleFields(Class grammarClass) { Field[] fields = grammarClass.getDeclaredFields(); List<Field> ruleFields = new ArrayList<>(); for (Field field : fields) { if (Rule.class.isAssignableFrom(field.getType())) { ruleFields.add(field); } } return ruleFields; } }
Grammar { public static List<Field> getRuleFields(Class grammarClass) { Field[] fields = grammarClass.getDeclaredFields(); List<Field> ruleFields = new ArrayList<>(); for (Field field : fields) { if (Rule.class.isAssignableFrom(field.getType())) { ruleFields.add(field); } } return ruleFields; } Grammar(); }
Grammar { public static List<Field> getRuleFields(Class grammarClass) { Field[] fields = grammarClass.getDeclaredFields(); List<Field> ruleFields = new ArrayList<>(); for (Field field : fields) { if (Rule.class.isAssignableFrom(field.getType())) { ruleFields.add(field); } } return ruleFields; } Grammar(); static List<Field> getRuleFields(Class grammarClass); static List<Field> getAllRuleFields(Class grammarClass); Rule rule(GrammarRuleKey ruleKey); abstract Rule getRootRule(); }
Grammar { public static List<Field> getRuleFields(Class grammarClass) { Field[] fields = grammarClass.getDeclaredFields(); List<Field> ruleFields = new ArrayList<>(); for (Field field : fields) { if (Rule.class.isAssignableFrom(field.getType())) { ruleFields.add(field); } } return ruleFields; } Grammar(); static List<Field> getRuleFields(Class grammarClass); static List<Field> getAllRuleFields(Class grammarClass); Rule rule(GrammarRuleKey ruleKey); abstract Rule getRootRule();  }