Bug 505610 - [templates] Templates for empty .java files
Summary: [templates] Templates for empty .java files
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.14 M1   Edit
Assignee: Roland Grunberg CLA
QA Contact: Roland Grunberg CLA
URL:
Whiteboard: RHT
Keywords: noteworthy, usability
Depends on:
Blocks:
 
Reported: 2016-10-10 03:51 EDT by Mickael Istria CLA
Modified: 2021-08-12 08:19 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2016-10-10 03:51:32 EDT
Assuming someone tries content-assist on an empty .java file, it would be nice to show templates such as "Create new class <fileName>", "Create new interface <fileName>", "Create new enum <fileName>"... that would scaffold a minimal content (packange and object declaration at least).
Or maybe those completion items could directly open the right New wizard without leaving opportunity to change the name and let the wizard perform the change.
Comment 1 Mickael Istria CLA 2018-01-10 03:02:22 EST
Note that if we go for templates rather than wizards, it would be also profitable to JDT-LS, while wizards wouldn't.
Comment 2 Roland Grunberg CLA 2018-01-22 15:33:43 EST
I tried out just a simple template and using the CompilationUnit to roughly fill in some values :

https://rgrunber.fedorapeople.org/empty-java-template.ogv

The problem with this being useful is all the other templates that show up for an empty .java file, not to mention the valid auto-completions for the file itself (eg. abstract, class, enum, etc.)  Maybe the video makes it seem a bit worse than it is because most users wouldn't get the jni* templates (from org.eclipse.swt.tools) but one might still need to scroll down a bit or at least know to look for that template.
Comment 3 Mickael Istria CLA 2018-01-29 10:40:57 EST
I like your proposal and the new template. However, I agree it would be best to show this template first in the list as the "most interesting" one a user would like to see on an empty file.
I suggest to split this in 2 commits/tasks: 1. author the template and make sure they're available, then 2. try to make them first proposal.
Comment 4 Roland Grunberg CLA 2018-01-29 11:06:15 EST
(In reply to Mickael Istria from comment #3)
> I like your proposal and the new template. However, I agree it would be best
> to show this template first in the list as the "most interesting" one a user
> would like to see on an empty file.
> I suggest to split this in 2 commits/tasks: 1. author the template and make
> sure they're available, then 2. try to make them first proposal.

Yeah, sounds reasonable. The tricky part is that the first proposals (eg. abstract, class, enum, ..) are not templates but actual completions in the given context (cursor not inside any block statement). I could certainly see if there's a way to order templates, but not sure how to place a template even above non-template entries. The preference page seems to allow some kind of ordering.

I'll have to look further.
Comment 5 Eclipse Genie CLA 2018-02-07 16:34:43 EST
New Gerrit change created: https://git.eclipse.org/r/116887
Comment 7 Mickael Istria CLA 2019-10-07 14:57:04 EDT
💕
Is it in any way reusable by JDT-LS ?
Comment 8 Roland Grunberg CLA 2019-10-07 16:00:38 EDT
(In reply to Mickael Istria from comment #7)
> 💕
> Is it in any way reusable by JDT-LS ?

It relies on AbstractTemplateCompletionProposalComputer which implements IJavaCompletionProposalComputer, so not yet, but I believe it can be done.
Comment 9 Noopur Gupta CLA 2019-10-09 07:57:09 EDT
Anything pending here or can it be closed for M1?
Comment 10 Roland Grunberg CLA 2019-10-09 10:07:59 EDT
Just N&N entry, but I can close and open separate bugs on any new fixes to this.
Comment 11 Roland Grunberg CLA 2019-10-09 16:40:07 EDT
Verified for 4.14 M1 using I20191009-0600 build.
Comment 12 Eclipse Genie CLA 2019-10-11 12:47:41 EDT
New Gerrit change created: https://git.eclipse.org/r/150958