RuleModelVisitor { public void visit(Object o) { if (o == null) { return; } if (o instanceof RuleModel) { visitRuleModel((RuleModel) o); } else if (o instanceof FactPattern) { visitFactPattern((FactPattern) o); } else if (o instanceof CompositeFieldConstraint) { visitCompositeFieldConstraint((CompositeFieldConstraint) o); } else if (o instanceof SingleFieldConstraintEBLeftSide) { visitSingleFieldConstraint((SingleFieldConstraintEBLeftSide) o); } else if (o instanceof SingleFieldConstraint) { visitSingleFieldConstraint((SingleFieldConstraint) o); } else if (o instanceof CompositeFactPattern) { visitCompositeFactPattern((CompositeFactPattern) o); } else if (o instanceof FreeFormLine) { visitFreeFormLine((FreeFormLine) o); } else if (o instanceof FromAccumulateCompositeFactPattern) { visitFromAccumulateCompositeFactPattern((FromAccumulateCompositeFactPattern) o); } else if (o instanceof FromCollectCompositeFactPattern) { visitFromCollectCompositeFactPattern((FromCollectCompositeFactPattern) o); } else if (o instanceof FromCompositeFactPattern) { visitFromCompositeFactPattern((FromCompositeFactPattern) o); } else if (o instanceof DSLSentence) { visitDSLSentence((DSLSentence) o); } else if (o instanceof ActionInsertFact) { visitActionFieldList((ActionInsertFact) o); } else if (o instanceof ActionUpdateField) { visitActionFieldList((ActionUpdateField) o); } else if (o instanceof ActionSetField) { visitActionFieldList((ActionSetField) o); } else if (o instanceof TemplateAware) { visitTemplateVariableAware((TemplateAware) o); } } RuleModelVisitor();  RuleModelVisitor(Map<InterpolationVariable, Integer> vars);  RuleModelVisitor(IPattern pattern,
                            Map<InterpolationVariable, Integer> vars);  RuleModelVisitor(IAction action,
                            Map<InterpolationVariable, Integer> vars);  RuleModelVisitor(IPattern[] lhs,
                            Map<InterpolationVariable, Integer> vars);  RuleModelVisitor(IAction[] rhs,
                            Map<InterpolationVariable, Integer> vars); void visit(Object o);  }
@Test public void visitTemplate() { Map<InterpolationVariable, Integer> variableMap = new HashMap<>(); RuleModelVisitor visitor = new RuleModelVisitor(variableMap); visitor.visit(new TemplateAwareIAction()); assertTrue(variableMap.containsKey(new InterpolationVariable("test", DataType.TYPE_OBJECT))); }
@Test public void testSingleFieldConstraintPredicate() { Map<InterpolationVariable, Integer> variableMap = new HashMap<>(); RuleModelVisitor visitor = new RuleModelVisitor(variableMap); SingleFieldConstraint singleFieldConstraint = new SingleFieldConstraint(); singleFieldConstraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE); singleFieldConstraint.setValue("(age != null) == \"@{param1}\""); visitor.visit(singleFieldConstraint); assertEquals(1, variableMap.keySet().size()); InterpolationVariable interpolationVariable = variableMap.keySet().iterator().next(); assertEquals("param1", interpolationVariable.getVarName()); assertEquals("Object", interpolationVariable.getDataType()); assertNull(interpolationVariable.getFactField()); assertNull(interpolationVariable.getOperator()); }