UNPKG

@vlocode/apex

Version:
70 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MethodDeclarationVisitor = void 0; const types_1 = require("../types"); const formalParameterVisitor_1 = require("./formalParameterVisitor"); const typeRefVisitor_1 = require("./typeRefVisitor"); const blockVisitor_1 = require("./blockVisitor"); class MethodDeclarationVisitor extends blockVisitor_1.BlockVisitor { constructor(state) { super(state ?? { name: '', returnType: { name: '', isSystemType: false }, modifiers: [], parameters: [], decorators: [], localVariables: [], refs: [], sourceRange: types_1.ApexSourceRange.empty, }); } visitBlock(ctx) { return new blockVisitor_1.BlockVisitor(this.state).visitChildren(ctx); } visitAnnotation(ctx) { if (ctx?.qualifiedName().getText().toLowerCase() === 'istest') { this.state.isTest = true; } return this.state; } visitModifier(ctx) { if (ctx.TESTMETHOD()) { this.state.isTest = true; } if (ctx.ABSTRACT()) { this.state.isAbstract = true; } if (ctx.VIRTUAL()) { this.state.isVirtual = true; } if (!this.visitAccessModifier(ctx)) { this.state.modifiers.push(ctx.getText()); } this.visitAnnotation(ctx.annotation()); return this.state; } visitMethodDeclaration(ctx) { this.state.name = ctx.id().getText(); ctx.formalParameters().accept(this); ctx.block()?.accept(this); if (ctx.VOID()) { this.state.returnType = types_1.ApexTypeRef.fromString('void'); } else { ctx.typeRef()?.accept(new typeRefVisitor_1.TypeRefVisitor(this.state.returnType)); } return this.state; } visitFormalParameters(ctx) { ctx.formalParameterList()?.formalParameter().forEach(parameter => { this.state.parameters.push(parameter.accept(new formalParameterVisitor_1.FormalParameterVisitor())); }); this.addRef(this.state.parameters.map(p => p.type), 'parameter'); return this.state; } } exports.MethodDeclarationVisitor = MethodDeclarationVisitor; //# sourceMappingURL=methodDeclarationVisitor.js.map