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.
I am attaching a patch with some updates to the Java abbreviations. This is driven by two reasons: - Some abbreviations need updating to take advantage of new editor features in 6.0 (for example, there is no reason 'wh' should only insert 'while(' when it can do the whole block and template the expression) - Now that Tab is the default key for expanding abbreviations, there is much more flexibility for what characters can be used for abbreviations - we no longer have the "we'return" problem that word endings will be expanded as abbreviations Here is a summary of the changes: Modified: tw (throw an existing throwable) now tries to find a Throwable instance in scope twn (throw a new exception) defaults to IllegalStateException, which is templated. wh (previously generated "while (") now generates a full while loop [this probably means we should delete whilexp, which does something similar but uses Boolean not boolean with ugly results]. sw (previously generated "switch(") now generates a full switch statement with one empty case statement and a default case of throwing an AssertionError, and looks for a java.lang.Enum for its argument Added: cs - generates an individual case statement 2arr - create an array from a collection in scope 2arl - create an ArrayList from an array in scope 2l - create a List from an array in scope 2s - create a Set from an array in scope sort - sort a collection in scope asort - sort an array in scope csort - create a copy of a collection in scope and sort it map - create a HashMap in a new variable of type Map set - create a new HashSet in a new variable of type Set arl - create a new ArrayList in a new variable of type List ll - create a new LinkedList in a new variable of type List spl - invoke String.split() on a string in scope rn - return null; ps - private static Ps - public static pf - private final Pf - public final m - generate a method skeleton, with templated access, return type, name and args Pfm - generate a public method skeleton, with return type, method name and args templated pfm - same as Pfm but private prfm - same as Pfm but protected, not public prfm - same as Pfm but protected, not public pm - same as m but access is private pcm - Create an inner class with a method skeleton NetBeans-specific added templates - would be nice if apisupport could deliver them, but they are harmless enough here: Nbb - NbBundle.getMessage (getClass(), "${key}"); Nbbb - Same as nbb, but with additional arguments for formatted strings lkp - get an object from a Lookup in scope Lkp - get an object from the default lookup lka - get a collection of objects from a Lookup in scope Lka - get a collection of objects from a Lookup in scope lkr - get a Lookup.Result from a Lookup in scope Lkr - same as lkr but using the default lookup lko - Lookup an object on a Lookup.Provider in scope Given that these do not involve code changes, it would be nice to try to get them into 6.0 or a java editor update shortly after.
Created attachment 49328 [details] Patch to defaultAbbrevs.xml
I'm little bit scared of all those two letters templates. For tab is probably OK but when someone switches back to space ...
Well, which is more valuable - the productivity a lot of users get from very useful short templates, or the ability to switch back to space for long time users? I don't know that there is a right answer to that question - certainly not one that will make 100% of people happy.
I think will all the new editing functionality, people will alter their workflow anyway. People who are experienced enough to go and actually modify the expansion key will also be savvy enough to go and rip out the templates that they don't intend to expand. Now that we're no longer expanding on space, we can put some more useful names on some of the abbreviations. "trycatch" should be renamed to just "try". We should have a "class" abbreviation which inserts a class skeleton. "iff" should be renamed to "if". Also, here's my own contribution: the following two snippets were used at the JavaOne keynote demo. "jpaem" -> inserts a JPA (Java Persistence Architecture) entity manager lookup. "jpaq" -> inserts a JPA Query Both take advantage of the semantic parameters available to code templates to find entity managers in scope etc. <abbrevs> <abbrev key="jpaq" xml:space="preserve">${Query default="Query" editable="false" type="javax.persistence.Query"} ${query newVarName} = ${em instanceof="javax.persistence.EntityManager"}.createQuery("select ${p} from ${table} ${p}");</abbrev> <abbrev key="jpaem" xml:space="preserve">${EntityManager default="EntityManager" editable="false" type="javax.persistence.EntityManager"} ${entityManager newVarName} = ${Persistence default="Persistence" editable="false" type="javax.persistence.Persistence"}.createEntityManagerFactory("${persistenceUnit}").createEntityManager();</abbrev> </abbrevs>
> "jpaem" -> inserts a JPA (Java Persistence Architecture) entity manager lookup. One thing I was thinking about: It would be nice if a project (or more specifically, a web framework on a web project) could provide some custom templates. For example, I can think of tons of useful templates for Wicket - since doing almost anything involves writing one inner class that overrides one method. But having all of this stuff defined by default would start to get pretty big. Food for thought?
Btw, also of interest: issue 116451, and one other issue I filed, regarding being able to specify the generic parameters of an object in scope (i.e. if a template that creates a HashSet from a List <String> should auto-detect <String> - no way to do this currently).
I'm interested in that myself. The Ruby module registers 160 code templates. But for RSpec development, I have a separate module which adds some functionality - and 60 more code templates. I was trying to "add" these templates into the mimetype but recently realized they weren't adding, they were -replacing- the base templates. I don't know if there's way to add in templates for a mimetype; what is "Defaults" in the below registration, and what happens if I supply something else? Are code templates themed? <folder name="CodeTemplates"> <folder name="Defaults"> <file name="codetemplates.xml" url="codetemplates.xml"> </file> </folder> </folder>
After chatting with Hrebejk, we settled on the following ones as being viable for 6.0: map (rename to hmap) - create a HashMap in a new variable of type Map set - (rename to hset) - create a new HashSet in a new variable of type Set arl - create a new ArrayList in a new variable of type List ll - create a new LinkedList in a new variable of type List spl - invoke String.split() on a string in scope rn - return null; ps - private static Ps - public static pf - private final Pf - public final I will attach a patch with only these, and a patch for apisupport for the NB-specific ones.
BTW, a note and a correction. Tor: You can have a module add additional code templates - just add your own XML file to the CodeTemplates/Defaults folder for your MIME type. If it does not duplicate the original file's name, it should get picked up. Correction: The NbBundle abbreviations are nbb and nbbb (probably will not include the latter), not Nbb, etc.
As mentioned by Hrebejk already I use SPACE for expansion too. I'm wondering whether "ll" will have enough usage (I personally use LinkedList much less often than ArrayList since it does not support binary searches efficiently). I hope that "rn" is not commonly used variable name :) Due to my SPACE expansion I would also prefer "hmap" and "hset" over "map" and "set".
I'm fine with the change for 6.0. A general note about abbreviations. We should use simple abbreviations and don't look at potential problems caused to users who use the space key for expansion. There's already many abbreviation that are problematic for space expansion and we really want to make the default behavior as productive as possible. I also support modifying the simple abbreviations as proposed by Tim (tw, wh, ...) and simplification as proposed by Tor (iff -> if, ...). Probably not for 6.0 as it's too late.
moving opened issues from TM <= 6.1 to TM=Dev
Any chance of doing this for 7.0?
Created attachment 84916 [details] Updated diff for 6.7 w/ new file layout and improvements
Unless somebody in my management chain screams extremely loudly in the next two days, I am simply going to apply this patch. We've discussed and agreed that it would be a good idea for 6.5, then for 6.7, and it is still not there. These added and improved additions provide huge convenience to users, and as a side effect, make them less likely to be happy in any other IDE once they know them. This should not have taken two years to do.
Created attachment 84950 [details] Final diff w/ nb-development-specific changes removed - they can go in apisupport
Sounds good Tim, but... is there a plan for getting these added to the documentation?
Well, that's a good question. I don't know if docs currently generates the keyboard shortcuts PDF, or if it's done manually. I'm happy to describe the additions; actually, the diff, if you're willing to read it, is pretty self-explanatory. I added a few since the original patch; also the NetBeans-specific ones are now in a separate issue for apisupport. Changes: sw - existed before; now generates a complete skeleton switch statement, not just the word "switch" cs - generates skeleton switch but without default: throw new AssertionError or initial case statement 2arr - converts a collection to an array in a new variable; will automatically use the first collection in scope if there is one 2l - converts an array to a list using Arrays.asList() in a new variable 2arl - converts an array to a mutable list in a new variable - i.e. List<Foo> l = new ArrayList<Foo>(Arrays.asList(arr)); 2s - converts an array to a Set using Arrays.asList() and HashSet() asort - calls Arrays.sort() on the nearest array in scope csort - calls Collections.sort() on the nearest list in scope map - create a new typed hashmap assigned to a local variable set - create a new typed hashset assigned to a local variable ll - create a new typed LinkedList al - create a new typed ArrayList rn - return null; f - final ps - private static Ps - public static pf - private final Pf - public final spl - call iterate over String.split() on a string in scope with default (settable) pattern "," n - same as existing newo template - generate ${type} var = new ${type}(|) Pm - new public method skeleton pm - new private method skeleton ...pfm, psm, pfsm, prm, prfm, prfsm - same pattern - pr for private, s for static, f for final, all generate method skeletons m - completely templated new method - i.e. you can overtype or delete - it generates private static final method skeleton; more flexible but more typing ic - inner class skeleton w/ constructor same pattern for pfc, psfc (i.e. private static final class...), sc, sfc, fc; cl - completely templated skeleton class (i.e. all modifiers templated - again, more typing but flexible); cli - same as cl + implements clause fixed broken definition of "bcom" template
Created attachment 85031 [details] Really final patch this time - noticed two duplicates (sort/csort, 2nl/2arl) when I was documenting. sort and 2arl removed
Any chance of this for 6.9? Or, to rephrase...if I simply integrate this patch, say, tomorrow, is anybody actually going to get upset?
Adding Ondrej to Cc:. Otherwise the list already on Cc: for this bug is quite representative I think. If everyone is ok with this I guess you can go ahead.
Fixed, along with #167824, #108167, #173652, #173851, #101131 and #173655 in main/ 4beffcfd4006
Integrated into 'main-golden', will be available in build *201001240200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/4beffcfd4006 User: Tim Boudreau <tboudreau@netbeans.org> Log: #116449, #167824, #108167, #173652, #173851, #101131, #173655 - additional Java editor hints, enhancements to existing ones, addition of module development-specific hints in apisupport.project