test_class.file: mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/parsers/DynamicTableNameParserTest.java
test_class.identifier: DynamicTableNameParserTest
test_case.body: @Test
      void parser() {
          DynamicTableNameParser parser = new DynamicTableNameParser();
          Map<String, ITableNameHandler> tableNameHandlerMap = new HashMap<>();
          tableNameHandlerMap.put("t_user",
                  // https://github.com/baomidou/mybatis-plus/issues/2411
                  (metaObject, sql, tableName) -> {
                      if ("t_user".equals(tableName)) {
                          return "t_user_2019";
                      }
                      return tableName;
                  });
          parser.setTableNameHandlerMap(tableNameHandlerMap);
  
          String before = "select a.* from t_user a join t_userrole b on b.userid = a.gid";
          String after = "select a.* from t_user_2019 a join t_userrole b on b.userid = a.gid";
          assertEquals(after, parser.parser(null, before).getSql());
  
          before = "select * from t_user";
          after = "select * from t_user_2019";
          assertEquals(after, parser.parser(null, before).getSql());
  
          before = "insert into t_user(id,name) values('1','zhangsan')";
          after = "insert into t_user_2019(id,name) values('1','zhangsan')";
          assertEquals(after, parser.parser(null, before).getSql());
          before = "select a.*,\n" +
                  "        (select count(1) from t_user) as cnt\n" +
                  "        from t_xxx a";
          after = "select a.*,\n" +
                  "        (select count(1) from t_user_2019) as cnt\n" +
                  "        from t_xxx a";
          assertEquals(after, parser.parser(null, before).getSql());
      }
test_case.class_method_signature: DynamicTableNameParserTest.parser()
test_case.full_signature: @Test void parser()
test_case.identifier: parser
test_case.invocations: put equals setTableNameHandlerMap assertEquals getSql parser assertEquals getSql parser assertEquals getSql parser assertEquals getSql parser
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void parser()
focal_class.declarator: tableNameHandlerMap
focal_class.modifier: private
focal_class.original_string: private Map<String, ITableNameHandler> tableNameHandlerMap;
focal_class.type: Map<String, ITableNameHandler>
focal_class.var_name: tableNameHandlerMap
focal_class.file: mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/DynamicTableNameParser.java
focal_class.identifier: DynamicTableNameParser
focal_class.interfaces: implements ISqlParser
focal_class.class_method_signature: DynamicTableNameParser.parser(MetaObject metaObject, String sql)
focal_class.full_signature: @Override public SqlInfo parser(MetaObject metaObject, String sql)
focal_class.identifier: parser
focal_class.modifiers: @Override public
focal_class.parameters: (MetaObject metaObject, String sql)
focal_class.return: SqlInfo
focal_class.signature: SqlInfo parser(MetaObject metaObject, String sql)
focal_class.class_method_signature: DynamicTableNameParser.allowProcess(MetaObject metaObject)
focal_class.full_signature: public boolean allowProcess(MetaObject metaObject)
focal_class.identifier: allowProcess
focal_class.modifiers: public
focal_class.parameters: (MetaObject metaObject)
focal_class.return: boolean
focal_class.signature: boolean allowProcess(MetaObject metaObject)
focal_method.body: @Override
      public SqlInfo parser(MetaObject metaObject, String sql) {
          // fix-issue:https://gitee.com/baomidou/mybatis-plus/issues/I1K7Q1
          // Assert.isFalse(CollectionUtils.isEmpty(tableNameHandlerMap), "tableNameHandlerMap is empty.");
          if (allowProcess(metaObject)) {
              TableNameParser parser = new TableNameParser(sql);
              List<TableNameParser.SqlToken> names = new ArrayList<>();
              parser.accept(names::add);
              StringBuilder builder = new StringBuilder();
              int last = 0;
              for (TableNameParser.SqlToken name : names) {
                  int start = name.getStart();
                  if (start != last) {
                      builder.append(sql, last, start);
                      String value = name.getValue();
                      ITableNameHandler handler = tableNameHandlerMap.get(value);
                      if (handler != null) {
                          builder.append(handler.dynamicTableName(metaObject, sql, value));
                      } else {
                          builder.append(value);
                      }
                  }
                  last = name.getEnd();
              }
              if (last != sql.length()) {
                  builder.append(sql.substring(last));
              }
              return SqlInfo.of(builder.toString());
          }
          return null;
      }
focal_method.class_method_signature: DynamicTableNameParser.parser(MetaObject metaObject, String sql)
focal_method.full_signature: @Override public SqlInfo parser(MetaObject metaObject, String sql)
focal_method.identifier: parser
focal_method.invocations: allowProcess accept getStart append getValue get append dynamicTableName append getEnd length append substring of toString
focal_method.modifiers: @Override public
focal_method.parameters: (MetaObject metaObject, String sql)
focal_method.return: SqlInfo
focal_method.signature: SqlInfo parser(MetaObject metaObject, String sql)