@@ -11,18 +11,50 @@ import type { ErrorNode, ParseTree, RuleNode, TerminalNode } from 'antlr4ts/tree
1111
1212type ApexNature = 'Class' | 'Method' ;
1313
14+ /**
15+ * Represents a node in the Apex syntax tree.
16+ * Can be either a class or method declaration with optional child nodes.
17+ */
1418export interface ApexNode {
19+ /** The type of Apex construct (Class or Method) */
1520 nature ?: ApexNature ;
21+ /** The name of the class or method */
1622 name ?: string ;
23+ /** Child nodes (nested classes or methods) */
1724 children ?: ApexNode [ ] ;
25+ /** Line number where the node is declared */
1826 line ?: number ;
27+ /** Character position of the identifier on the line */
28+ idCharacter ?: number ;
29+ }
30+
31+ /**
32+ * Represents a class declaration node in the Apex syntax tree.
33+ * All properties are required (non-optional) to ensure complete class metadata.
34+ */
35+ export interface ApexClassNode extends ApexNode {
36+ /** Indicates this node represents a class declaration */
37+ nature : 'Class' ;
38+ /** Line number where the class is declared */
39+ line : number ;
40+ /** Character position of the class identifier on the line */
41+ idCharacter : number ;
1942}
2043
21- export type ApexMethodNode = ApexNode & {
44+ /**
45+ * Represents a method declaration node in the Apex syntax tree.
46+ * All properties are required (non-optional) to ensure complete method metadata.
47+ */
48+ export interface ApexMethodNode extends ApexNode {
49+ /** Indicates this node represents a method declaration */
2250 nature : 'Method' ;
51+ /** Comma-separated list of parameter types for the method */
2352 params : string ;
53+ /** Line number where the method is declared */
2454 line : number ;
25- } ;
55+ /** Character position of the method identifier on the line */
56+ idCharacter : number ;
57+ }
2658
2759type VisitableApex = ParseTree & {
2860 accept < Result > ( visitor : ApexParserVisitor < Result > ) : Result ;
@@ -49,22 +81,30 @@ export class ApexVisitor implements ApexParserVisitor<ApexNode> {
4981 return { children } ;
5082 }
5183
52- visitClassDeclaration ( ctx : ClassDeclarationContext ) : ApexNode {
84+ visitClassDeclaration ( ctx : ClassDeclarationContext ) : ApexClassNode {
85+ const { start } = ctx ;
86+ const ident = ctx . id ( ) ;
87+
5388 return {
5489 nature : 'Class' ,
5590 name : ctx . id ( ) . Identifier ( ) ?. toString ( ) ?? '' ,
5691 children : ctx . children ?. length ? this . visitChildren ( ctx ) . children : [ ] ,
57- line : ctx . start . line ,
92+ line : start . line ,
93+ idCharacter : ident . start . charPositionInLine ?? 0 ,
5894 } ;
5995 }
6096
6197 visitMethodDeclaration ( ctx : MethodDeclarationContext ) : ApexMethodNode {
98+ const { start } = ctx ;
99+ const ident = ctx . id ( ) ;
100+
62101 return {
63102 nature : 'Method' ,
64103 name : ctx . id ( ) . Identifier ( ) ?. toString ( ) ?? '' ,
65104 children : ctx . children ?. length ? this . visitChildren ( ctx ) . children : [ ] ,
66105 params : this . getParameters ( ctx . formalParameters ( ) ) ,
67- line : ctx . start . line ,
106+ line : start . line ,
107+ idCharacter : ident . start . charPositionInLine ,
68108 } ;
69109 }
70110
0 commit comments