Modify the Code hints feature for Eclipse and MyEclipse

Source: Internet
Author: User

The purpose of this article is to modify the code hinting capabilities of Eclipse and myeclipse so that it can help programmers write code more quickly.


The version of Eclipse version 4.2 juno,myeclipse used in this article is 10.6.



1. Set trigger key for code autocomplete prompt
Click Window-->preferences-->java-->editor-->content Assist:





"Auto activation triggers for Java" Specifies that a code hint pops up when a key is pressed. According to your own custom configuration, my configuration is ". ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ ([{,".

Earlier versions of Eclipse and MyEclipse can only specify up to 5 keys here, you want to specify more keys, you can only use the pilot exit configuration file, and then import the method after the modification. Specific methods can be consulted: http://hi.baidu.com/umltlgdcbsbilzd/item/aeb086202e194fc9a4275a67

"Auto activation Delay (ms):" This value specifies how many milliseconds to delay the popup code hint when the corresponding trigger key is pressed. The recommended setting is 100 or less, otherwise there will be a noticeable sense of pause.



2. Cancel the space on screen

When you use the code hinting feature of Eclipse and MyEclipse, when you press the SPACEBAR, Eclipse automatically displays the first item in the code hint. This is sometimes quite annoying, because most of the time we simply want to enter a space. However, this feature cannot be changed by configuration. Fortunately, Eclipse is open source, and we can still change that by modifying the source code.

Let's take eclipse as an example.

First, if you downloaded eclipse as the SDK version, you can go straight over the following paragraph.

If your eclipse is not an SDK version, it is strongly recommended that you use the SDK version of Eclipse instead, as the SDK version of Eclipse comes with all the source code. If you do not want to use the SDK version, you can also get the source code required below from http://www.eclipse.org/projects/listofprojects.php, as an example of this article, click Platform Text, Jump to the project page and click Clone on GitHub to download it to the appropriate source code.

Click Window-->show view-->other ... in the pop-up dialog box and select Plug-in development-->plug-ins:





Locate Org.eclipse.jface.text in Plug-ins, right-click, select Import As-->source Project:



Eclipse will then import the project into your workspace. Expand the project and select the Org.eclipse.jface.text.contentassist.CompletionProposalPopup.java file in the src directory:



Find the following code in the file:

Case '\ t':
E.doit= false;
Fproposalshell.setfocus ();
return false;


Change it to:

Case '\ t':
E.doit= false;
Insertselectedproposalwithmask (E.statemask);
Break ;


Then, below this code, find the following code:

If (CONTAINS (triggers, key)) {
E.doit= false;
Hide ();
Insertproposal (P, key, E.statemask, Fcontentassistsubjectcontroladapter.getselectedrange (). x);
}


Change its first line to:

If(Key!= 0x20 && key !=  = ' ; "  &&  contains (Triggers, key))  {


After the above changes, we removed the press space on the screen function, and changed it to press the TAB key screen, I believe this is in line with the habits of most people.

Save the changes. The next thing to do is to use the modified code to generate the plugin, and replace the Eclipse original plugin. Right-click on the project and select Export ... :


In the pop-up dialog box, select Plug-in development-->deployable plug-ins and fragments, and click Next:


Specify a location to save the jar package that will be exported, click Finish.



At this point, a plugins folder is generated under the path you just specified, which is the exported jar package:


The final step is to locate the plugins folder in the Eclipse installation directory and replace the original Org.eclipse.jface.text package with this newly generated jar package.

Now, when you use the code hint, pressing the SPACEBAR will not automatically screen, but instead use the TAB key to screen it.

MyEclipse's modification method is exactly the same as eclipse, replacing the jar package with the modified jar package with the MyEclipse, the location of the jar package in MyEclipse is: MyEclipse installation directory \common\plugins.

Additional attention is paid to the version of the Org.eclipse.jface.text package used in MyEclipse. As the author uses the MyEclipse 10.6 jface.text version is 3.7.2, and Eclipse Juno uses the Jface.text version of 3.8.1. The author attempts to replace the jar package with the MyEclipse's 3.7.2 with the modified version of the 3.8.1 jar package, discovering that the replaced MyEclipse cannot be started. Helpless can only re-download from the Internet 3.7.2 version of the Eclipse SDK, the inside of the Jface.text modified to replace the lane MyEclipse, and finally resolved the problem.

Modify the Code hints feature for Eclipse and MyEclipse

Related Article

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.