Skip to content

Rename Symbol Does not Rename References to a Class in Sibling Class Properties #6555

@no-stack-dub-sack

Description

@no-stack-dub-sack

Summary

When using the "Rename Symbol" refactor on an inner class, references to that class in sibling inner class properties do not get renamed.

Steps To Reproduce:

Paste the following code into an Apex .cls or .apex file and try to use the "Rename Symbol" (F2) refactor on the Foo class.

class RenameBugDemo {
  class FooBar {
    public String bar { get; set; }
  }

  class Baz {
    // ❌ none of the references to the `Foo` type below get renamed
    // when using the "Rename Symbol" refactor on the `Foo` class above
    public Foo foo { get; set; }
    public List<Foo> foos { get; set; }
    public Map<Foo, String> fooMap { get; set; }
    public Map<String, Foo> reverseFooMap { get; set; }

    public void doSomething(FooBar f) {
      System.debug(f.bar);
    }

    // ✅ all of the references to the `Foo` type below get renamed
    public Baz() {
      this.foo = new FooBar();
      this.foos = new List<FooBar>();
      this.fooMap = new Map<FooBar, String>();
      this.reverseFooMap = new Map<String, FooBar>();
    }
  }

  // ✅ all of the references to the `Foo` type below get renamed
  public static void main() {
    Baz b = new Baz();
    FooBar f = new FooBar();
    f.bar = 'Hello, World!';

    b.foos = new List<FooBar>();
    b.foos.add(new FooBar());
    b.foos.add(f);

    for (FooBar f : b.foos) {
      System.debug(f.bar);
    }
  }
}

Expected result

All of the references to Foo should be renamed.

Actual result

The references to Foo within the Bar class properties do not get renamed:

class RenameBugDemo {
  class Whoops {
    public String bar { get; set; }
  }

  class Baz {
    // ❌ none of the references to the `Foo` type below get renamed
    // when using the "Rename Symbol" refactor on the `Foo` class above
    public Foo foo { get; set; }
    public List<Foo> foos { get; set; }
    public Map<Foo, String> fooMap { get; set; }
    public Map<String, Foo> reverseFooMap { get; set; }

    public void doSomething(Whoops f) {
      System.debug(f.bar);
    }

    // ✅ all of the references to the `Foo` type below get renamed
    public Baz() {
      this.foo = new Whoops();
      this.foos = new List<Whoops>();
      this.fooMap = new Map<Whoops, String>();
      this.reverseFooMap = new Map<String, Whoops>();
    }
  }

  // ✅ all of the references to the `Foo` type below get renamed
  public static void main() {
    Baz b = new Baz();
    Whoops f = new Whoops();
    f.bar = 'Hello, World!';

    b.foos = new List<Whoops>();
    b.foos.add(new Whoops());
    b.foos.add(f);

    for (Whoops f : b.foos) {
      System.debug(f.bar);
    }
  }
}

Additional information

As a side-note, I'm not sure if its expected that Rename Symbol would work on top-level classes (if so I can create a separate ticket), but when using the refactor on top-level classes in .cls files, outside references to the class do not get renamed (though it is quite nice that the file is auto-renamed).

Cheers.

Salesforce Extension Version in VS Code: 64.14.10

Salesforce CLI Version: @salesforce/cli/2.85.7 win32-x64 node-v22.14.0

OS and version: Windows 11

VS Code version:
1.104.1
0f0d87fa9e96c856c5212fc86db137ac0d783365
x64

Most recent version of the extensions where this was working: Unsure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions