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.

Bug 228540 - Code template completionInvoke does not work for new templates under certain situations
Summary: Code template completionInvoke does not work for new templates under certain ...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.2
Hardware: PC Windows 7 x64
: P2 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-13 21:26 UTC by jgjp
Modified: 2013-04-19 06:08 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jgjp 2013-04-13 21:26:25 UTC
I created a code template, called "npe" for NullPointerException, using completionInvoke.
But completionInvoke does not work for the following template:
-----------
if (${param instanceof="java.lang.Object" default="args" completionInvoke} == null)
    throw new NullPointerException("${param} is null");${cursor}
-----------
ie, when I type npe<tab> the template gets inserted, and whatever identifier name I type in for the "param" in the first line, gets correctly reproduced into the second line as I wanted it to. However, the completion window does NOT popup when I start typing the identifier name, even though the identifier is definitely in scope.
However, when I change the code template to the following template, the completion window DOES popup after I type in the first char of the identifier.
-----------
if (${param instanceof="java.lang.Object" default="args" completionInvoke} == null)${cursor}
-----------
But in the latter case, it defeats my purpose for defining the code template, which is that I should not have to re-type the identifier name in the second line.
Comment 1 Dusan Balek 2013-04-15 10:44:10 UTC
Hint 'completionInvoke' should be used only with the predefined parameter 'cursor' meaning "Invoke code completion at the position where the caret will be located after the editing of the code template values finishes".
Comment 2 jgjp 2013-04-15 19:40:15 UTC
The same custom template I mentioned in my initial comment (reproduced below)
worked exactly as-is in all earlier NetBeans versions prior to NetBeans 7.x (on all platforms Windows XP 32 bit, 64 bit and Windows 7 64 bit). 
When I upgraded straight from 6.9.2 to 7.2, the template stopped working.
So it appears your response as to how completionInvoke should be used is either incorrect, or is a new behavior in NetBeans 7.x. This new behavior is is not mentioned in any documentation; in any case, it is hard to understand why something which was working perfectly in 6.x and was an extremely useful feature was broken in Netbeans 7.x.

---- Custom template that works in NetBeans >= 6.8.x but does not in 7.x -----
if (${param instanceof="java.lang.Object" default="args" completionInvoke} ==
null)
    throw new NullPointerException("${param} is null");${cursor}
--------------------
Comment 3 Dusan Balek 2013-04-16 11:20:15 UTC
Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/06b62f596e01

FYI: 'completionInvoke' hint as it is used in your examples really has no effect on IDE behavior. The exactly same behavior could be achieved without it.

The problem was caused by replication of the typed text that by mistake closed the code completion window.
Comment 4 jgjp 2013-04-16 16:22:53 UTC
That was fast! Thanks a lot!

BTW, how do I get jet-main? [I have only downloaded NetBeans releases before].
Comment 5 Dusan Balek 2013-04-17 06:41:31 UTC
You could either download the latest build from http://bertram2.netbeans.org:8080/job/jet-main/ or wait couple of days until the fix gets propagated to our daily builds.
Comment 6 Quality Engineering 2013-04-18 02:18:25 UTC
Integrated into 'main-golden', will be available in build *201304172301* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/06b62f596e01
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #228540: Code template completionInvoke does not work for new templates under certain situations - fixed.
Comment 7 jgjp 2013-04-19 06:08:11 UTC
Thank you!