Extract Interface and Extract Superclass refactorings for ActionScript/Flex
ActionScript/Flex development support in IntelliJ IDEA eventually gets closer to the unbeaten level of its Java assistance. Today it’s time to Extract Interface and Superclass.
Let’s illustrate this feature on a simple example…
Assume we’re writing a graphic editor that operates with shapes. We’ve already implemented the first shape:
Also we have a
Canvas class that can operates on shapes (let’s ignore the underlines for now):
Eventually we realize that some of the members of
RectangleShape are actually valid for any shape, so we’d like to create an interface which
RectangleShape will implement.
To do that, we just need to put the caret anywhere in the source class, interface or MXML component (or select the file in Project view) and invoke corresponding action in context menu Refactoring group.
First, we choose if we simply want to
- extract interface, pull up selecte d members and leave other things as is.
Other (and more powerful) options are:
- replace all the usages of original class with the usages of super interface (where possible)
- extract implementation class, and keep all the usages untouched (where required usages will be updated keeping the code green)
Let’s stick to the option 2. Then, we enter the name and package of the interface we want to create.
Now, it’s time to choose which members should reside in there. As with the other refactorings, IDEA will notify us of an unselected member that is used by a moved one with red color.
When extracting an interface, we can contr
ol how to process methods’ ASDoc: move it along with the target, copy, or leave as is.
Our class implements an interface (
IVisible), you we pull this inheritance relation up to the super interface as well. IntelliJ IDEA will highlight interface methods with blue.
Before changing our code, IntelliJ IDEA will check for the conflicts (e.g. methods that become inaccessible after move). If found, you can review the problems in advance to be sure that no single line will get broken behind our back.
Now let’s look at the code after we press OK!
Please say welcome to the new
We see that
RectangleShape class now implements it:
And what about the usages? Here they are:
Note that usages of original class (blue underline) were replaced with interface usages where possible (orange underline). The only exception is the constructor call (red underline).
Of course, you can Extract superclass quite the same way.
PS. Needless to say, these refactorings are also accessible on UML diagram.
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…