Symbol Rename Overview

From RAD Studio
Jump to: navigation, search

Go Up to Refactoring Applications Index


Renames an identifier and all references to this identifier. You can rename an identifier if its original declaration is in your project or in a project your project depends on and this project is in the same open project group. You can rename such identifiers as type-names, method-names, variables, fields, and other. In Delphi, you can rename identifiers used with generics.

The refactoring engine enforces a few renaming rules:

  • You cannot rename an identifier to a keyword.
  • You cannot rename an identifier to the same identifier name unless its case differs.
  • You cannot rename an identifier from within a dependent project when the project where the original declaration identifier resides is not open.
  • You cannot rename symbols imported by the compiler.
  • You cannot rename an overridden method when the base method is declared in a class that is not in your project.
  • You cannot rename constructors or destructors.
  • If an error results from a refactoring, the engine cannot apply the change. For example, you cannot rename an identifier to a name that already exists in the same declaration scope. If you still want to rename your identifier, you need to rename the identifier that already has the target name first, then refresh the refactoring. You can also redo the refactoring and select a new name. The refactoring engine traverses parent scopes, searching for an identifier with the same name. If the engine finds an identifier with the same name, it issues a warning.
  • Renaming identifiers used with generics, you cannot rename type parameters. This means that if you have the following declaration:
     type
       List<Item> = class
       ...
       end;

then you cannot rename the Item identifier (this is the type parameter), but you can rename the List identifier.

Renaming Methods

Renaming a method is functionally the same as renaming any other identifier. If you select a procedure name in the Code Editor, you can rename it using the Refactor > Rename command. If the procedure is overloaded, the refactoring engine renames only the overloaded procedure and only calls to the overloaded procedure. An example of this rule follows:

procedure Foo; overload;
procedure Foo(A:Integer); overload;
Foo();
Foo;
Foo(5);

If you rename the first procedure Foo in the preceding code block, the engine renames the first, third, and fourth items.

If you rename an overridden identifier, the engine renames all of the base declarations and descendent declarations, which means the original virtual identifier and all overridden symbols that exist. An example of this rule follows:

TFoo = class
  procedure Foo; virtual;
  end;
TFoo2 = class(TFoo)
  procedure Foo; override;
  end;
TFoo3 = class(TFoo)
  procedure Foo; override;
  end;
TFoo4 = class(TFoo3)
  procedure Foo; override;
  end;

Performing a rename operation on Foo renames all instances of Foo shown in the preceding code sample.

See Also