@Test public void testVisitIf() { If ifStmt = new If( new MatchCommunitySet(new RegexCommunitySet("^20:")), ImmutableList.of(new DeleteCommunity(new LiteralCommunity(COMM1))), ImmutableList.of(new AddCommunity(new LiteralCommunity(COMM2)))); Set<CommunityVar> result = _varCollector.visitIf(ifStmt, _baseConfig); Set<CommunityVar> expected = ImmutableSet.of( CommunityVar.from("^20:"), CommunityVar.from(COMM1), CommunityVar.from(COMM2)); assertEquals(expected, result); }
@Override public Set<CommunityVar> visitIf(If if1, Configuration arg) { ImmutableSet.Builder<CommunityVar> builder = ImmutableSet.builder(); return builder .addAll(if1.getGuard().accept(new BooleanExprVarCollector(), arg)) .addAll(visitAll(if1.getTrueStatements(), arg)) .addAll(visitAll(if1.getFalseStatements(), arg)) .build(); }
RoutePolicyStatementVarCollector implements StatementVisitor<Set<CommunityVar>, Configuration> { @Override public Set<CommunityVar> visitIf(If if1, Configuration arg) { ImmutableSet.Builder<CommunityVar> builder = ImmutableSet.builder(); return builder .addAll(if1.getGuard().accept(new BooleanExprVarCollector(), arg)) .addAll(visitAll(if1.getTrueStatements(), arg)) .addAll(visitAll(if1.getFalseStatements(), arg)) .build(); } }
RoutePolicyStatementVarCollector implements StatementVisitor<Set<CommunityVar>, Configuration> { @Override public Set<CommunityVar> visitIf(If if1, Configuration arg) { ImmutableSet.Builder<CommunityVar> builder = ImmutableSet.builder(); return builder .addAll(if1.getGuard().accept(new BooleanExprVarCollector(), arg)) .addAll(visitAll(if1.getTrueStatements(), arg)) .addAll(visitAll(if1.getFalseStatements(), arg)) .build(); }  }
RoutePolicyStatementVarCollector implements StatementVisitor<Set<CommunityVar>, Configuration> { @Override public Set<CommunityVar> visitIf(If if1, Configuration arg) { ImmutableSet.Builder<CommunityVar> builder = ImmutableSet.builder(); return builder .addAll(if1.getGuard().accept(new BooleanExprVarCollector(), arg)) .addAll(visitAll(if1.getTrueStatements(), arg)) .addAll(visitAll(if1.getFalseStatements(), arg)) .build(); }  @Override Set<CommunityVar> visitAddCommunity(AddCommunity addCommunity, Configuration arg); @Override Set<CommunityVar> visitBufferedStatement(
      BufferedStatement bufferedStatement, Configuration arg); @Override Set<CommunityVar> visitCallStatement(CallStatement callStatement, Configuration arg); @Override Set<CommunityVar> visitComment(Comment comment, Configuration arg); @Override Set<CommunityVar> visitDeleteCommunity(
      DeleteCommunity deleteCommunity, Configuration arg); @Override Set<CommunityVar> visitIf(If if1, Configuration arg); @Override Set<CommunityVar> visitPrependAsPath(PrependAsPath prependAsPath, Configuration arg); @Override Set<CommunityVar> visitSetAdministrativeCost(
      SetAdministrativeCost setAdministrativeCost, Configuration arg); @Override Set<CommunityVar> visitSetCommunities(SetCommunities setCommunities, Configuration arg); @Override Set<CommunityVar> visitSetCommunity(SetCommunity setCommunity, Configuration arg); @Override Set<CommunityVar> visitSetDefaultPolicy(
      SetDefaultPolicy setDefaultPolicy, Configuration arg); @Override Set<CommunityVar> visitSetEigrpMetric(SetEigrpMetric setEigrpMetric, Configuration arg); @Override Set<CommunityVar> visitSetIsisLevel(SetIsisLevel setIsisLevel, Configuration arg); @Override Set<CommunityVar> visitSetIsisMetricType(
      SetIsisMetricType setIsisMetricType, Configuration arg); @Override Set<CommunityVar> visitSetLocalPreference(
      SetLocalPreference setLocalPreference, Configuration arg); @Override Set<CommunityVar> visitSetMetric(SetMetric setMetric, Configuration arg); @Override Set<CommunityVar> visitSetNextHop(SetNextHop setNextHop, Configuration arg); @Override Set<CommunityVar> visitSetOrigin(SetOrigin setOrigin, Configuration arg); @Override Set<CommunityVar> visitSetOspfMetricType(
      SetOspfMetricType setOspfMetricType, Configuration arg); @Override Set<CommunityVar> visitSetTag(SetTag setTag, Configuration arg); @Override Set<CommunityVar> visitSetVarMetricType(
      SetVarMetricType setVarMetricType, Configuration arg); @Override Set<CommunityVar> visitSetWeight(SetWeight setWeight, Configuration arg); @Override Set<CommunityVar> visitStaticStatement(
      StaticStatement staticStatement, Configuration arg); Set<CommunityVar> visitAll(List<Statement> statements, Configuration arg); }
