Bug 23210 - Member variable name proposal
Summary: Member variable name proposal
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.1 M4   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-05 06:56 EDT by Omry Yadan CLA
Modified: 2002-12-18 04:34 EST (History)
5 users (show)

See Also:


Attachments
The new API class (21.68 KB, text/plain)
2002-12-16 10:57 EST, David Audel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Omry Yadan CLA 2002-09-05 06:56:59 EDT
When I use CTRL + Space to propose name for a member of a class, I would like 
eclipse to prefix it by some prefix (in my case, "m_").
for example :

class Foo
{
  EventDispatch <CTRL + SPACE>
}
  
right now eclipse propose 'eventDispatcher' and 'dispatcher', which are both 
good names.
I would like it to propose (in my case) 'm_eventDispatcher' and 'm_dispatcher'.
Comment 1 Robert Matthews CLA 2002-09-05 08:08:38 EDT
This is a nice feature that needs to be customisable rather that dictating some
naming convention, but then you're probably leading to that.  The question is
how many prefixs would/could I define and hence how easy would it be?
Comment 2 Omry Yadan CLA 2002-09-05 08:54:18 EDT
I think there should be only one defineable prefix for member variables.
one developer would not be likely to use two different codding standard within 
the same workspace.

maybe we can also have defineable prefix for static members, for methods 
arguments, and for local variables.
and above all, some people (I am not one of them), like to encode the type of 
the variable into the name, so we might add a map which maps type to prefix.
Comment 3 Omry Yadan CLA 2002-09-05 09:03:24 EDT
clearfication:
I said 'and above all', not because I think its the most importent thing, but 
because it effects all the previous things I said in that message.
Comment 4 Renaud Waldura CLA 2002-09-05 13:19:34 EDT
There is something related to this in Preferences / Java / Code Generation / 
Remove prefix from field names. Maybe this setting could be {re,ab}used to 
implement what you suggest.

Regarding your suggestion to have only one defineable prefix for fields, prefix 
for static members, type-dependent prefixes etc. I think that's going a bit 
far. It's only a suggestion after all.
Comment 5 Omry Yadan CLA 2002-09-05 13:27:50 EDT
maybe you are right.
Comment 6 Martin Aeschlimann CLA 2002-09-06 08:32:35 EDT
I tried to add that, but couldn't do it.
The problem is that the name proposal algorithm is located in JCore's 
codeassist and JCore doesn't know anything about the field prefixes defined on 
JDT-UI preference page.
We can't override the core behaviour from UI because core also does the 
filtering of proposals.

EventDispatch f|<CTRL + SPACE

will not give a callback for a variable completion, as core's proposals 
wouldn't start with 'f'. It would only come up on

EventDispatch e|<CTRL + SPACE

and propose eventDispatch

My suggestion is that we move the name proposal algorithm to UI. Code assist 
should simply give callbacks of acceptVariableName on all offsets inside a 
variable. 

Moving to JCore for comments.

see also bug 9092.
Comment 7 Omry Yadan CLA 2002-09-08 16:56:47 EDT
I am not sure adding an acceptVariableName callback will be enough.
in order to generate the appropriate variable name proposal, the core needs to 
know about the user defined prefixs.
I see several options:
1. have a setable strategy object.
this way, the core will call external code that will know about user defined 
prefixes and will ask it to propose a name.
I don't like this option very much.
2. add setMemberVariablePrefix(String prefixs[]) to some class in the core.
this way, ui code will be able to configure the core based on user preferences.
this option is not bad, although I think if you do it, you need to think well 
about other cases (such as local variables name proposal for example), because 
if future support will need to be wider, the API might chanage.


Omry.
Comment 8 Philipe Mulet CLA 2002-09-09 04:37:51 EDT
The JDT/Core callback suggests a variable name, which can be overhidden by the 
UI client. It passes along the type of the variable.

However, it does not tell you about the variable location (field, local, 
argument, ...). So we may either want to pass additional information (hard 
since would change API), or add a couple more convenient settings to render 
JDT/Core aware of such prefixes.
Comment 9 Philipe Mulet CLA 2002-10-22 10:06:54 EDT
We should make JDT/Core be aware of member prefixes.
Comment 10 David Audel CLA 2002-11-06 05:25:44 EST
I could add two new settings to JavaCore :
- field prefix: when this setting have a value, a field name completion should 
begin with this prefix.
- static field prefix: when this setting have a value, a static field name 
completion should begin with this prefix.

Do you think this suggestion is correct and sufficient ?
Comment 11 David Audel CLA 2002-11-12 08:41:21 EST
Change target Milestone to M4
Comment 12 Martin Aeschlimann CLA 2002-11-12 11:19:25 EST
Note that we currenly support a list of field prefixes and list of field 
suffixes.
I still think it would be better if all name guesing code would be grouped: I 
think it should be in JDT.UI but also jdt core could offer some API (e.g. 
INameGuesser) that also we can use.

