Tampilkan postingan dengan label eclipse. Tampilkan semua postingan
Tampilkan postingan dengan label eclipse. Tampilkan semua postingan

5 handy eclipse tips you must know

Selasa, 18 Februari 2014



It is imperative to be able to quickly navigate through your code as in commercial projects there will be thousands of artifacts. You will find more debugging tips using eclipse and other tools. The following tips are must know, and if you dont know any of this already, apply these tips and see how productive you become. Especially the control clicking shown here will help you fly through your code.


Tip #1 : Navigating between web resource files and Java classes

<div>
<s:link rendered="#{!myAccounts.viewAccounts}" reRender="myAccounts" styleClass="link-excel" view="/view/accounts/myaccounts.excel.xhtml" > Export </s:link>
......
</div>

you will often want to navigate from one xhtml or JSP page to another. In the above example to navigate to myaccounts.excel.xhtml page from your current page, highlight the text "myaccounts.excel.xhtml" in the above code and then press "ctrl+shift+r" short-cut to select the file and go to that file directly. In the above code, "myAccounts" within #{!myAccounts.viewAccounts} is an annotation attribute in the Java based backing bean. To get quickly to the backing Java bean, you will need to highlight the text "myAccounts" in the above code and the press "ctr+h" short-cut to bring up the search dialog to search for that text. The Java snippet will look like this
    
@In(value = "myAccounts")
private MyAccounts myAccountsController;

Once you have found the Java source file that has the text "myAccounts" annotated attribute, you can go directly to the method with the context helper short cut "ctrl+o" and then typing the first few charaters of the method "viewAccounts" to go to that method. This tip can be applied for other Web frameworks as well if you want to navigate between Web resources and Java source files.

The "highlighting + ctrl+h" is also handy for navigating to relevant Java or web resource file from a spring config file or any other configuration file like web.xml.

Tip #2: If you are navigating between Java source files then the code snippet below
   
public void init(Long accountId) {
logger.debug("Initialising accounts .... ");
this.selectedAccount = this.serviceFacade.getAccount(accountId, user);
this.authoriser.checkPermission(new AccountsPermission(this.user, this.selectedAccount));
...
}

may require you to navigate to "AccountsPermission" class. Highlight the "AccountsPermission" and press "F3" function key to go to that class. If you want to see the type hirarchy (i.e. its interfaces, super class, sub class, etc) press "F4". You can also highlight a varible like "selectedAccount" or a method like "checkPermission" and then press "F3" to go to that variable or method declaration.


What is even more efficient is "ctrl + clicking". All you have to do is press the ctrl key and then click on a variable or class to name to navigate to it. If a particular method has both interface and implementation, you will get a contextual option list to choose either the interface or the implementation with this control clicking.

So, both "ctrl + clicking" and "highlight  + (ctrl+shift+r or ctrl+h) are very handy commands for navigating around.


Tip 3#: If eclipse is slow in opening your files or starting up, etc it is likely that some plugins might be making it slow.

Recently I had this issue, and after removing a number of plugins, for example Atlasian Maven/Bamboo build plugins and some JBoss plugins for JSF and Seam UI development, my eclipse is much faster and responsive. 


Tip #4: If you are working on a large project with lots of modules or projects

 it is worth creating "working sets" to group relevant projects together. This will also enable you to open and close projects or modules based on "working sets". You can also search for resources based on a "working set". Google for "How to create a working set in eclipse".


Tip #5:Code assist to type less

No body wants to type a lot of code. While working on your code, you can use "ctrl + space" to auto complete some variable names, methods, class names, etc.



The above short-cut keys will help you navigate quickly through your code. Feel free to comment with other useful tips. There are more tips on

Read More..

How to escape String literal in Java using Eclipse IDE

Selasa, 11 Februari 2014

Whenever you paste String in Eclipse which contains escape characters,  to store in a String variable or just as String literal it will ask to manually escape special characters like single quotes, double quotes, forward slash etc. This problem is more prominent when you are pasting large chunk of data which contains escape characters like a whole HTML or XML file,  which contains lots of single quotes e.g. ‘’ and double quotes “” along with forward slash on closing tags. It’s very hard to manually escape all those characters and its pretty annoying as well. While writing JUnit test for XML documents, parsing and processing I prefer to have whole XML file as String in Unit test, which pointed me to look for that feature in Eclipse. As I said earlier in my post Top 30 Eclipse keyboard shortcuts, I always look to find new shortcut and settings in Eclipse which help to automate repetitive task. Thankfully Eclipse has one setting which automatically escapes text as soon as you paste it. This is even more useful if you prefer to copy file path and just paste it, Since windows uses forward slash it automatically escape that instead of you going manually and escaping them. By default this setting is disabled in Eclipse IDE and you need to enable it.
Read more »
Read More..