### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/InternalNamingConventions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/InternalNamingConventions.java,v retrieving revision 1.22 diff -u -r1.22 InternalNamingConventions.java --- model/org/eclipse/jdt/internal/core/InternalNamingConventions.java 22 Oct 2008 08:27:57 -0000 1.22 +++ model/org/eclipse/jdt/internal/core/InternalNamingConventions.java 20 Nov 2008 09:08:26 -0000 @@ -282,12 +282,16 @@ } private static char[][] computeBaseTypeNames(char[] typeName, boolean isConstantField, char[][] excludedNames){ - char[] name = computeBaseTypeNames(typeName[0], excludedNames); - if(name != null) { - return new char[][]{name}; + if (isConstantField) { + return computeNonBaseTypeNames(typeName, isConstantField); } else { - // compute variable name like from non base type - return computeNonBaseTypeNames(typeName, isConstantField); + char[] name = computeBaseTypeNames(typeName[0], excludedNames); + if(name != null) { + return new char[][]{name}; + } else { + // compute variable name like from non base type + return computeNonBaseTypeNames(typeName, isConstantField); + } } } private static char[] computeBaseTypeNames(char firstName, char[][] excludedNames){ @@ -344,7 +348,11 @@ } if (length == 1) { - return new char[][]{CharOperation.toLowerCase(sourceName)}; + if (isConstantField) { + return generateConstantName(new char[][]{CharOperation.toLowerCase(sourceName)}, 0); + } else { + return generateNonConstantName(new char[][]{CharOperation.toLowerCase(sourceName)}, 0); + } } char[][] nameParts = new char[length][]; @@ -533,7 +541,7 @@ prefixes = assistOptions.staticFieldPrefixes; suffixes = assistOptions.staticFieldSuffixes; break; - case VK_CONSTANT_FIELD: + case VK_STATIC_FINAL_FIELD: prefixes = assistOptions.staticFinalFieldPrefixes; suffixes = assistOptions.staticFinalFieldSuffixes; break; @@ -548,11 +556,11 @@ } - return getBaseName(name, prefixes, suffixes, variableKind == VK_CONSTANT_FIELD); + return getBaseName(name, prefixes, suffixes, variableKind == VK_STATIC_FINAL_FIELD); } private static char[] getBaseName(char[] name, char[][] prefixes, char[][] suffixes, boolean isConstant) { - char[] nameWithoutPrefixAndSiffix = removeVariablePrefixAndSuffix(name, prefixes, suffixes, false); + char[] nameWithoutPrefixAndSiffix = removeVariablePrefixAndSuffix(name, prefixes, suffixes, true); char[] baseName; if (isConstant) { @@ -564,7 +572,7 @@ for (int i = 0; i < length; i++) { char c = nameWithoutPrefixAndSiffix[i]; if (c != '_') { - if (previousIsUnderscore || i == 0) { + if (previousIsUnderscore) { baseName[++baseNamePtr] = ScannerHelper.toUpperCase(c); previousIsUnderscore = false; } else { @@ -604,7 +612,7 @@ prefixes = assistOptions.staticFieldPrefixes; suffixes = assistOptions.staticFieldSuffixes; break; - case VK_CONSTANT_FIELD: + case VK_STATIC_FINAL_FIELD: prefixes = assistOptions.staticFinalFieldPrefixes; suffixes = assistOptions.staticFinalFieldSuffixes; break; @@ -749,7 +757,7 @@ public static final int VK_STATIC_FIELD = 1; public static final int VK_INSTANCE_FIELD = 2; - public static final int VK_CONSTANT_FIELD = 3; + public static final int VK_STATIC_FINAL_FIELD = 3; public static final int VK_PARAMETER = 4; public static final int VK_LOCAL = 5; @@ -792,7 +800,7 @@ prefixes = assistOptions.staticFieldPrefixes; suffixes = assistOptions.staticFieldSuffixes; break; - case VK_CONSTANT_FIELD: + case VK_STATIC_FINAL_FIELD: isConstantField = true; prefixes = assistOptions.staticFinalFieldPrefixes; suffixes = assistOptions.staticFinalFieldSuffixes; Index: model/org/eclipse/jdt/core/NamingConventions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/NamingConventions.java,v retrieving revision 1.39 diff -u -r1.39 NamingConventions.java --- model/org/eclipse/jdt/core/NamingConventions.java 27 Oct 2008 14:20:53 -0000 1.39 +++ model/org/eclipse/jdt/core/NamingConventions.java 20 Nov 2008 09:08:26 -0000 @@ -11,6 +11,7 @@ package org.eclipse.jdt.core; import org.eclipse.jdt.core.compiler.CharOperation; + import org.eclipse.jdt.internal.codeassist.impl.AssistOptions; import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; import org.eclipse.jdt.internal.core.INamingRequestor; @@ -25,18 +26,24 @@ * The possible options are : * *

