UNPKG

@vlocode/apex

Version:
83 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyDeclarationVisitor = void 0; const types_1 = require("../types"); const blockVisitor_1 = require("./blockVisitor"); const declarationVisitor_1 = require("./declarationVisitor"); const typeRefVisitor_1 = require("./typeRefVisitor"); /** * Represents a visitor for field declarations in Apex. */ class PropertyDeclarationVisitor extends declarationVisitor_1.DeclarationVisitor { constructor(state) { super(state ?? { name: '', type: { name: '', isSystemType: false }, sourceRange: types_1.ApexSourceRange.empty, }); } visitModifier(ctx) { if (!this.visitAccessModifier(ctx) && !this.visitPropertyModifiers(ctx)) { if (!this.state.modifiers) { this.state.modifiers = []; } this.state.modifiers.push(ctx.getText()); } return this.state; } visitPropertyModifiers(ctx) { if (ctx.STATIC()) { this.state.isStatic = true; } else if (ctx.TRANSIENT()) { this.state.isTransient = true; } else { return false; } return true; } visitPropertyDeclaration(ctx) { this.state.name = ctx.id().getText(); return this.visitChildren(ctx); } visitTypeRef(ctx) { this.state.type = new typeRefVisitor_1.TypeRefVisitor().visit(ctx) ?? this.state.type; return this.state; } visitGetter(ctx) { const getterBlock = ctx.block(); if (getterBlock) { const visitor = new blockVisitor_1.BlockVisitor({ sourceRange: types_1.ApexSourceRange.fromToken(getterBlock), }); this.state.getter = visitor.visitChildren(getterBlock); } return this.state; } visitSetter(ctx) { const setterBlock = ctx.block(); if (setterBlock) { const visitor = new SetterBlockVisitor(this.state.type, types_1.ApexSourceRange.fromToken(setterBlock)); this.state.setter = setterBlock.accept(visitor); } return this.state; } } exports.PropertyDeclarationVisitor = PropertyDeclarationVisitor; class SetterBlockVisitor extends blockVisitor_1.BlockVisitor { constructor(type, sourceRange) { super({ sourceRange, localVariables: [{ name: 'value', type, sourceRange: types_1.ApexSourceRange.empty }] }); } } //# sourceMappingURL=propertyDeclarationVisitor.js.map