MCPcopy Create free account
hub / github.com/Yuy0ung/YuC0de / parseClassBody

Method parseClassBody

backend/engine/java_parser.go:300–340  ·  view source on GitHub ↗
(classNode *ClassNode)

Source from the content-addressed store, hash-verified

298}
299
300func (p *Parser) parseClassBody(classNode *ClassNode) {
301 braceCount := 1
302 _ = p.pos // Was startPos
303
304 for p.pos < len(p.tokens) {
305 t := p.peek()
306
307 if t.Value == "}" {
308 braceCount--
309 p.next()
310 if braceCount == 0 {
311 classNode.EndLine = t.Line
312 break
313 }
314 continue
315 } else if t.Value == "{" {
316 braceCount++
317 p.next()
318 continue
319 }
320
321 // Try to identify methods
322 // Heuristic: Type Name ( Args ) {
323 // Or: public Type Name ( Args ) {
324 // We look ahead
325 if p.isMethodStart() {
326 method := p.parseMethod()
327 if method != nil {
328 classNode.Methods = append(classNode.Methods, method)
329 continue // parseMethod consumes the body
330 }
331 } else if p.isFieldStart() {
332 field := p.parseField()
333 if field != nil {
334 classNode.Fields = append(classNode.Fields, field)
335 }
336 } else {
337 p.next()
338 }
339 }
340}
341
342func (p *Parser) isMethodStart() bool {
343 // Look ahead for ( ... ) {

Callers 1

parseClassMethod · 0.95

Calls 6

peekMethod · 0.95
nextMethod · 0.95
isMethodStartMethod · 0.95
parseMethodMethod · 0.95
isFieldStartMethod · 0.95
parseFieldMethod · 0.95

Tested by

no test coverage detected