1 /* 2 * Copyright (c) 2025 Shenzhen Kaihong Digital. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package gen; 17 18 import grammar.*; 19 import utils.Constants; 20 21 import java.util.List; 22 23 /** 24 * <h3>类名:该类用于xxx</h3> 25 * description base of generator 26 * 27 * @author Administrator 28 * date 2025-02-28 29 * @version 1.0 30 * @since 2025-02-28 31 */ 32 public class GeneratorBase { 33 /** 34 * 生成文件时追加内容 35 */ 36 public static final String GEN_APPEND = "APPEND"; 37 38 /** 39 * 生成文件时覆盖内容 40 */ 41 public static final String GEN_REPLACE = "REPLACE"; 42 43 /** 44 * 生成文件名 45 */ 46 protected String genFileName = ""; 47 48 /** 49 * 生成文件模式 50 */ 51 protected String genMode = GEN_REPLACE; 52 53 private final String headerFormat = "// Generated from %s by KaiHong ohgen %s-PLUGIN"; 54 55 /** 56 * 生成文件头内容 57 * 58 * @param filePath 文件路径 59 * @return 返回文件头 60 */ genFileHeader(String filePath)61 public String genFileHeader(String filePath) { 62 String fileHeader = ""; 63 fileHeader += String.format(headerFormat, filePath, Constants.VERSION); 64 return fileHeader; 65 } 66 67 /** 68 * 生成内容 69 * 70 * @param po 解析类 71 */ genContent(ParseObj po)72 public void genContent(ParseObj po) { 73 System.out.println("GeneratorBase: genContent"); 74 } 75 76 /** 77 * 生成文件 78 * 79 * @param filePath 文件路径 80 * @param fileName 文件名 81 */ genFile(String filePath, String fileName)82 public void genFile(String filePath, String fileName) { 83 System.out.println("GeneratorBase: path is " + filePath + ", file is " + fileName); 84 } 85 setGenMode(String genMode)86 public void setGenMode(String genMode) { 87 this.genMode = genMode; 88 } 89 90 /** 91 * 生成接口 92 * 93 * @param iol 接口列表 94 */ genInterfaceList(List<InterfaceObject> iol)95 public void genInterfaceList(List<InterfaceObject> iol) { 96 System.out.println("GeneratorBase: genInterfaceList"); 97 }; 98 99 /** 100 * 生成枚举 101 * 102 * @param eol 枚举列表 103 */ genEnumList(List<EnumObj> eol)104 public void genEnumList(List<EnumObj> eol) { 105 System.out.println("GeneratorBase: genEnumList"); 106 }; 107 108 /** 109 * 生成类 110 * 111 * @param col 类列表 112 */ genClassList(List<ClassObj> col)113 public void genClassList(List<ClassObj> col) { 114 System.out.println("GeneratorBase: genClassList"); 115 }; 116 117 /** 118 * 生成方法 119 * 120 * @param fol 方法列表 121 */ genFuncList(List<FuncObj> fol)122 public void genFuncList(List<FuncObj> fol) { 123 System.out.println("GeneratorBase: genFuncList"); 124 }; 125 126 /** 127 * 生成结构体 128 * 129 * @param sol 结构体列表 130 */ genStructList(List<StructObj> sol)131 public void genStructList(List<StructObj> sol) { 132 System.out.println("GeneratorBase: genStructList"); 133 }; 134 135 /** 136 * 生成类型 137 * 138 * @param tol 类型列表 139 */ genTypeList(List<TypeObj> tol)140 public void genTypeList(List<TypeObj> tol) { 141 System.out.println("GeneratorBase: genTypeList"); 142 }; 143 144 /** 145 * 生成联合体 146 * 147 * @param uol 联合体列表 148 */ genUnionList(List<UnionObj> uol)149 public void genUnionList(List<UnionObj> uol) { 150 System.out.println("GeneratorBase: genUnionList"); 151 }; 152 153 /** 154 * 生成变量 155 * 156 * @param pol 变量列表 157 */ genVarList(List<ParamObj> pol)158 public void genVarList(List<ParamObj> pol) { 159 System.out.println("GeneratorBase: genVarList"); 160 } 161 } 162