Another, API compatible, approach would be that code assist does not do name 
guessing but returns always -well known- names that signal the variable kind 
(e.g. 'fieldname', 'paramname', 'localname'). Code assist then wouldn't filter, 
but always return one of the given names.
JDT.UI can then on top calculate the guess-names.
Comment 13 Philipe Mulet CLA 2002-11-18 05:30:02 EST
This would be a contract change, breaking other clients. 
Either we provide prefixes to JDT/Core, or we wait until 3.0 for a breaking API 
change (in which case I would vote for splitting acceptVariableName into
- acceptLocalVariableName
- acceptFieldName 
etc...

Comment 14 Martin Aeschlimann CLA 2002-11-18 10:13:38 EST
There is no promise to the client what names are returned by the 
ICompletionRequestor: In my opinion jdt.core is definitly free to always return 
a proposal called 'variable'.

Another non-API breaking suggestion is to introduce an interface
ICompletionRequestorExtension

The API for codeAssist is still
  void codeComplete(int offset, ICodeCompletionRequestor requestor)
the jdt.core implementation tests:
if (requestor instanceof ICompletionRequestorExtension)
  ((ICompletionRequestorExtension)requestor).acceptLocalVariableName(...)
You can then merge in this interface in 3.0

But as I said, its also fine for me if jdt.core offers a name guessing 
infrastructure that we could reuse.



Comment 15 Philipe Mulet CLA 2002-11-19 08:52:43 EST
The API extension sounds really a hack. It has been used in various place when 
it was critical only. 

Passing special variable names is doable, but this one is a contract change 
(not an API change, but the contract is broken). I agree at the moment it is 
not completely spec'ed, and we could change it, but existing customers would 
get broken.

How critical is this feature ? I'd rather defer it until 3.0, where we can 
solve it at once.
Comment 16 Erich Gamma CLA 2002-11-19 09:36:20 EST
for people using some prefix convention this is an important usability. It 
breaks the flow when you always have to go back and tweak the proposed name.
Comment 17 David Audel CLA 2002-12-16 10:55:17 EST
I added 8 JavaCore options and a new API class 
org.eclipse.jdt.core.NamingConventions. NamingConventions methods compute 
variable name and remove suffix/prefix.

These changes are released in the last build (I20021213).

Fixed.
Comment 18 David Audel CLA 2002-12-16 10:56:15 EST
New options :
CODEASSIST / Define the Prefixes for Field Name
  When the prefixes is non empty, completion for field name will begin with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.fieldPrefix"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Prefixes for Static Field Name
  When the prefixes is non empty, completion for static field name will begin 
with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.staticFieldPrefix"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Prefixes for Local Variable Name
  When the prefixes is non empty, completion for local variable name will begin 
with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.localPrefix"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Prefixes for Argument Name
  When the prefixes is non empty, completion for argument name will begin with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.argumentPrefix"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Field Name
  When the suffixes is non empty, completion for field name will end with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.fieldPrefix"
   - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Static Field Name
  When the suffixes is non empty, completion for static field name will end with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.staticFieldPrefix"
   - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Local Variable Name
  When the suffixes is non empty, completion for local variable name will end 
with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.localPrefix"
   - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Argument Name
  When the suffixes is non empty, completion for argument name will end with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.argumentPrefix"
   - possible values:   { "<suffix>[,<suffix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
Comment 19 David Audel CLA 2002-12-16 10:57:39 EST
Created attachment 2804 [details]
The new API class
Comment 20 David Audel CLA 2002-12-16 11:36:26 EST
Be careful : There are errors in my previous comment and in the javadoc of 
JavaCore#getDefaultOptions() inside build I20021213. The options id are not 
good. 

The errors are only in the comment and the corresponding constants have the 
correct value.

CODEASSIST / Define the Prefixes for Field Name
  When the prefixes is non empty, completion for field name will begin with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.fieldPrefixes"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Prefixes for Static Field Name
  When the prefixes is non empty, completion for static field name will begin 
with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Prefixes for Local Variable Name
  When the prefixes is non empty, completion for local variable name will begin 
with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.localPrefixes"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Prefixes for Argument Name
  When the prefixes is non empty, completion for argument name will begin with
  one of the proposed prefixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.argumentPrefixes"
   - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Field Name
  When the suffixes is non empty, completion for field name will end with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.fieldSuffixes
   - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Static Field Name
  When the suffixes is non empty, completion for static field name will end with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"
   - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Local Variable Name
  When the suffixes is non empty, completion for local variable name will end 
with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.localSuffixes"
   - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String 
without any wild-card 
   - default:           ""
CODEASSIST / Define the Suffixes for Argument Name
  When the suffixes is non empty, completion for argument name will end with
  one of the proposed suffixes.
   - option id:         "org.eclipse.jdt.core.codeComplete.argumentSuffixes"
   - possible values:   { "<suffix>[,<suffix>]*" } where <prefix> is a String 
without any wild-card 
   - default:           ""
Comment 21 David Audel CLA 2002-12-18 04:34:21 EST
Verified.