Skip to content

Conversation

@peternhale
Copy link
Contributor

Refactor Built-in Type Management and Resolution

Summary

This PR refactors how built-in Apex types (String, Integer, List, Map, Set, etc.) are managed in the Standard Apex Library. The changes improve maintainability by separating built-in type definitions into a dedicated builtins/ folder while maintaining backward compatibility through ZIP generation that merges them into the StandardApexLibrary structure.

Changes

1. Built-in Type Source Organization

  • Restored builtins/ folder in src/resources/ with 15 essential built-in classes:

    • Primitive wrappers: Blob, Boolean, Date, DateTime, Decimal, Double, Id, Integer, Long, String, Time
    • Collection types: List, Map, Set
    • Base type: Object
  • Modified ZIP generation (scripts/generate-zip.mjs) to merge built-in classes from builtins/ into StandardApexLibrary/System/ during ZIP creation

  • Removed built-in classes from StandardApexLibrary/System/ in source (they now only exist in builtins/ and are merged during build)

2. Type Resolution Improvements

  • Fixed TypeInfoFactory to recognize primitive types before checking BuiltInTypeTables
  • Updated ResourceLoader to correctly resolve built-in types with proper URIs (apexlib://resources/StandardApexLibrary/System/...)
  • Added isBuiltinClass() method to ResourceLoader for built-in type detection
  • Simplified BuiltInTypeTables to only handle non-class types (void, null, SObjects)

3. Symbol Resolution Enhancements

  • Fixed class symbol resolution for generic types (List<T>, Map<K,V>) with empty names
  • Updated ApexSymbolManager to properly resolve built-in types from ResourceLoader
  • Improved type reference collection in ApexSymbolCollectorListener for better symbol tracking
  • Added diagnostics logging for type resolution debugging

4. Code Simplification

  • Removed BUILTIN_RESOURCE_PREFIX and related special handling
  • Unified URI scheme to use only apexlib://resources/StandardApexLibrary/
  • Simplified namespace handling by removing built-in vs StandardApexLibrary distinctions

5. Documentation and Testing

  • Updated README.md with comprehensive maintenance guidelines:
    • Critical warning about not removing built-in classes
    • Documentation of source vs ZIP file structure
    • Maintenance guidelines for adding/updating/removing classes
  • Updated tests to use System namespace instead of BUILT_IN
  • Added test fixtures for built-in type resolution
  • Fixed test expectations to use new ResourceLoader URIs

File Changes

Added Files

  • packages/apex-parser-ast/src/resources/builtins/*.cls (15 built-in type class files)
  • packages/apex-parser-ast/test/fixtures/builtin-types.cls

Modified Files

  • packages/apex-parser-ast/scripts/generate-zip.mjs - ZIP generation with built-in merge
  • packages/apex-parser-ast/src/utils/resourceLoader.ts - Built-in type detection and resolution
  • packages/apex-parser-ast/src/utils/TypeInfoFactory.ts - Primitive type recognition
  • packages/apex-parser-ast/src/utils/BuiltInTypeTables.ts - Simplified to non-class types only
  • packages/apex-parser-ast/src/symbols/ApexSymbolManager.ts - Built-in type resolution
  • packages/apex-parser-ast/src/listeners/ApexSymbolCollectorListener.ts - Enhanced type reference collection
  • packages/apex-parser-ast/src/types/symbol.ts - Type system updates
  • packages/apex-parser-ast/README.md - Maintenance documentation

Removed Files

  • packages/apex-parser-ast/src/resources/StandardApexLibrary/System/Date.cls (moved to builtins/)
  • packages/apex-parser-ast/src/resources/StandardApexLibrary/System/Time.cls (moved to builtins/)

Backward Compatibility

Fully backward compatible - The ZIP file structure remains unchanged:

  • Built-in classes appear in StandardApexLibrary/System/ in the ZIP (merged during build)
  • ResourceLoader continues to resolve built-in types using the same URI scheme
  • No breaking changes to public APIs

Testing

  • ✅ All existing tests pass
  • ✅ New tests added for built-in type resolution
  • ✅ Integration tests updated to use new ResourceLoader URIs
  • ✅ Type reference collection tests enhanced
  • ✅ Symbol resolution tests updated for generic types

Impact

Benefits

  • Better maintainability: Built-in types are clearly separated and documented
  • Improved type resolution: More accurate resolution of primitive and collection types
  • Clearer structure: Source organization matches the critical nature of built-in types
  • Documentation: Comprehensive guidelines prevent accidental removal of critical classes

Risk Assessment

  • Low risk: Changes are primarily organizational with backward-compatible ZIP structure
  • No breaking changes: All public APIs remain unchanged
  • Well tested: Comprehensive test coverage for type resolution

Migration Notes

No migration required - this is an internal refactoring that maintains backward compatibility.

@W-20479746@

…t URIs

- Add built-in type definitions (String, Integer, List, Set, Map, etc.) to builtins/System/
- Update ZIP generation to include builtins folder with proper path structure
- Fix TypeInfoFactory to recognize primitive types before checking BuiltInTypeTables
- Add isBuiltinClass() method to ResourceLoader to detect built-in classes
- Update resolveStandardApexClass to use correct URI prefix for built-in types
- Fix test expectations to use new ResourceLoader URIs instead of synthetic URIs
- Initialize ResourceLoader in resolution tests to enable built-in type resolution
- Simplify BuiltInTypeTables to only handle non-class types (void, null, SObjects)
- Merge all builtin type classes (List, Map, Set, String, etc.) from builtins/System/ into StandardApexLibrary/System/
- Remove builtins folder and all special handling for builtins vs StandardApexLibrary
- Update ZIP generation to only include StandardApexLibrary
- Remove BUILTIN_RESOURCE_PREFIX and isBuiltinClass/isBuiltinPath methods
- Simplify URI scheme to use only apexlib://resources/StandardApexLibrary/
- Update all code to use unified StandardApexLibrary structure
- Fix class symbol resolution for generic types (List<T>, Map<K,V>) with empty names
- Update tests to use System namespace instead of BUILT_IN
- Add diagnostics logging for type resolution debugging
- Update README with maintenance guidelines and warning about builtin classes
- Restore builtins/ folder in src/resources/ with 15 essential builtin classes
- Modify generate-zip.mjs to merge builtins into StandardApexLibrary/System/ during ZIP creation
- Update README.md to document the new source structure and ZIP merge process
- Remove builtin classes from StandardApexLibrary/System/ in source
- ZIP structure remains unchanged for backward compatibility with ResourceLoader
- Format long comments with proper line breaks in NamespaceUtils and TypeInfoFactory
- Simplify arrow function syntax in ProtocolHandler
- Format regex pattern for consistency
- Remove unused fs and path imports from test file
@peternhale peternhale requested a review from a team as a code owner December 10, 2025 18:17
@peternhale peternhale changed the base branch from main to tdx26/main December 10, 2025 18:20
Copy link

@kylewalke kylewalke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are the issues accessing hover info from the builtins now that they rely on the same resolution algo as the rest of the files but this can be resolved as we shore up that process. With that said, I didn't see anything code wise requiring changes here so this is approved.

@peternhale peternhale merged commit ab854f9 into tdx26/main Dec 11, 2025
13 of 16 checks passed
@peternhale peternhale deleted the phale/faux-classes-for-builtins branch December 11, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants