Change Method Signature Refactoring for ActionScript and Flex
Hi all ActionScript/Flex devs! I hope you enjoy using IntelliJ IDEA and I’m sure you’ll like it even more after you try Change Method Signature refactoring! It’s amazing how it allows you to quickly restyle your methods not only by renaming them, but also by adding, reordering, renaming, and deleting parameters, changing their types and default values.
All usages and overriding method declarations will be updated automagically, so your application compiles and works the same way as before with no extra care from your side!
Let me show you how it all works.
In my code, the second print() call has an extra argument. To resolve the problem, I invoke quick-fix that suggests to change method signature so that it would match usage:
The dialog opens with the expected parameter list, so all I need is just to give new parameter meaningful name and press Refactor:
Voila! Both usages are correct!
Now time for a deeper look. Assume I work on a simple Painter application, where I have Shapes
Canvas that holds and paints shapes, and main Application component that controls everything:
At some point I may decide to introduce wireframe mode to improve performance on complex drawings. Consequently, I’ll need to have the flag in paint() method that comes from main component. Also, to draw outline of dragged shape I need to provide an offset parameter. Finally, I’d like to change existing parameter name to a more meaningful, like graphics.
I place the caret at IShape.paint() method declaration (so that implementing methods will also be handled) and invoke Refactor | Change Signature action. Dialog will open, showing current method name, return type, parameters list and signature preview:
When specifying/changing parameter type and default value, IntelliJ IDEA offers context-aware completion and error highlighting:
…so it’s easy to refactor your code, but hard to make a mistake.
After playing with parameters I came up to the following result:
Note that I don’t need to specify default value for an optional parameter offset.
Now I need to propagate newly added parameters up to the main component class. For this I just need to click Propagate Parameters button and tick needed methods in call tree:
Done! Let’s invoke the refactoring and look at the code:
You see that IntelliJ IDEA updated methods declarations and usages exactly how I needed. Note that my main component has got only one additional argument (for wireframe parameter), since I haven’t provided default value for optional offset.
As usual, this refactoring is available from UML diagram.
Improve your code with pleasure!
Subscribe to Blog updates
Thanks, we've got you!
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Profile on the Fly With the IntelliJ Profiler
At JetBrains, we believe that profiling should be simple and accessible to all developers, regardless of their level of expertise. That’s why the IntelliJ Profiler puts ease of use and seamless integration at the forefront of its mission. In previous releases, we introduced a range of features to s…
History of Gradle Delegation Process in IntelliJ IDEA
Nowadays, a build tool is an essential part of any project, and IntelliJ IDEA integrates with the majority of them. Among the most popular build tools is Gradle. We’d like to give a brief historical overview of its integration with IntelliJ IDEA and the delegation process implemented inside the I…
How to Work With Protobuf-Maven Projects in IntelliJ IDEA
Protobuf, short for Protocol Buffers, is a language-agnostic data serialization format developed by Google. It is designed to efficiently and reliably serialize structured data to communicate between different systems and programming languages. Protobuf offers a compact binary representation of data…