Building a fully functional code editor based on the JFace Text framework: Part 4th

Source: Internet
Author: User

Content Assistant

Content Assistant

Content Assistant can help programmers quickly complete the code, and there is additional functionality for automatic code completion. This is critical for a code editor and is one reason many people like to write code in the IDE. But it's not as simple as that, but let's take a look at the concepts associated with JTF and content Assistant, and here's what the Java Editor's content hints look like in Eclipse:

Figure 1. Content hints for the Java editor

Let's first introduce the three concepts that appear in Figure 1:

Proposal (Proposed): Proposal represents a possible AutoComplete option, and after the programmer chooses, the code is automatically filled in to the editor.

Proposal popup (Proposed pop-up list): Proposal popup is a window to display the AutoComplete list

Additional info (additional information): Each proposal can be accompanied by some help information, called Additional info, which appears next to the pop-up list and automatically refreshes when you select a Proposal.

Tip: After the pop-up list appears, you may find that some keyboard events are being processed by the pop-up list, such as when you press the up and down arrows, which change the Proposal that is currently selected. This is because before the list pops up, the content Tip manager adds a key to the text box to verify the event handler and intercepts the keys. The specific code can refer to Contentassistant's internal class Internallistener.

These three parts are customizable, but some of them are simply a bit cumbersome. For example, we see a line below the pop-up list that prompts "press ' alt+/' to show Template proposals", which is not in the standard pop-up list, JDT customizing this part.

Add content hint support for sample code

I intend to add the following content hint support for the sample code for this article: automatically prompt for variable names that have been declared. For example, the following statement:

Listing 1. Sample statement

a = 3;
b = 4;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.