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 227566 - Patch for: Code completion should propose singular variable names
Summary: Patch for: Code completion should propose singular variable names
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Dusan Balek
Depends on:
Reported: 2013-03-16 22:59 UTC by markiewb
Modified: 2014-07-17 02:18 UTC (History)
0 users

See Also:
Exception Reporter:

Shows the current state, only proposes "s" and "string" (3.15 KB, image/png)
2013-03-16 22:59 UTC, markiewb
Patch draft (6.02 KB, patch)
2013-11-30 19:50 UTC, markiewb
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description markiewb 2013-03-16 22:59:53 UTC
Created attachment 132693 [details]
Shows the current state, only proposes "s" and "string"

	List<String> projects = new ArrayList<String>();
	for (String | : projects) { // | defines the current caret
Code complete at the given caret...

ACTUAL: code completion suggests "s" or "string"
EXPECTED: code completion suggests "project" (and the old ones "s" or "string")


	List<String> projects = new ArrayList<String>();
	for (String project : projects) { 

Please suggest the singular form for the variable name when iterating on a variable which looks like a plural form

For example:

projects -> project
items -> item
strings -> string
actions -> action

entries -> entry
tries -> try

IMHO: This addition would make the code completion even more useful and the CC looks more intelligent. You do not have to implement all the grammatically specifics of the English language, IMHO these two cases are sufficient in most cases.
Comment 1 markiewb 2013-11-30 19:50:46 UTC
Created attachment 142750 [details]
Patch draft

@Dusan: Please review the proposed patch. Please note that is only a draft - no code cleanup yet.

But it works in my manual tests.

Create and use a new code template with includes the newly introduced "iterableElementVarName"

for (${TYPE iterableElementType default="Object" editable=false} ${ELEM iterableElementVarName default="elem"} : ${ITER iterable default="col"}) {

I like to get your feedback. Thank you in advance!
Comment 2 markiewb 2014-07-09 21:50:24 UTC
@Dusan: Please review the patch
Comment 3 Dusan Balek 2014-07-10 08:00:13 UTC
More general fix created. Should cover also the following cases:

for(int i = 0; i < args.length; i++) {
    String | = args[i];
} ==> arg

String | = getProjectName(); ==> projectName

Fixed in jet-main.
Comment 4 Quality Engineering 2014-07-17 02:18:01 UTC
Integrated into 'main-silver', will be available in build *201407170001* on (upload may still be in progress)

User: Dusan Balek <>
Log: Issue #227566: Code completion should propose singular variable names - fixed.