Introduction
A source code comment is an explanation and a description of the code. Code annotations can effectively help programmers plan for unfinished code tasks. Reduce the time cost of reading and understanding old code, the auxiliary location may produce erroneous code, etc., especially in the case of large developer flow, the good and bad of code annotation is directly related to the execution efficiency of work handover and even the time and quality control of the whole development cycle. Clear Code programming specification and detailed and accurate code annotation have become one of the important reference standards to evaluate the quality of software source code.
Eclipse is one of the best Java integrated development environments in the world, while a code template is provided to customize the code and annotation format, it only inserts predefined comments and snippets into the template by customizing the content for the first time the Java file is created and automatically inserted into the code fragment, which is relative to the lengthy code The maintenance process is far from enough. For example, to add a copyright notice to all existing source code files, Eclipse provides templates and formatting features that do not meet similar requirements. This article provides the tools to compensate for the lack of Eclipse template functionality, so that Java code and annotations can be updated at any time to the latest templates, greatly simplifying the effort to maintain code annotations and formatting.
Tools Introduction
The solution for this article is to develop a plug-in project ADD Comment and Format based on the infrastructure of the JDT (Java Development Tool) built in the Eclipse3.4 version. This plug-in adds, modifies, and formats Java source code for Java code within the workspace, as set by the code style template in the Eclipse workspace preferences.
Readers can download this plug-in project, import it as an existing project into Eclipse, run the startup item in the "Run an Application" mode, and create a new Eclipse application. You can see the ADD Comment and Format toolbar buttons (Action) appear in the new Eclipse application (see Figure 1). Clicking this button triggers the addition of Java code comments and formatting Java code events.
Figure 1. ADD Comment and Format button
Here is an example to show the execution and effectiveness of this tool.
First, reconfigure the annotation format for the preference Code template (see Figure 2). In the example in this article, add plug in development to the Code->new Java file template, delete ${filecomment}, and add comments-> in fields ${field_type template Delete return in the methods template before adding to the field name.
Figure 2. Eclipse Code Template Preferences Configuration page
Then, click the Add Comment and Format button in the toolbar (see Figure 1) to perform the formatting code and annotation functionality and view the results (see Figure 3).
Figure 3. Code comparison before and after modifying a template