Adding new methods

  1. Start adding a method by typing the following at the end of the VectorTest.java file (but before the closing brackets of the type) in the Java editor:
    public void testSizeIsThree()
    As soon as you type the method name in the editor area, the new method appears at the bottom of the Outline view.

    New method in outline view

    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, Unmatched bracket; Syntax error on token ")", "{" expected, 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 Analyze annotations while typing option located on the preference page Java > Editor under the Typing tab .

    Error annotations in overview ruler

  2. Click the Save button. The compilation unit is compiled automatically and errors appear in the Package Explorer view, in the Problems 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.

    Error propagation in package explorer

  3. Complete the new method by typing the following:

    {
      assertTrue(fFull.size() == 3);

    Note, that the closing curly bracket has been auto inserted.
  4. Save the file. Notice that the error indicators disappear since the missing bracket has been added.

Related concepts

Java editor

Related tasks

Using the Java editor

Related reference

Java Editor Preferences

Legal notices