2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5 <title>4.4. Code Inspector</title><link rel="stylesheet" href="site.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="manual.html" title="Jalopy User Manual"><link rel="up" href="settings.html" title="Chapter 4. Settings"><link rel="previous" href="misc.html" title="4.3.13. Misc"><link rel="next" href="inspector-naming.html" title="4.4.2. Naming"><link rel="preface" href="dedication.html" title="Dedication"><link rel="preface" href="acknowledge.html" title="Acknowledgements"><link rel="preface" href="introduction.html" title="Introduction"><link rel="part" href="part-core.html" title="Part I. Jalopy core"><link rel="chapter" href="installation.html" title="Chapter 1. Installation"><link rel="chapter" href="build.html" title="Chapter 2. Building"><link rel="chapter" href="usage.html" title="Chapter 3. Usage"><link rel="chapter" href="settings.html" title="Chapter 4. Settings"><link rel="part" href="part-plugins.html" title="Part II. Plug-ins"><link rel="chapter" href="plugin-ant.html" title="Chapter 5. Ant Plug-in task"><link rel="chapter" href="plugin-console.html" title="Chapter 6. Console Application"><link rel="chapter" href="plugin-eclipse.html" title="Chapter 7. Eclipse Plug-in"><link rel="chapter" href="plugin-jbuilder.html" title="Chapter 8. JBuilder OpenTool"><link rel="chapter" href="plugin-jdev.html" title="Chapter 9. JDeveloper Extension"><link rel="chapter" href="plugin-jedit.html" title="Chapter 10. jEdit Plug-in"><link rel="chapter" href="plugin-netbeans.html" title="Chapter 11. NetBeans/Sun ONE Studio module"><link rel="appendix" href="dependencies.html" title="Appendix A. Library Dependencies"><link rel="appendix" href="license-bsd.html" title="Appendix B. The Jalopy BSD License"><link rel="appendix" href="license-antlr.html" title="Appendix C. ANTLR SOFTWARE RIGHTS"><link rel="appendix" href="license-apache.html" title="Appendix D. The Apache Software License, Version 1.1"><link rel="appendix" href="license-gnu.html" title="Appendix E. GNU GENERAL PUBLIC LICENSE Version 2, June 1991"><link rel="appendix" href="license-gnu-doc.html" title="Appendix F. GNU Free Documentation License Version 1.1, March 2000"><link rel="appendix" href="license-common-public.html" title="Appendix G. Common Public License Version 1.0"><link rel="appendix" href="license-sun-public.html" title="Appendix H. SUN PUBLIC LICENSE Version 1.0"><link rel="index" href="ix01.html" title="Index"><link rel="subsection" href="inspector.html#d0e5095" title="4.4.1. General"><link rel="subsection" href="inspector-naming.html" title="4.4.2. Naming">
6 <meta name="description" content="Jalopy Java Source Code Formatter Beautifier Pretty Printer">
7 <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" l gen true for "http://jalopy.sf.net" r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://jalopy.sf.net" r (n 0 s 0 v 0 l 0))'>
8 </head><body id="toppage" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table width="700" border="0" cellpadding="0" cellspacing="0" align="left"><tbody><tr><td><table cellpadding="0" cellspacing="0" width="100%" style="border:1px solid #336699"><tbody><tr><td height="16"></td></tr><tr><td bgcolor="#3399cc" height="1"></td></tr><tr style="border:none"><td style="border:none"><table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td class="logo">JALOPY</td><td class="sublogo" valign="bottom">Java Source Code Formatter Beautifier Pretty Printer</td></tr></tbody></table></td></tr><tr><td bgcolor="#3399cc" height="1"></td></tr><tr><td height="10"></td></tr><tr><td bgcolor="#ff8000" height="4"></td></tr><tr><td height="20" bgcolor="#336699" style="color:#ffffff;padding-left:10px"><a href="./index.html" class="navlink">Overview</a> •
9 <a href="./download.html" class="navlink">Download</a> •
10 <a href="./docs.html" class="navlink">Documentation</a> •
11 <a href="./plugins.html" class="navlink">Plug-ins</a> •
12 <a href="./links.html" class="navlink">Links</a> •
13 <a href="./contact.html" class="navlink">Contact</a></td></tr><tr><td height="1" bgcolor="#ffffff"></td></tr></tbody></table></td></tr><tr valign="top"><td valign="top" bgcolor="#ffffff"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td height="20" bgcolor="#faebd7" style="padding-left:15px"><a href="./features.html" class="navlink2">Features</a> |
14 <a href="./history.html" class="navlink2">History</a> |
15 <a href="./manual.html" class="navlink2">Manual</a> |
16 <a href="./faq.html" class="navlink2">FAQ</a> |
17 <a href="./api/index.html" class="navlink2">Javadoc</a></td></tr><tr><td height="20" bgcolor="#ffffff"></td></tr><tr><td bgcolor="#eeeecc" height="17" align="right" style="font-size:10px;padding-right:3px">
18 This page generated: <strong>June 8 2004</strong></td></tr></tbody></table><table border="0" width="100%" cellspacing="0" cellpadding="5"><tr><td><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4.4. Code Inspector</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="misc.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Settings</th><td width="20%" align="right"> <a accesskey="n" href="inspector-naming.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="inspector"></a>4.4. Code Inspector</h2></div></div><div></div></div><a class="indexterm" name="d0e5090"></a><p>
19 Provides the configuration facility for the Jalopy Code Inspector. The Code Inspector is
20 able to inspect Java source files for naming convention violations and possible code
22 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e5095"></a>4.4.1. General</h3></div></div><div></div></div><p>
23 Lets you control the general Code Inspector settings.
24 </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e5100"></a>4.4.1.1. General</h4></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><p>
27 Lets you enable or disable the Code Inspector as a whole.
28 </p></li></ul></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e5109"></a>4.4.1.2. Tips</h4></div></div><div></div></div><p>
29 Lets you selectively choose what actions should be performed during inspection. Moving the
30 mouse pointer onto a checkbox displays a minimalistic tooltip after a short delay.
31 </p><div class="itemizedlist"><ul type="disc"><li><p>
32 Tip 1 - Don't substitute another type for <tt class="classname">Object</tt> in the equals declaration
34 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 35.
36 Tip 2 - Object the general contract when overriding <tt class="literal">equals</tt>
38 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 25.
40 Tip 3 - Always override <tt class="literal">hashCode</tt> when you override <tt class="literal">equals</tt>
42 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 36.
44 Tip 4 - Always override <tt class="literal">equals</tt> when you override <tt class="literal">hashCode</tt>
46 Tip 5 - Always override <tt class="literal">toString</tt>
48 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 42.
50 Tip 6 - Use interfaces only to define types
52 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 89.
54 Tip 7 - Replace structures with classes
56 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 97.
58 Tip 8 - Return zero-length arrays, not <tt class="literal">nulls</tt>
60 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 134.
62 Tip 9 - Adhere to generally accepted naming conventions
64 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 165.
66 Tip 10 - Refer to objects by their interfaces
68 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 156.
70 Tip 11 - Never declare that a method "throws Exception"
72 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 181.
74 Tip 12 - Never declare that a method "throws Throwable"
76 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 181.
78 Tip 13 - Don't ignore exceptions
80 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 187.
82 Tip 14 - Never invoke <tt class="literal">wait</tt> outside a loop
84 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 201.
86 Tip 15 - Avoid thread groups
88 For a detailed discussion see <span class="emphasis"><em>Effective Java</em></span> [<a href="bi01.html#bloch01">Bloch01</a>], pp. 211.
90 Tip 16 - Document collection types
92 As long as there are no strong-typed collections (a.k.a. Java Generics support) available,
93 it is best to document the object type of the items hold by a collection.
94 </p><div class="example"><a name="inspector-tip16"></a><p class="title"><b>Example 4.154. Collection comment</b></p><table border="0" bgcolor="#E0E0E0" class="shade"><tr><td><pre class="programlisting">
95 private static final List _favorableTypes = new ArrayList(20); // List of <String>
96 </pre></td></tr></table></div><p></p></li><li><p>
97 Tip 17 - Adhere to naming convention for collection types
99 If you use comments to document the object type of collection items, you should conform to
100 a generally accepted naming convention.
102 Tip 18 - Avoid empty <tt class="literal">finally</tt> blocks
104 Empty <tt class="literal">finally</tt> blocks are of no use and may indicate programmer errors.
105 </p><div class="example"><a name="inspector-tip18"></a><p class="title"><b>Example 4.155. Empty <tt class="literal">finally</tt> block</b></p><table border="0" bgcolor="#E0E0E0" class="shade"><tr><td><pre class="programlisting">
106 Writer writer = null;
110 writer = new BufferedWriter(new FileWriter(file));
113 catch (IOException ex)
115 System.err.println("file could not be written -- " + file);
120 </pre></td></tr></table></div><p>
121 The programmer certainly wanted to close the <tt class="classname">Writer</tt> in the
122 <tt class="literal">finally</tt> block to ensure that allocated system resources will be freed.
124 Tip 19 - Avoid variable shadowing
126 Variable shadowing should be avoided on general principle, as it tends to be confusing.
128 For more information about shadowing, see the
129 Java Developer Connection (JDC) Tech Tips, October 10, 2000
130 (<a href="http://developer.java.sun.com/developer/TechTips/2000/tt1010.html#tip2" target="_top">
131 http://developer.java.sun.com/developer/TechTips/2000/tt1010.html#tip2</a>, subscription needed) or
132 section 6.3.2, "Obscured Declarations," section 7.5.2,
133 "Type-Import-on-Demand Declaration," section 8.4.6, "Inheritance, Overriding, and Hiding,"
134 section 8.4.8.5, "Example: Invocation of Hidden Class Methods," and section 14.4.3,
135 "Shadowing of Names by Local variables" in "The Java Language Specification Second
136 Edition" by Gosling, Joy, Steele, and Bracha
137 (<a href="http://java.sun.com/docs/books/jls/" target="_top">http://java.sun.com/docs/books/jls/)</a>.
139 Tip 20 - Add <span class="emphasis"><em>NOI18N</em></span> comment for String literals
141 Enabling this tip will cause warnings for all String literals without associated
142 <tt class="literal">/* NOI18N */</tt> comment.
144 Internationalizing Java applications is often done with nifty tools that use marker
145 comments to indicate that a given String literal should not be considered for localization.
146 Most tools (at least the ones I know of) use trailing single-line comments which may not
147 be very robust for processing with a formatting tool such as Jalopy. In contrast the author
148 uses a multi-line comment of the form <tt class="literal">/* NOI18N */</tt> that gets directly
149 placed after a String literal and will therefore always stuck with it.
150 </p><div class="example"><a name="inspector-tip20"></a><p class="title"><b>Example 4.156. $NON-NLS-1$ comment</b></p><table border="0" bgcolor="#E0E0E0" class="shade"><tr><td><pre class="programlisting">
151 FileDialog dialog = new FileDialog(this,
152 ResourceBundle.getBundle(BUNDLE_NAME)
153 .getString("BTN_SAVE_AS", FileDialog.SAVE); //$NON-NLS-1$
154 </pre></td></tr></table></div><p>
155 This trailing comment could be easily moved away from its String literal during formatting
156 which would result in an unwanted notice on successive internationalization runs.
157 </p><div class="example"><a name="inspector-tip20a"></a><p class="title"><b>Example 4.157. $NON-NLS-1$ comment</b></p><table border="0" bgcolor="#E0E0E0" class="shade"><tr><td><pre class="programlisting">
160 ResourceBundle.getBundle(BUNDLE_NAME).
161 getString("BTN_SAVE_AS",
162 FileDialog.SAVE); //$NON-NLS-1$
163 </pre></td></tr></table></div><p></p><div class="example"><a name="inspector-tip20b"></a><p class="title"><b>Example 4.158. NOI18N comment</b></p><table border="0" bgcolor="#E0E0E0" class="shade"><tr><td><pre class="programlisting">
166 ResourceBundle.getBundle(BUNDLE_NAME).
167 getString("BTN_SAVE_AS" /* NOI18N */),
169 </pre></td></tr></table></div><p></p></li></ul></div></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="misc.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="settings.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="inspector-naming.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4.3.13. Misc </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 4.4.2. Naming</td></tr></table></div></td></tr></table></td></tr><tr><td bgcolor="#eeeecc" height="17" style="font-size:9px;padding-left:5px"><a href="#toppage">to top</a></td></tr><tr><td height="30"><br></td></tr><tr><td height="3"></td></tr><tr><td bgcolor="#336699" height="1"></td></tr><tr><td height="1"></td></tr><tr><td bgcolor="#336699" height="16"></td></tr><tr><td bgcolor="#ff9966" height="4"></td></tr><tr><td class="footer" align="center" height="15" valign="middle">
170 Copyright © 2001-2004, <a class="footer" href="./contact.html">Marco Hunsicker</a>. All rights reserved. Hosted by <a href="http://sourceforge.net">SourceForge.net</a></td></tr></tbody></table><img src="http://sourceforge.net/sflogo.php?group_id=45216&type=1" width="1" height="1" border="0" hspace="0" vspace="0" alt=""></body></html>