RoutePolicyStatementVarCollector implements StatementVisitor<Set<CommunityVar>, Configuration> { @Override public Set<CommunityVar> visitIf(If if1, Configuration arg) { ImmutableSet.Builder<CommunityVar> builder = ImmutableSet.builder(); return builder .addAll(if1.getGuard().accept(new BooleanExprVarCollector(), arg)) .addAll(visitAll(if1.getTrueStatements(), arg)) .addAll(visitAll(if1.getFalseStatements(), arg)) .build(); }  @Override Set<CommunityVar> visitAddCommunity(AddCommunity addCommunity, Configuration arg); @Override Set<CommunityVar> visitBufferedStatement(
      BufferedStatement bufferedStatement, Configuration arg); @Override Set<CommunityVar> visitCallStatement(CallStatement callStatement, Configuration arg); @Override Set<CommunityVar> visitComment(Comment comment, Configuration arg); @Override Set<CommunityVar> visitDeleteCommunity(
      DeleteCommunity deleteCommunity, Configuration arg); @Override Set<CommunityVar> visitIf(If if1, Configuration arg); @Override Set<CommunityVar> visitPrependAsPath(PrependAsPath prependAsPath, Configuration arg); @Override Set<CommunityVar> visitSetAdministrativeCost(
      SetAdministrativeCost setAdministrativeCost, Configuration arg); @Override Set<CommunityVar> visitSetCommunities(SetCommunities setCommunities, Configuration arg); @Override Set<CommunityVar> visitSetCommunity(SetCommunity setCommunity, Configuration arg); @Override Set<CommunityVar> visitSetDefaultPolicy(
      SetDefaultPolicy setDefaultPolicy, Configuration arg); @Override Set<CommunityVar> visitSetEigrpMetric(SetEigrpMetric setEigrpMetric, Configuration arg); @Override Set<CommunityVar> visitSetIsisLevel(SetIsisLevel setIsisLevel, Configuration arg); @Override Set<CommunityVar> visitSetIsisMetricType(
      SetIsisMetricType setIsisMetricType, Configuration arg); @Override Set<CommunityVar> visitSetLocalPreference(
      SetLocalPreference setLocalPreference, Configuration arg); @Override Set<CommunityVar> visitSetMetric(SetMetric setMetric, Configuration arg); @Override Set<CommunityVar> visitSetNextHop(SetNextHop setNextHop, Configuration arg); @Override Set<CommunityVar> visitSetOrigin(SetOrigin setOrigin, Configuration arg); @Override Set<CommunityVar> visitSetOspfMetricType(
      SetOspfMetricType setOspfMetricType, Configuration arg); @Override Set<CommunityVar> visitSetTag(SetTag setTag, Configuration arg); @Override Set<CommunityVar> visitSetVarMetricType(
      SetVarMetricType setVarMetricType, Configuration arg); @Override Set<CommunityVar> visitSetWeight(SetWeight setWeight, Configuration arg); @Override Set<CommunityVar> visitStaticStatement(
      StaticStatement staticStatement, Configuration arg); Set<CommunityVar> visitAll(List<Statement> statements, Configuration arg);  }