apex-language

Parse and validate Apex source files using ANTLR-generated contexts and CompilerService listeners.

11|2|Updated Apr 4, 2025
One-click install
npx skills add https://github.com/forcedotcom/apex-language-support --skill apex-language
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: apex-language
Source: https://github.com/forcedotcom/apex-language-support/tree/main/.cursor/skills/apex-language
Command: npx skills add https://github.com/forcedotcom/apex-language-support --skill apex-language

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides concrete guidance and patterns for implementing reliable Apex parsing, listener-based analysis, and compiler-aligned validation so developers can build language-server features that match Salesforce compiler behavior.

Core Features & Use Cases

  • ANTLR grammar mapping: Explains where to find BaseApexParser and BaseApexLexer rules and how parser rule names map to generated Context classes used in listeners.
  • Listener and validator patterns: Describes extending BaseApexParserListener, scope tracking, entering/exiting rule handlers, and integrating with CompilerService to collect results, errors, and warnings.
  • Validation workflow & error codes: Documents TIER 1 and TIER 2 validator strategies, how to consult messages_en_US.properties, and the required workflow for adding and regenerating error codes.
  • Use Case: Build a validator that enforces parameter limits and reports Salesforce-consistent error codes across .cls, .trigger, and anonymous .apex files.

Quick Start

Ask the AI to parse MyClass.cls with the Apex grammar and return AST nodes, syntax errors, and suggested validator checks.

Frequently Asked Questions about apex-language

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build an Apex parser using ANTLR for Salesforce files?

To build an Apex parser, extend BaseApexParserListener and use ANTLR-generated context classes to map parser rules. This approach processes .cls, .trigger, and anonymous .apex files for listener-based syntax analysis.

How do ANTLR listener patterns work for Apex code validation?

ANTLR listener patterns work by entering and exiting rule handlers in BaseApexParserListener to track scopes. You integrate with CompilerService listeners to collect validation results, syntax errors, and warnings across Apex files.

What is the workflow for adding and regenerating Apex validator error codes?

The validator error code workflow involves consulting messages_en_US.properties and applying TIER 1 and TIER 2 validator strategies. You must follow the required workflow for adding and regenerating error codes to ensure Salesforce-consistent reporting.

Can I use this approach to validate .trigger and anonymous .apex files?

Yes, you can validate .trigger and anonymous .apex files by applying the same parsing guidance and CompilerService listener patterns used for .cls files. This ensures consistent compiler-aligned validation across all Apex file types.

What's the best way to enforce parameter limits in Apex validators?

The best way to enforce parameter limits is implementing a custom validator that extends BaseApexParserListener and reports Salesforce-consistent error codes. This leverages TIER 1 and TIER 2 validation strategies for compiler-aligned checks.