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

Summary: Patch for: Code completion should propose singular variable names
Product: java Reporter: markiewb
Component: EditorAssignee: Dusan Balek <dbalek>
Status: RESOLVED FIXED    
Severity: normal Keywords: PATCH_AVAILABLE
Priority: P3    
Version: 7.3   
Hardware: PC   
OS: Windows 7   
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: Shows the current state, only proposes "s" and "string"
Patch draft

Description markiewb 2013-03-16 22:59:53 UTC
Created attachment 132693 [details]
Shows the current state, only proposes "s" and "string"

<code>
	List<String> projects = new ArrayList<String>();
	for (String | : projects) { // | defines the current caret
	    
	}
</code>
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")

<code>

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

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

For example:

XXXs-> XXX:
projects -> project
items -> item
strings -> string
actions -> action
...

XXXies->XXXy:
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"}) {
${selection}${cursor}
}

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. 

http://hg.netbeans.org/jet-main/rev/e0a2163c3e03
Comment 4 Quality Engineering 2014-07-17 02:18:01 UTC
Integrated into 'main-silver', will be available in build *201407170001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/e0a2163c3e03
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #227566: Code completion should propose singular variable names - fixed.