This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Provide ability to assign return value in code completion | ||
---|---|---|---|
Product: | java | Reporter: | tomwheeler <tomwheeler> |
Component: | Editor | Assignee: | Dusan Balek <dbalek> |
Status: | RESOLVED FIXED | ||
Severity: | blocker | CC: | matthies |
Priority: | P3 | ||
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
tomwheeler
2008-11-23 21:30:54 UTC
We could try to do something for NB 7.1. Fixed in jet-main. http://hg.netbeans.org/jet-main/rev/2963de079c0f Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/2963de079c0f User: Dusan Balek <dbalek@netbeans.org> Log: Issue #153725: Provide ability to assign return value in code completion - fixed. Tried it, it's great, thanks! Verified using a nightly build: Product Version: NetBeans IDE Dev (Build 201109120600) Java: 1.6.0_27; Java HotSpot(TM) 64-Bit Server VM 20.2-b06 System: Linux version 2.6.27-17-server running on amd64; UTF-8; en_US (nb) Thanks for implementing this! I would like to see that as the default behaviour when you press Enter. Why not? When you press Enter in Code Completion Box one of these should happen: - Generate the entire statement. or at least - Complete the code and add ';' at the end. I can't imagine a good reason not to do this by default when Enter is pressed. If you do not want to create the entire statement then you press '.', ';' or space. I am just asking to change the "ALT ENTER" shortcut just to Enter. It's more intuitive. I'm not sure if the change in the default behavior would be well accepted by majority of our users. I think it's a subject for a wider discussion. BTW - do you know if any other IDE behaves this way? I'm against changing the default behavior. There are many situations where I don't intend to code an assignment statement, and it would be a pain to always have to think of having to type a different key. Also, when you want to write multiline code like foo.getDerivedBarObject(ssdfsd, gyhujtyu) .transmogrify(target); it get's complicated because you'd want to type Enter instead of "." to generate the line break, which conflicts with the suggested semantics of Enter. "What about argument guessing? If it's "foo.getCar(someArg, someOtherArg)", then would pressing the dot key open the second CC popup, or would it go into argument editing mode (to possibly correct the guessed arguments)? I don't think this would work well. I wouldn't want to have to take care which key to press to select a completion." - by Niklas Matthies in NetCat mailing list. Ok, I understand your point. Forget the "dot automatically opens completion popup". I would be happy if Enter always define a new variable (when the method is not void), because the general design principle says that a given construct should do precisely one thing. 1) So lets suppose this: foo.get| >> Opens auto completion popup at | >> Selected method is foo.getCar(someArg, someOtherArg), and you press Enter. >> The "rename variable" dialog box appears and you give the name "car" to the variable. So you have: Car car = foo.getCar(someArg, someOtherArg); >> Then the cursor is placed at someArg so you can rename it. The cursor navigates to someOtherArg when you press Tab or Enter, and to the end of the line if you press Tab or Enter again. 2) Other case: System.out.println(foo.get|); >> Opens auto completion popup at | >> Selected method is foo.getCar(someArg, someOtherArg), and you press Enter. >> The "rename variable" dialog box appears and you give the name "car" to the variable. So you have: Car car = foo.getCar(someArg, someOtherArg); System.out.println(car); >> Then the cursor is placed at someArg so you can rename it. The cursor navigates to someOtherArg when you press Tab or Enter, and to the end of the line if you press Tab or Enter again. If you dont want this behavior press '.', ';' or space when a method is selected on the auto-completion popup window. I think this will be better for everyone. Sorry, it won't be better for me. I suspect most users wouldn't want the IDE to lock them into that "general design principle". "Also, when you want to write multiline code like foo.getDerivedBarObject(ssdfsd, gyhujtyu) .transmogrify(target); it get's complicated because you'd want to type Enter instead of "." to generate the line break, which conflicts with the suggested semantics of Enter." Suppose you start with this: foo.get| >> Displays auto-completion popup at | (when the shortcut for auto-completion is activated). >> The method "getDerivedBarObject(ssdfsd, gyhujtyu)" is selected from the auto-completion popup window. You press Enter. >> Then the "rename variable" dialog appears, you give the name "obj" to the variable. So you have this: DerivedBarObject obj = foo.getDerivedBarObject(ssdfsd, gyhujtyu); >> The cursor is placed at "ssdfsd" so you can rename it. If you press Enter or Tab the cursor navigates to "gyhujtyu". If you press Enter or Tab again the cursor goes to the end of the line. >> Ok, now the cursor is at the end of the line. You press Enter (you are not in any popup window now) so you go to the next line. Then you type this: obj.| >> and call the auto-completion popup window >> Select the "transmogrify(target)" from the popup window and press Enter. So you will have: DerivedBarObject obj = foo.getDerivedBarObject(ssdfsd, gyhujtyu); obj.transmogrify(target); >> If the "transmogrify(target)" method is void then the cursor will be placed at "target" so you can rename it. If you press Enter or Tab again the cursor goes to the end of the line. Overall, I agree with dbalek and matthies that this change of default behavior is unlikely to be accepted by the users, and I consider it undesirable (sorry). (In reply to comment #10) > "What about argument guessing? If it's "foo.getCar(someArg, someOtherArg)", > then would pressing the dot key open the second CC popup, or would it go into > argument editing mode (to possibly correct the guessed arguments)? > > I don't think this would work well. I wouldn't want to have to take care which > key to press to select a completion." - by Niklas Matthies in NetCat mailing > list. > > > Ok, I understand your point. Forget the "dot automatically opens completion > popup". > > I would be happy if Enter always define a new variable (when the method is not > void), because the general design principle says that a given construct should > do precisely one thing. > > 1) So lets suppose this: > foo.get| >> Opens auto completion popup at | > >> Selected method is foo.getCar(someArg, someOtherArg), and you press Enter. > >> The "rename variable" dialog box appears and you give the name "car" to the variable. So you have: I definitely disagree with code completion to show any dialog after pressing Enter on confirming a method call. That is sure to break user's workflow. > Car car = foo.getCar(someArg, someOtherArg); > >> Then the cursor is placed at someArg so you can rename it. The cursor navigates to someOtherArg when you press Tab or Enter, and to the end of the line if you press Tab or Enter again. > > 2) Other case: > System.out.println(foo.get|); >> Opens auto completion popup at | > >> Selected method is foo.getCar(someArg, someOtherArg), and you press Enter. > >> The "rename variable" dialog box appears and you give the name "car" to the variable. So you have: > Car car = foo.getCar(someArg, someOtherArg); > System.out.println(car); > >> Then the cursor is placed at someArg so you can rename it. The cursor navigates to someOtherArg when you press Tab or Enter, and to the end of the line if you press Tab or Enter again. Sorry, but I have to disagree completely here: such a code rewrite in this context is simply too magical and users are not going to understand and accept this behavior, especially if it is the default behavior. > > If you dont want this behavior press '.', ';' or space when a method is > selected on the auto-completion popup window. Along the matthies lines: currently, when I press Enter, I always get a sensible result. I *may* think before pressing Enter and press Alt-Enter, '.' or ';' to get a result better suited for my current situation. But if I press Enter, I always get something meaningful that I can extend. With your proposal I would *have to* think before pressing anything and choose the correct shortcut. That is a huge paradigm shift, IMO. > > I think this will be better for everyone. Sorry, but I have to disagree again: I am convinced that the proposed change of default would produce piles of complaints and would deter users from using NetBeans. "Sorry, it won't be better for me. I suspect most users wouldn't want the IDE to lock them into that 'general design principle'." The IDE will not lock the users into that principle. If you dont want that behavior you press space or dot or semicolon for example. Furthermore, Enter should insert new variable only in the first level method. Many users don't even know that "Alt Enter" shortcut exists. But ok, you decide. I think Alt Enter will be a forgotten feature. Sorry for my last comment above. I am sure Alt Enter to assign return value in code completion is really a great feature, no matter if is "Alt Enter" or just "Enter". At the end you are right. Thanks for that :) |