Skip to content

Commit 607da25

Browse files
committed
docs: translate Chinese comments to English for clarity
1 parent 78a248b commit 607da25

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

tools/dubbogo-cli/generator/sample/hessian/generator.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (g Generator) Execute() {
7979
showLog(infoLog, "=== Generate completed [%s] ===", f)
8080
}
8181

82-
// scanFile 扫描文件内容
82+
// scanFile scans the file content
8383
// nolint
8484
func scanFile(filePath string) (file *fileInfo, err error) {
8585
var f *os.File
@@ -117,36 +117,36 @@ func scanFile(filePath string) (file *fileInfo, err error) {
117117
lineSize = len(line)
118118

119119
if file.hasInitFunc && lineSize > 0 && line[0] == funcEnd {
120-
file.initFuncEndIndex = bufferSize + 1 // 检测初始化函数结束位
120+
file.initFuncEndIndex = bufferSize + 1 // Detect the end position of the init function
121121
}
122122

123123
buffer = append(buffer, line...)
124124
buffer = append(buffer, newLine)
125125

126-
if packageRegexp.Match(line) { // 检测package位置
127-
file.packageStartIndex = bufferSize // 检测初始化函数初始位
128-
file.packageEndIndex = bufferSize + lineSize + 1 // 检测初始化函数初始位
126+
if packageRegexp.Match(line) { // Detect package position
127+
file.packageStartIndex = bufferSize // Record start position of package
128+
file.packageEndIndex = bufferSize + lineSize + 1 // Record end position of package
129129
continue
130130
}
131131

132-
if initFunctionRegexp.Match(line) { // 检测初始化函数
132+
if initFunctionRegexp.Match(line) { // Detect init function
133133
file.hasInitFunc = true
134-
file.initFuncStartIndex = bufferSize // 检测初始化函数初始位
135-
file.initFuncStatementStartIndex = bufferSize + lineSize // 初始化函数方法体初始位
134+
file.initFuncStartIndex = bufferSize // Record start position of init function
135+
file.initFuncStatementStartIndex = bufferSize + lineSize // Record start position of init function body
136136
continue
137137
}
138138

139139
if !file.hasHessianImport {
140140
rIndexList := hessianImportRegexp.FindIndex(line)
141-
if len(rIndexList) > 0 { // 检测是否已导入hessian2包
141+
if len(rIndexList) > 0 { // Detect whether hessian2 package has been imported
142142
checkStatement := line[:rIndexList[0]]
143-
passed := lineCommentRegexp.Match(checkStatement) // 是否被行注释
143+
passed := lineCommentRegexp.Match(checkStatement) // Check if it's commented out
144144
file.hasHessianImport = !passed
145145
continue
146146
}
147147
}
148148

149-
if !hessianPOJORegexp.Match(line) { // 校验是否为Hessian.POJO实现类
149+
if !hessianPOJORegexp.Match(line) { // Check whether it's a Hessian.POJO implementation class
150150
continue
151151
}
152152
structName := getStructName(line)
@@ -159,7 +159,7 @@ func scanFile(filePath string) (file *fileInfo, err error) {
159159
return
160160
}
161161

162-
// getStructName 获取Hessian.POJO实现类的类名
162+
// getStructName gets the class name of the Hessian.POJO implementation
163163
func getStructName(line []byte) []byte {
164164
r, _ := regexp.Compile(HessianPOJONameRegexp)
165165
line = r.Find(line)
@@ -169,7 +169,7 @@ func getStructName(line []byte) []byte {
169169
return nil
170170
}
171171

172-
// genRegistryPOJOStatement 生成POJO注册方法体
172+
// genRegistryPOJOStatement generates the POJO registration statement
173173
func genRegistryPOJOStatement(pojo []byte) []byte {
174174
var buffer []byte
175175
buffer = append(buffer, hessianRegistryPOJOFunctionPrefix...)
@@ -206,7 +206,7 @@ func escape(str string) string {
206206
return str
207207
}
208208

209-
// genRegistryPOJOStatements 生成POJO注册方法体
209+
// genRegistryPOJOStatements generates POJO registration statements
210210
// nolint
211211
func genRegistryPOJOStatements(file *fileInfo, initFunctionStatement *[]byte) []byte {
212212
f := file.path
@@ -216,17 +216,17 @@ func genRegistryPOJOStatements(file *fileInfo, initFunctionStatement *[]byte) []
216216
var rIndexList []int
217217
for _, name := range hessianPOJOList {
218218
statement := genRegistryPOJOStatement(name)
219-
if initFunctionStatement != nil { // 检测是否已存在注册方法体
219+
if initFunctionStatement != nil { // Check whether a registration statement already exists
220220
r, _ = regexp.Compile(escape(string(statement)))
221221
initStatement := *initFunctionStatement
222222
rIndexList = r.FindIndex(initStatement)
223223
if len(rIndexList) > 0 {
224224
i := rIndexList[0]
225225
n := lastIndexOf(initStatement, newLine, &i)
226226
checkStatement := initStatement[lastIndexOf(initStatement, newLine, &n)+1 : i]
227-
if passed, _ := regexp.Match(LineCommentRegexp, checkStatement); !passed { // 是否被行注释
227+
if passed, _ := regexp.Match(LineCommentRegexp, checkStatement); !passed { // Check if commented out
228228
showLog(infoLog, "=== Ignore POJO [%s].%s ===", f, name)
229-
continue // 忽略相同的注册操作
229+
continue // Ignore duplicate registration operations
230230
}
231231
}
232232
}
@@ -248,7 +248,7 @@ func genRegistryStatement(file *fileInfo) error {
248248

249249
offset := 0
250250

251-
if !file.hasHessianImport { // 追加hessian2导包
251+
if !file.hasHessianImport { // Add hessian2 import statement
252252
sliceIndex := file.packageEndIndex + offset
253253
var bufferClone []byte
254254
bufferClone = append(bufferClone, buffer[:sliceIndex]...)
@@ -266,13 +266,13 @@ func genRegistryStatement(file *fileInfo) error {
266266
registryPOJOStatement = genRegistryPOJOStatements(file, &initFunctionStatement)
267267
var bufferClone []byte
268268
bufferClone = append(bufferClone, buffer[:sliceIndex]...)
269-
bufferClone = append(bufferClone, registryPOJOStatement...) // 追加POJO注册方法体至init函数
269+
bufferClone = append(bufferClone, registryPOJOStatement...) // Append POJO registration statements into the init function
270270
bufferClone = append(bufferClone, buffer[sliceIndex:]...)
271271
buffer = bufferClone
272-
} else { // 追加初始化函数
272+
} else { // Add init function
273273
registryPOJOStatement = genRegistryPOJOStatements(file, nil)
274-
buffer = append(buffer, initFunctionPrefix...) // 添加init函数
275-
buffer = append(buffer, registryPOJOStatement...) // 追加POJO注册方法体至init函数
274+
buffer = append(buffer, initFunctionPrefix...) // Add init function
275+
buffer = append(buffer, registryPOJOStatement...) // Append POJO registration statements into init function
276276
buffer = append(buffer, initFunctionSuffix...)
277277
}
278278

0 commit comments

Comments
 (0)