xixiaofinland / afmt

Salesforce Apex code formatter written in Rust
MIT License
23 stars 3 forks source link

Classes implementing nested interfaces are dropped on formatting #6

Closed aheber closed 1 month ago

aheber commented 1 month ago

Classes that implement interfaces that aren't pure type_identifier lose those interfaces in the formatting.

global class Me implements namespace.InterfaceName {
}

Formats as

global class Me implements  {
}

Noting the drop of the namespace.InterfaceName from the output.

The parse tree for that part looks like this:

interfaces: interfaces [0, 16] - [0, 57]
  type_list [0, 27] - [0, 57]
    scoped_type_identifier [0, 27] - [0, 57]
      type_identifier [0, 27] - [0, 36]
      type_identifier [0, 37] - [0, 57]
aheber commented 1 month ago

A similar example but different type setup:

public with sharing class Me implements Database.Batchable<SObject> {}

Parse tree:

interfaces: interfaces [0, 29] - [0, 67]
  type_list [0, 40] - [0, 67]
    generic_type [0, 40] - [0, 67]
      scoped_type_identifier [0, 40] - [0, 58]
        type_identifier [0, 40] - [0, 48]
        type_identifier [0, 49] - [0, 58]
      type_arguments [0, 58] - [0, 67]
        type_identifier [0, 59] - [0, 66]
xixiaofinland commented 1 month ago

Fixed, and both are guarded with new tests

ClassInterface1.in ClassInterface2.in