Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 115046

Summary: removePrefixAndSuffixForFieldName transforms more than the suffix
Product: [Eclipse Project] JDT Reporter: Arno Schuring <aelschuring>
Component: CoreAssignee: David Audel <david_audel>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard: stalebug

Description Arno Schuring CLA 2005-11-04 05:20:16 EST
This might be by design, but the following seems at least counterintuitive to me:

static final int __VAR_2 = 2;

Java Code Style -> prefix for static fields set to __

NamingConventions.removePrefixAndSuffixForFieldName() on this field returns
vAR_2. (the same with an added suffix instead of prefix)


The question:
Why does this method insist on starting static final fields with a lowercase letter?
Comment 1 Arno Schuring CLA 2005-11-04 07:46:23 EST
(In addition to comment #0)

The javadoc says the following:

"If field name prefix is pre and field name suffix is suf  then for a field
named preFieldsuf the result of this method is field. If there is no prefix or
suffix defined in JavaCore options the result is the unchanged name preFieldsuf."

The latter assertion does not seem to be the case either, e.g. for a variable

static final int VAR = 2;

and prefixes and suffixes for static fields empty, the result is still vAR

Comment 2 Olivier Thomann CLA 2005-11-04 11:30:45 EST
The spec covers the first case in the sentence.
"If field name prefix is pre and field name suffix is suf  then for a field
named preFieldsuf the result of this method is field.". This means that after
removing the prefix and the suffix, the remaining part "Field" is converted to
"field". So this implies an uppercase to lowercase conversion for the first
character.
I would say that the conversion to lowercase should only be done if the field is
not static. For a static field, the uppercase should be preserved. Unfortunately
this is not covered by the specs. So we need to find out if such change would be
an API breakage.
The second case however looks like a bug, because the spec clearly states that
when no prefix or suffix are defined, the name is unchanged.
Comment 3 Arno Schuring CLA 2005-11-04 14:32:50 EST
(In reply to comment #2)

I agree that the first issue is a matter of interpretation, and might be fixed
by a documentation change (read: clarification). However, following the Java
naming conventions, lowercase characters should be disallowed for constants
(i.e. static final fields).

I also recognize the possibility that these prefixes/suffixes might be intended
for variables only, i.e. should not be applied to static finals. Can one of the
JDT developers clarify whether static final fields are considered prefixable via
"static variable" prefixes?
Comment 4 Eclipse Genie CLA 2019-06-21 16:58:10 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.