*

- * For a complete description of the configurable options, see getDefaultOptions. - * For programmaticaly change these options, see JavaCore#setOptions(). + * For a complete description of the configurable options, see {@link JavaCore#getDefaultOptions()}. + * To programmatically change these options, see {@link JavaCore#setOptions(java.util.Hashtable)}. *

*

* This class provides static methods and constants only. @@ -243,11 +250,18 @@ */ public static final int VK_INSTANCE_FIELD = InternalNamingConventions.VK_INSTANCE_FIELD; /** + * Variable kind which represents a static final field. + * + * @since 3.5 + */ + public static final int VK_STATIC_FINAL_FIELD = InternalNamingConventions.VK_STATIC_FINAL_FIELD; + /** * Variable kind which represents a constant field (static final). * * @since 3.5 + * @deprecated use VK_STATIC_FINAL_FIELD instead. This constant will be removed before 3.5M5. */ - public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_CONSTANT_FIELD; + public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_STATIC_FINAL_FIELD; /** * Variable kind which represents an argument. * @@ -542,12 +556,28 @@ * Returns a base name which could be used to generate the given variable name with {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)}. *

* e.g.
- * If the variable is a {@link #VK_LOCAL} and the variable name is variableName then the base name will be VariableName.
- * If the variable is a {@link #VK_CONSTANT_FIELD} and the variable name is VARIABLE_NAME then the base name will be VariableName.
+ * If the variable is a {@link #VK_LOCAL} and the variable name is variableName then the base name will be variableName.
+ * If the variable is a {@link #VK_STATIC_FINAL_FIELD} and the variable name is VARIABLE_NAME then the base name will be variableName.
+ *

+ *

+ * Prefixes and suffixes defined in JavaCore options will be also removed from the variable name.
+ * Each variable kind is affected by the following JavaCore options: + *

+ *

+ *

+ * e.g.
+ * If the variable is a {@link #VK_LOCAL}, the variable name is preVariableNamesuf, a possible prefix is pre and a possible suffix is suf + * then the base name will be variableName.
*

* * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, - * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. + * {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FINAL_FIELD}. * @param variableName a variable name * @param javaProject project which contains the variable or null to take into account only workspace settings. * @@ -1041,31 +1071,31 @@ * *

* The base name is used to compute the variable name. - * Some different kinds of base name are possible and each kind is associated to a different heuristic to compute variable names.
+ * Some different kinds of base names are possible and each kind is associated to a different heuristic to compute variable names.
* The heuristic depends also on the kind of the variable. Each kind of variable is identified by a constant starting with VK_.
* When a prefix and a suffix can be added then all combinations of prefix and suffix are suggested. * If the name is name, the prefix is pre and the suffix is suf then the suggested names will be * prenamesuf, prename, namesuf and name.
*
- * The different kinds of base name are: + * The different kinds of base names are: *

*

*

- * For a complete description of these configurable options, see getDefaultOptions. - * For programmaticaly change these options, see JavaCore#setOptions(). + * For a complete description of these configurable options, see {@link JavaCore#getDefaultOptions()}. + * To programmatically change these options, see {@link JavaCore#setOptions(java.util.Hashtable)} and {@link IJavaProject#setOptions(java.util.Map)} *

*

* Proposed names are sorted by relevance (best proposal first).
* The names are proposed in the following order: *

    - *
  1. Names with prefix and suffix. Longest name are proposed first
  2. - *
  3. Names with prefix. Longest name are proposed first
  4. - *
  5. Names with suffix. Longest name are proposed first
  6. - *
  7. Names without prefix and suffix. Longest name are proposed first
  8. + *
  9. Names with prefix and suffix. Longer names are proposed first
  10. + *
  11. Names with prefix. Longer names are proposed first
  12. + *
  13. Names with suffix. Longer names are proposed first
  14. + *
  15. Names without prefix and suffix. Longer names are proposed first
  16. *
*

* * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, - * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. + * {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FINAL_FIELD}. * @param baseNameKind specifies what type the base name is: {@link #BK_NAME} or {@link #BK_TYPE_NAME} * @param baseName name used to compute the suggested names. * @param javaProject project which contains the variable or null to take into account only workspace settings. * @param dim variable dimension (0 if the field is not an array). * @param excluded a list of names which cannot be suggested (already used names). - * Can be null if there is no excluded names. - * @param evaluateDefault if set, the result is guaranteed to contain at least one result. If not, the result can be an empty array. + * Can be null if there are no excluded names. + * @param evaluateDefault if true, the result is guaranteed to contain at least one result. If false, the result can be an empty array. * @return String[] an array of names. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v retrieving revision 1.380 diff -u -r1.380 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 22 Oct 2008 08:27:57 -0000 1.380 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 20 Nov 2008 09:08:26 -0000 @@ -1561,7 +1561,7 @@ InternalNamingConventions.VK_INSTANCE_FIELD : (field.modifiers & ClassFileConstants.AccFinal) == 0 ? InternalNamingConventions.VK_STATIC_FIELD : - InternalNamingConventions.VK_CONSTANT_FIELD; + InternalNamingConventions.VK_STATIC_FINAL_FIELD; findVariableNames(field.realName, field.type, excludeNames, null, kind); } @@ -2176,7 +2176,7 @@ InternalNamingConventions.VK_INSTANCE_FIELD : (method.modifiers & ClassFileConstants.AccFinal) == 0 ? InternalNamingConventions.VK_STATIC_FIELD : - InternalNamingConventions.VK_CONSTANT_FIELD; + InternalNamingConventions.VK_STATIC_FINAL_FIELD; findVariableNames(this.completionToken, method.returnType, excludeNames, null, kind); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java,v retrieving revision 1.23 diff -u -r1.23 NamingConventionTests.java --- src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java 22 Oct 2008 08:27:50 -0000 1.23 +++ src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java 20 Nov 2008 09:08:28 -0000 @@ -63,7 +63,7 @@ this.project); assertEquals( - "OneName", //$NON-NLS-1$ + "oneName", //$NON-NLS-1$ baseName); } /* @@ -71,12 +71,12 @@ */ public void testGetBaseName002() { String baseName = NamingConventions.getBaseName( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, "ONE_NAME", //$NON-NLS-1$ this.project); assertEquals( - "OneName", //$NON-NLS-1$ + "oneName", //$NON-NLS-1$ baseName); } /* @@ -94,7 +94,7 @@ this.project); assertEquals( - "OneName", //$NON-NLS-1$ + "oneName", //$NON-NLS-1$ baseName); } /* @@ -107,12 +107,12 @@ JavaCore.setOptions(options); String baseName = NamingConventions.getBaseName( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, "preONE_NAMEsuf", //$NON-NLS-1$ this.project); assertEquals( - "OneName", //$NON-NLS-1$ + "oneName", //$NON-NLS-1$ baseName); } public void testSuggestFieldName001() { @@ -485,7 +485,7 @@ */ public void testSuggestFieldName021() { String[] suggestions = NamingConventions.suggestVariableNames( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, NamingConventions.BK_TYPE_NAME, "MyType", //$NON-NLS-1$ this.project, @@ -508,7 +508,7 @@ JavaCore.setOptions(options); String[] suggestions = NamingConventions.suggestVariableNames( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, NamingConventions.BK_TYPE_NAME, "MyType", //$NON-NLS-1$ this.project, @@ -574,7 +574,7 @@ */ public void testSuggestFieldName025() { String[] suggestions = NamingConventions.suggestVariableNames( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, NamingConventions.BK_TYPE_NAME, "My_Type", //$NON-NLS-1$ this.project, @@ -592,7 +592,7 @@ */ public void testSuggestFieldName026() { String[] suggestions = NamingConventions.suggestVariableNames( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, NamingConventions.BK_TYPE_NAME, "_MyType", //$NON-NLS-1$ this.project, @@ -610,7 +610,7 @@ */ public void testSuggestFieldName027() { String[] suggestions = NamingConventions.suggestVariableNames( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, NamingConventions.BK_TYPE_NAME, "MyType_", //$NON-NLS-1$ this.project, @@ -628,7 +628,7 @@ */ public void testSuggestFieldName028() { String[] suggestions = NamingConventions.suggestVariableNames( - NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.VK_STATIC_FINAL_FIELD, NamingConventions.BK_TYPE_NAME, "MyTyp_e", //$NON-NLS-1$ this.project, @@ -826,6 +826,40 @@ "type", //$NON-NLS-1$ toString(suggestions)); } +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=255345 + */ +public void testSuggestFieldName039() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_STATIC_FINAL_FIELD, + NamingConventions.BK_TYPE_NAME, + "A", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "A", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=255345 + */ +public void testSuggestFieldName040() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_STATIC_FINAL_FIELD, + NamingConventions.BK_TYPE_NAME, + "int", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "INT", //$NON-NLS-1$ + toString(suggestions)); +} /** @deprecated */ public void testRemovePrefixAndSuffixForFieldName001() { Hashtable options = JavaCore.getOptions();