Create a new refactoring feature in Eclipse

Source: Internet
Author: User

1 Introduction

Refactoring plays an important role in the process of modern software development, it can reduce the workload of software developers and improve the productivity of software development. To illustrate the importance of refactoring, here's a quote from the tutorial on refactoring provided by David Carew on Developerworks:

Now, a developer's job is mostly to modify existing code, rather than to write new code. A simple modification might include adding to existing code. However, a change in the variety or expansion of the software will cause the internal structure to deteriorate. Refactoring changes the internal structure of the software to make the software easier to understand and makes it less costly to modify without changing its apparent behavior.

In the Java software development process, we have at least the following benefits by using the refactoring tools provided by eclipse:

1. The final product is more robust: our changes to the program code will be less likely to go wrong, there may be fewer missing modifications, even if there is a problem can be returned through the Undo function to the state before the refactoring.

2. Increased production efficiency. Often, a refactoring can complete multiple changes to the program's code. The most obvious example may be the rename refactoring provided by Eclipse, which is able to change all references while modifying the name.

Eclipse provides us with a variety of practical refactoring capabilities that can be of great benefit to us when we use these refactoring in the software development process. However, for the special needs of each developer, there are always some desperately needed features that are not available through refactoring. At this point, we can extend some of the eclipse platform to create refactoring that adapts to our own needs. If this refactoring happens to fit the needs of most people, we can also contribute our refactoring to the eclipse community like other Eclipse contributor.

Next, we'll show you an example of how to create a new refactoring feature in Eclipse. The refactoring we create here will be used to migrate the JUnit test cases. We know that in the current version of JUnit, a function for testing must start with the string "test" as the method name. In the upcoming JUnit 4, a "@Test" annotation is used to indicate that the method is a test method. The refactoring we're about to create will complete this migration work by adding the "@Test" tag before all the methods that start with "test". @Test annotation can also contain a timeout property to specify the maximum execution time for the method, we provide a page in the wizard for the user to choose whether to timeout properties.

2 Results Preview

In order to give the reader an intuitive feeling, we first introduce the actual operation effect of the example in this article. After reading this article, the reader friend can also successfully complete similar functions.

After starting the refactor provided by the example program, we got a three-page wizard. In the first page, the user can choose whether the timeout parameter is required, and the user can set the value of the timeout parameter.

Figure 1 Input parameters

When the user enters the parameter, we will go to the next page by clicking the Next button. The wizard will conduct initial and final condition checks and feed back the results of the check to the user. As we can see in Figure 2, the initial and final conditions are normal, so we can go to the next step.

Figure 2 Display Condition check

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.