Community
Participate
Working Groups
There are a few refactor operations that involve 'wrapping' an existing bit of code. For example, making a block of code conditional. Rather than coming up with explicit refactoring actions, it would be possible to do these if Code Templates were expanded slightly: the ability to send existing text into the template, through some variable (eg. ${selection}). These templates would be invoked by using code-assist when a block of text is selected. Eg. Template: if if (${condition}) { ${selection} } Code: ... obj.callMethod(param); [select line, ctrl+space, 'if'] ... Selecting the given line of code and invoking code- assist would (among other options) provide a list of wrapping templates. If the 'if' template is selected, the selected code is passed into the template, which is then evaluated as normal.
This is a good suggestion. We should consider this for 2.1
I like the idea. Will investigate if this can be easily done.
implemented >= 20020815 Select a range and then hit Ctrl-Space for code assist. The templates with ${cursor} are used to wrap code. The assumption is made that ${cursor} is usually used inside some kind of block. The main issue is that all the templates with the ${cursor} variable are shown, since there's no longer a "completion" (prefix matching).
changed resolution to fixed
Excellent! Can't wait to try it out. Thanks!
Finally got a new build to try this out with. Very nice. But I do see the issue regarding the missing completion. Is it possible to catch key events while the codeassist popup is displayed and use them to perform the completion? Typing while the popup is displayed usually works in this fashion (allowing you to refine the prefix).
The problem is that it's not possible in a generic way since it conflicts with ordinary code assist. In case of code assist w/o templates, you want to overwrite the selection. After all, it's supposed to be a lightweight dialog and not introduce a new editor behaviour. It would be possible to just 'remember' the old selection and use that as input, but then the user would be too suprised/scared that the selected text was lost. I agree that the current solution with listing up all the templates with ${cursor} is not elegant. I'm open to more suggestions.
i think remembering it is oan option. And a user knows what he is doing if he first selects it and then press CTRL-SPACE. but if i do this: str = str.subtring(2); and then: for[cursor] str = str.substring(2); and i select from cursor to the end. I see all the templates with a cursor. If this could be different (only templates with a cursor that starts with what is before the cursor) then the completion list is in my eyes good enough. but now i select for from the list in the above example and i get this: for for(int i=xx ect) so double time "for" johan P.S. isn't this bug a dublicate of 7213??
*** Bug 7213 has been marked as a duplicate of this bug. ***
I vote for Johan's idea: use the text _before_ the selection as the completion. This at least gives the user a chance to narrow the options. It should still have a decent work flow. Whereas before I would do: type 'if', code assist, select text, cut, paste now it becomes: type 'if', select text, code assist
partially implemented >= 20020910 (not in integration build) I changed the behaviour such that keywords in front of the selections are respected, but the selection is not remembered (some implementation issues). Please check if this is already useful...
what do you mean with: Selection is not remembered? It works fine now just as i want (i think) type: if[select everyting i want][CTRL-SPACE] only things that starts with if are there and i select one. And it does it's work. good job
What I meant was that when you start typing, the selection is gone. For example: fo<selection-begin>System.out.println();<selection-end> If I want to refine 'fo' to 'for', then the selection is lost. But if the current behaviour is sufficient, the more happy I am :)
I agree, this works great as is. Thanks!
I tried this feature. It worked the first time. I got two options for "while" when enclosing code with "while" I tried the first "while" it worked. Subsequently I tried the second while and it gave an error dialog box about collision of something (I don't remember the wording). After that I am not able to bring up wrapping help when I highlight and press ctl-space. As if the feature went dead. The code I was playing with is very simple: public class test1 { public static void main(String[] args) { String p; if p = ""; p = ""; } } I would have liked to give a more precise feedback. However, the feature just doesnot work anymore for me. I think being a new feature it may not be stable yet.
This is probably related to a new regession: bug #23425
I was hoping that when I wrap code, say, with "while", that I still should be allowed to populate the template parameters of while template as I normally do. while (enumeration.hasMoreElements()) { type element = (type) enumeration.nextElement(); } The ability to tab and fill the name of the variable (enumeration) and type above were lost.
will look into it
fixed 23425 >= 20020912
It seems stop working on M5. Code assist popup contains keywords (if, for, ... ) proposals only.
This nice feature is not working! (from M5 to 200303071024). Code assist popup for selection contains keywords (if, for, ... ) proposals only, but not templates proposals. Is this feature disabled now?
works for me what's your test case? (note that you have to select full lines)
hm... if[selection-start]System.out.println();[selection-end][cursor-here][eol] press CTRL-SPACE popup contains: - if - IftpClient - sun.net.ftp and so on... selecting "if" do nothing. there are no templates like - if - if statement - ifelse - if else statement
>(note that you have to select full lines)
What is "full lines"? My selection area is from letter 'S' to end of line. Right before i try this sample for M4 - it works fine.
Kai, fyi
I believe this works as expected - please reopen if you disagree.