Using content assist

In this section you will use content assist to finish writing a new method. Open junit.samples.VectorTest.java file in the Java editor if you do not already have it open and select the testSizeIsThree() method in the Outline view. If the file doesn't contain such a method see Adding new methods for instructions on how to add this method.

  1. Add the following lines to the end of the method. When you type the . after v, Eclipse will show a list of possible completions. Notice how the options are narrowed down as you continue to type.

    Vector v = new Vector();
    for (int i=0; i<3; i++)
      v.addElement(new Object());
    assert

  2. With your cursor at the end of the word assert, press Ctrl+Space to activate content assist. The content assist window with a list of proposals will appear. Scroll the list to see the available choices.

    Content assist

  3. With the content assist window still active, type the letter 't' in the source code after assert (with no space in between). The list is narrowed and only shows entries starting with 'assert'. Single-click various items in the list to view any available Javadoc help for each item.

    Content assist filtered

  4. Select assertTrue(boolean) from the list and press Enter. The code for the assertTrue(boolean) method is inserted.
  5. Complete the line so that it reads as follows:

    assertTrue(v.size() == fFull.size());

  6. Save the file.

Related concepts

Java editor

Related tasks

Using the Java editor
Using content assist

Related reference

Java Content Assist
Java Editor Preferences