< Day Day Up > |
Recipe 3.19 Customizing Code Assist3.19.1 ProblemCode assist is great, but some of its features don't fit your coding style. 3.19.2 SolutionCustomize code assist by selecting Window Preferences Java Code Formatter. 3.19.3 DiscussionOne common issue with code assist is that it puts curly braces on the same line as other code.
Some programmers, however, prefer that curly braces appear on separate lines: public void display( )
You can customize the location of curly braces by selecting Window Preferences Java Code Formatter, as shown in Figure 3-21. Here, check the "Insert a new line before an opening brace" checkbox, as shown in the figure; the sample code below will change to match. Figure 3-21. Customizing code assistYou also can create new code assist items in Eclipse. Say you want to create a shortcut to print the current date. To do that, select Window Preferences Java Editor Templates. In this case, we're going to create a new shortcut named datem to print the date, as shown in Figure 3-22. We'll use the code: System.out.println("${date}"); to print the date.
Figure 3-22. Creating a new shortcut for code assistNow when you type datem in your code and press Ctrl-Space, code assist will enter the code needed to print the current date, as shown in Figure 3-23. In fact, if you type d and then press Ctrl-Space, code assist lists all options that begin with the letter "d," including datem. Figure 3-23. Using the new code assist shortcutYou can customize code assist in other ways as well. For example, when you create a new Java code file, the following comment is inserted automatically: /* * Created on Feb 4, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ You can change the code in this comment by selecting Window Preferences Java Code Generation Code and Comments Code New Java Files, as shown in Figure 3-24. Then simply edit the template used to create this comment so that it reads the way you want it. Figure 3-24. Configuring code assist comments
3.19.3.1 Eclipse 3.0As you might expect, in Eclipse 3.0 you can customize code assist in numerous additional ways. For example, you can customize getter/setter code, as well as the comments used when a new field is inserted. |
< Day Day Up > |