Limit Your Access to Java API for More Productivity

Simplify your work environment to get more jobs done. One example here is to limit your access to the Java API so you won’t be distracted by proposals that you don’t need.

RCP/SWT developers are facing this all the time. Point is a class in org.eclipse.swt.graphics, but it is also a class in java.awt. When you start to autocomplete, you will get at least two proposals of Point and alas, the Point from java.awt is usually put in the first place. The same with MouseListener. You will get at least one from java.awt.event and one from org.eclipse.swt.events.

You can solve the problem by limiting your access to Java API. To do this, you need to open the Build Path properties of your project.

Here you can double click the Access rules to get the Type Access Rules dialog.

Click Add… to add a rule. For the example I gave before, you may need to set rule to access type java/awt/** as forbidden. You can set many rules as you like and after that close the dialog.

Now if you try to get proposal for Point, you’ll get only the class from SWT and nothing from AWT. This will surely help you choose the right class that you intended.

3 thoughts on “Limit Your Access to Java API for More Productivity”

  1. This does this for a single project. If you want to do this for your entire workspace, enter “Type Filters” in the “type filter text” field in the Preferences dialog. Add “java.awt.*” for the same effect.

Leave a Reply

Your email address will not be published. Required fields are marked *