-
Notifications
You must be signed in to change notification settings - Fork 301
Refactorings
Refactoring is all about improving your code, without modifying its functionality. Rubberduck refactorings are designed to avoid breaking things, but before modifying a piece of working code, it's recommended to have unit tests that cover the affected execution paths, so that a refactoring can demonstrably not affect functionality.
Most refactoring commands are context-sensitive and will only be enabled given a valid selection and a Ready
parser state, without any modules modified since the last parse.
Some of the current refactoring tools available are:
this refactoring is currently undergoing a rewrite, and is disabled in release builds.
Select the lines of code to extract to a new procedure; this refactoring replaces the selected code with a call to the extracted method, passing in any parameters, and cleaning up any local variable declarations that are no longer needed; Rubberduck will determine whether to extract a Sub
or a Function
, preview the result and allow you to rename, reorder, or remove parameters, and determine/modify what to return.
Select an identifier - be it a variable, a constant, a procedure, an enum, a UDT member, a line label, anything with a name, including a control on a UserForm or a class or standard module, enter a new name for it, and Rubberduck automatically updates all early-bound references.
Keep in mind that Rubberduck cannot resolve late-bound references, e.g. member calls made against Object
or Variant
.
This refactoring is also available from the Code Explorer.
Select a local variable to promote to a parameter. Call sites for the containing procedure will be updated with a TODO
argument, which must then be specified for all call sites.
Select a local variable to promote to module scope.
Select a module variable (aka "field") to make Private
and expose a Property Get
and Property Let/Set
accessors for.
Moves a field that's only used in 1 procedure, into that procedure. Or moves a local variable immediately above its first use.
Pick what class members to extract into an interface; the feature creates a new class modules with stubs for the selected members, and makes the original class implement the extracted interface.
Creates stubs for all members of an unimplemented interface, so you don't need to create them manually by selecting them one by one in the code pane dropdown.
rubberduckvba.com
© 2014-2021 Rubberduck project contributors
- Contributing
- Build process
- Version bump
- Architecture Overview
- IoC Container
- Parser State
- The Parsing Process
- How to view parse tree
- UI Design Guidelines
- Strategies for managing COM object lifetime and release
- COM Registration
- Internal Codebase Analysis
- Projects & Workflow
- Adding other Host Applications
- Inspections XML-Doc
-
VBE Events