| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> | |
| <html> | |
| <head> | |
| <title> | |
| Adding new methods | |
| </title> | |
| <link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css"> | |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
| <meta http-equiv="Content-Style-Type" content="text/css"> | |
| </head> | |
| <body> | |
| <h1> | |
| Adding new methods | |
| </h1> | |
| <ol> | |
| <li> | |
| Start adding a method by typing the following at the end of the <em>VectorTest.java</em> file (but before the closing | |
| brackets of the type) in the Java editor:<br> | |
| <code>public void testSizeIsThree()</code><br> | |
| As soon as you type the method name in the editor area, the new method appears at the bottom of the Outline view. | |
| <p> | |
| <img src="../images/qs-13.gif" width=506 height=291 alt="New method in outline view"> | |
| </p> | |
| In addition, an error annotation (red square) appears in the overview ruler positioned on the right hand side | |
| of the editor. This error annotation indicates that the compilation unit is currently not correct. If you hover | |
| over the red square a tool tip appears, <em>Unmatched bracket</em>; <em>Syntax error on token "}", | |
| "{" expected</em>, which is correct since the method doesn't have a body yet. Note that error | |
| annotations in the editor's rulers are updated as you type. This behavior can be controlled via the preference page <strong>Java > | |
| Editor > Annotations</strong>. | |
| <p> | |
| <img src="../images/qs-13a.gif" width=428 height=222 alt="Error annotations in overview ruler"> | |
| </p> | |
| </li> | |
| <li> | |
| Click the <strong>Save</strong> button. The compilation unit is compiled automatically and errors appear in the | |
| Package Explorer view, in the Tasks view and on the vertical ruler (left hand side of the editor). In the Package | |
| Explorer view, the errors are propagated up to the project of the compilation unit containing the error. | |
| <p> | |
| <img src="../images/qs-14.gif" width=247 height=337 alt="Error propagation in package explorer"> | |
| </p> | |
| </li> | |
| <li> | |
| Complete the new method by typing the following:<br> | |
| <p><code> | |
| {<br> | |
| assertTrue(fFull.size() == 3);<br> | |
| </code></p> | |
| Note, that the closing curly bracket has been auto inserted. | |
| </li> | |
| <li> | |
| Save the file. Notice that the error indicators disappear since the | |
| missing bracket has been added. | |
| </li> | |
| </ol> | |
| <p> | |
| <img border="0" src="../images/ngrelc.gif" alt="Related concepts" width="159" height="27"> | |
| </p> | |
| <p> | |
| <a href="../concepts/concepts-7.htm">Java editor</a><br> | |
| </p> | |
| <p> | |
| <img src="../images/ngrelt.gif" alt="Related tasks" border="0" height="27" width="159"> | |
| </p> | |
| <p> | |
| <a href="../tasks/tasks-54.htm">Using the Java editor</a><br> | |
| </p> | |
| <p> | |
| <img src="../images/ngrelr.gif" width=159 height=27 alt="Related reference"> | |
| </p> | |
| <p> | |
| <a href="../reference/ref-21.htm">Java Editor Preferences</a><br> | |
| </p> | |
| <p> | |
| <a href="../hglegal2003.htm"><img src="../images/ngibmcpy2003.gif" width=324 height=14 alt="Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved." border="0"></a> | |
| </p> | |
| </body> | |
| </html> | |