Pages

Monday, September 6, 2010

New Command in JDT : Open from Clipboard

This is what I used to end up doing very frequently
- copy something like String#getBytes from a bug comment
- press Ctrl+Shift+T in Eclipse
- paste the copied text Open Type dialog
- argh... no matches
- delete the method name
- open the type in an editor
- press Ctrl+O
- argh.. what was that method again?
- go back to bugzilla and read/copy the method name
- come back to Quick Outline and filter the method
- and finally reach the method

The new command opens a Java element or a Java stack trace from clipboard. If the clipboard content spans multiple lines then the it is pasted to the Java Stack Trace Console. If the clipboard content is a single line the command tries to open the matching Java element in an editor. Some examples
  • java.lang.String
  • String#getBytes
  • java.lang.String.getBytes(String, int[], int)
  • String.java:123
  • at java.lang.String.matches(String.java:1550)
  • java.lang.String.valueOf(char) line: 1456  
I use this command with a key binding of Ctrl+Shift+V. After doing a Ctrl+C the most natural thing to do is Ctrl+V so the key binding for this command should be similar. Plus Ctrl+Shift+V is also similar to Ctrl+Shift+T and Ctrl+Shift+R, making it a bit easier for me to remember it.

This command (Bug 48880) is already in nightly builds and will be in the today's I-build.

As a final note I should also mention 2 'nasty' Platform bugs that I faced while implementing this command
  • Bug 324160: [Commands] Platform should support to use the action IDs from the action set contribution in menuContribution
  • Bug 324161: menu contributions added using 'endof' should appear before contributions added using 'after'
I say nasty because in its current form the whole menu contribution, command, actionSet, action story can be very confusing...

1 comment:

  1. Hi Deepak,

    I recently discovered that you added the cool "Open from Clipboard" feature to the JDT, and I wonder, is there a reason why this is exclusive to the JDT? It seems that this could work for C, C++ or any other Eclipse editor as well... In fact, is there a reason why so many cool Eclipse features are JDT only? All other supported languages in Eclipse often feel like second-class citizens...

    Also, do you think it would be possible to make Eclipse use the same heuristics that it uses on the "Open from Clipboard" command when it opens a "file" from the command line? (i.e. that you could do "eclipse myfile.java:50" to open the file "myfile.java" and place the cursor at the line 50?

    Cheers,

    Angel

    ReplyDelete