### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v retrieving revision 1.188 diff -u -r1.188 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 9 Sep 2008 12:43:37 -0000 1.188 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 23 Sep 2008 08:24:51 -0000 @@ -5079,6 +5079,121 @@ requestor.getResults()); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName3() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor \n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + + "REQUESTOR[VARIABLE_DECLARATION]{REQUESTOR, null, Ltest.TypeNameRequestor;, REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + + "TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName4() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor nam\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor nam"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "NAM_REQUESTOR[VARIABLE_DECLARATION]{NAM_REQUESTOR, null, Ltest.TypeNameRequestor;, NAM_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + + "NAM_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{NAM_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAM_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + + "NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NAME_LESS_NEW_CHARACTERS+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName5() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor ZZ\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor ZZ"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "ZZ_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_REQUESTOR[VARIABLE_DECLARATION]{ZZ_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName6() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor ZZN\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor ZZN"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "ZZN_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZN_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZN_REQUESTOR[VARIABLE_DECLARATION]{ZZN_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZN_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZN_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName7() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor ZZ_N\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor ZZ_N"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "ZZ_N_REQUESTOR[VARIABLE_DECLARATION]{ZZ_N_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_N_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_N_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_N_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_N_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NAME_LESS_NEW_CHARACTERS + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + /** * Complete the type "A" from "new A". */ 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.22 diff -u -r1.22 NamingConventionTests.java --- src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java 27 Jun 2008 16:02:40 -0000 1.22 +++ src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java 23 Sep 2008 08:24:51 -0000 @@ -16,7 +16,6 @@ import junit.framework.Test; -import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.NamingConventions; import org.eclipse.jdt.core.compiler.CharOperation; @@ -53,42 +52,31 @@ super.tearDown(); } -private String toString(char[][] suggestions) { - if(suggestions == null) { - return ""; //$NON-NLS-1$ - } - - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < suggestions.length; i++) { - if(i != 0) { - buffer.append('\n'); - } - buffer.append(suggestions[i]); - } - return buffer.toString(); -} public void testSuggestFieldName001() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + assumeEquals( "name\n" + //$NON-NLS-1$ "oneName", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName002() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneClass".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); - + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneClass", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + assumeEquals( "class1\n" + //$NON-NLS-1$ "oneClass", //$NON-NLS-1$ @@ -99,13 +87,14 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "fName\n" + //$NON-NLS-1$ @@ -119,13 +108,14 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"_"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "_name\n" + //$NON-NLS-1$ @@ -139,14 +129,15 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$ options.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,"fg"); //$NON-NLS-1$ JavaCore.setOptions(options); - - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - Flags.AccStatic, - CharOperation.NO_CHAR_CHAR); + + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_STATIC_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "fgName\n" + //$NON-NLS-1$ @@ -161,13 +152,14 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "preNamesuf\n" + //$NON-NLS-1$ @@ -186,13 +178,14 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "int".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "int", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "preIsuf\n" + //$NON-NLS-1$ @@ -202,13 +195,14 @@ toString(suggestions)); } public void testSuggestFieldName008() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"name".toCharArray()}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{"name"}, //$NON-NLS-1$ + true); assumeEquals( "name2\n" + //$NON-NLS-1$ @@ -221,14 +215,15 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$ - + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{"preNamesuf"}, //$NON-NLS-1$ + true); + assumeEquals( "preName2suf\n" + //$NON-NLS-1$ "preOneNamesuf\n" + //$NON-NLS-1$ @@ -245,14 +240,15 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 1, - 0, - new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$ + + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 1, + new String[]{"preNamesuf"}, //$NON-NLS-1$ + true); assumeEquals( "preNamessuf\n" + //$NON-NLS-1$ @@ -266,26 +262,29 @@ toString(suggestions)); } public void testSuggestFieldName011() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "Factory".toCharArray(), //$NON-NLS-1$ - 1, - 0, - CharOperation.NO_CHAR_CHAR); //$NON-NLS-1$ + + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "Factory", //$NON-NLS-1$ + this.project, + 1, + new String[]{}, + true); assumeEquals( "factories", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName012() { - String[] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c", //$NON-NLS-1$ - "FooBar", //$NON-NLS-1$ - 0, - 0, - new String[]{"bar"}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "FooBar", //$NON-NLS-1$ + this.project, + 0, + new String[]{"bar"}, //$NON-NLS-1$ + true); assumeEquals( "bar2\n" + //$NON-NLS-1$ @@ -293,52 +292,56 @@ toString(suggestions)); } public void testSuggestFieldName013() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "java.lang".toCharArray(), //$NON-NLS-1$ - "Class".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "Class", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "class1",//$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName014() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "java.lang".toCharArray(), //$NON-NLS-1$ - "Class".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"class1".toCharArray()}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "Class", //$NON-NLS-1$ + this.project, + 0, + new String[]{"class1"}, //$NON-NLS-1$ + true); assumeEquals( "class2",//$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName015() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "#".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "#", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "name",//$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName016() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "#".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"name".toCharArray()}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "#", //$NON-NLS-1$ + this.project, + 0, + new String[]{"name"}, //$NON-NLS-1$ + true); assumeEquals( "name2",//$NON-NLS-1$ @@ -348,13 +351,14 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName017() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "names".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "names", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "names",//$NON-NLS-1$ @@ -364,13 +368,14 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName018() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "names".toCharArray(), //$NON-NLS-1$ - 1, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "names", //$NON-NLS-1$ + this.project, + 1, + new String[]{}, + true); assumeEquals( "names",//$NON-NLS-1$ @@ -380,13 +385,14 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName019() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "MyClass".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "MyClass", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "class1\n" + //$NON-NLS-1$ @@ -397,33 +403,119 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName020() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "MyClass".toCharArray(), //$NON-NLS-1$ - 1, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "MyClass", //$NON-NLS-1$ + this.project, + 1, + new String[]{}, + true); assumeEquals( "classes\n" + //$NON-NLS-1$ "myClasses", //$NON-NLS-1$ toString(suggestions)); } -public void testRemovePrefixAndSuffixForFieldName001() { +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName021() { + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "MyType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "TYPE\n" + //$NON-NLS-1$ + "MY_TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName022() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ + options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ + JavaCore.setOptions(options); + + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "MyType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "preTYPEsuf\n" + //$NON-NLS-1$ + "preMY_TYPEsuf\n" + //$NON-NLS-1$ + "preTYPE\n" + //$NON-NLS-1$ + "preMY_TYPE\n" + //$NON-NLS-1$ + "TYPEsuf\n" + //$NON-NLS-1$ + "MY_TYPEsuf\n" + //$NON-NLS-1$ + "TYPE\n" + //$NON-NLS-1$ + "MY_TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName023() { + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_NAME, + "oneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "oneName", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName024() { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); + + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_SIMPLE_NAME, + "oneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); - char[] name = NamingConventions.removePrefixAndSuffixForFieldName( - this.project, - "preOneNamesuf".toCharArray(), //$NON-NLS-1$ - 0); + assumeEquals( + "preOneNamesuf\n" + //$NON-NLS-1$ + "preOneName\n" + //$NON-NLS-1$ + "oneNamesuf\n" + //$NON-NLS-1$ + "oneName", //$NON-NLS-1$ + toString(suggestions)); +} +public void testRemovePrefixAndSuffixForFieldName001() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ + options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ + JavaCore.setOptions(options); + String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_INSTANCE_FIELD, this.project, "preOneNamesuf"); //$NON-NLS-1$ assumeEquals( "oneName", //$NON-NLS-1$ - new String(name)); + name); } public void testRemovePrefixAndSuffixForFieldName002() { Hashtable options = JavaCore.getOptions(); @@ -431,14 +523,10 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"uf, suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[] name = NamingConventions.removePrefixAndSuffixForFieldName( - this.project, - "preOneNamesuf".toCharArray(), //$NON-NLS-1$ - Flags.AccStatic); - + String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_STATIC_FIELD, this.project, "preOneNamesuf"); //$NON-NLS-1$ assumeEquals( "preOneNamesuf", //$NON-NLS-1$ - new String(name)); + name); } public void testRemovePrefixAndSuffixForFieldName003() { Hashtable options = JavaCore.getOptions(); @@ -446,14 +534,10 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"uf, suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[] name = NamingConventions.removePrefixAndSuffixForFieldName( - this.project, - "preOneNamesuf".toCharArray(), //$NON-NLS-1$ - 0); - + String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_INSTANCE_FIELD, this.project, "preOneNamesuf"); //$NON-NLS-1$ assumeEquals( "oneName", //$NON-NLS-1$ - new String(name)); + name); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=114086 public void testRemovePrefixAndSuffixForFieldName004() { @@ -461,14 +545,10 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre,"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[] name = NamingConventions.removePrefixAndSuffixForFieldName( - this.project, - "preOneName".toCharArray(), //$NON-NLS-1$ - 0); - + String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_INSTANCE_FIELD, this.project, "preOneName"); //$NON-NLS-1$ assumeEquals( "oneName", //$NON-NLS-1$ - new String(name)); + name); } public void testRemovePrefixAndSuffixForLocalName001() { Hashtable options = JavaCore.getOptions(); @@ -476,14 +556,10 @@ options.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES,"uf, suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[] name = NamingConventions.removePrefixAndSuffixForLocalVariableName( - this.project, - "preOneNamesuf".toCharArray() //$NON-NLS-1$ - ); - + String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_LOCAL, this.project, "preOneNamesuf"); //$NON-NLS-1$ assumeEquals( "oneName", //$NON-NLS-1$ - new String(name)); + name); } public void testSuggestGetterName001() { char[] suggestion = NamingConventions.suggestGetterName( @@ -633,12 +709,14 @@ newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); this.project.setOptions(newOptions); - String[] suggestions = NamingConventions.suggestLocalVariableNames( + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_LOCAL, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "Enum", this.project, - "",//$NON-NLS-1$ - "Enum",//$NON-NLS-1$ 0, - new String[]{"o"}); + new String[]{"o"}, //$NON-NLS-1$ + true); assumeEquals( "enum1", //$NON-NLS-1$ @@ -659,12 +737,14 @@ newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); this.project.setOptions(newOptions); - String[] suggestions = NamingConventions.suggestLocalVariableNames( + String[] suggestions = NamingConventions.getVariableNames( + NamingConventions.VK_LOCAL, + NamingConventions.BK_SIMPLE_TYPE_NAME, + "Enums", this.project, - "",//$NON-NLS-1$ - "Enums",//$NON-NLS-1$ 0, - new String[]{"o"}); + new String[]{"o"}, //$NON-NLS-1$ + true); assumeEquals( "enums", //$NON-NLS-1$ #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.21 diff -u -r1.21 InternalNamingConventions.java --- model/org/eclipse/jdt/internal/core/InternalNamingConventions.java 27 Jun 2008 16:03:50 -0000 1.21 +++ model/org/eclipse/jdt/internal/core/InternalNamingConventions.java 23 Sep 2008 08:24:56 -0000 @@ -12,7 +12,6 @@ import java.util.Map; -import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; @@ -37,227 +36,6 @@ null/*taskPriorities*/, true/*taskCaseSensitive*/); } - public static void suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) { - Map options = javaProject.getOptions(true); - CompilerOptions compilerOptions = new CompilerOptions(options); - AssistOptions assistOptions = new AssistOptions(options); - - suggestNames( - packageName, - qualifiedTypeName, - dim, - internalPrefix, - assistOptions.argumentPrefixes, - assistOptions.argumentSuffixes, - excludedNames, - getNameScanner(compilerOptions), - requestor); - } - public static void suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) { - boolean isStatic = Flags.isStatic(modifiers); - - Map options = javaProject.getOptions(true); - CompilerOptions compilerOptions = new CompilerOptions(options); - AssistOptions assistOptions = new AssistOptions(options); - - suggestNames( - packageName, - qualifiedTypeName, - dim, - internalPrefix, - isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes, - isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes, - excludedNames, - getNameScanner(compilerOptions), - requestor); - } - public static void suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) { - Map options = javaProject.getOptions(true); - CompilerOptions compilerOptions = new CompilerOptions(options); - AssistOptions assistOptions = new AssistOptions(options); - - suggestNames( - packageName, - qualifiedTypeName, - dim, - internalPrefix, - assistOptions.localPrefixes, - assistOptions.localSuffixes, - excludedNames, - getNameScanner(compilerOptions), - requestor); - } - - private static void suggestNames( - char[] packageName, - char[] qualifiedTypeName, - int dim, - char[] internalPrefix, - char[][] prefixes, - char[][] suffixes, - char[][] excludedNames, - Scanner nameScanner, - INamingRequestor requestor){ - - if(qualifiedTypeName == null || qualifiedTypeName.length == 0) - return; - - if(internalPrefix == null) { - internalPrefix = CharOperation.NO_CHAR; - } else { - internalPrefix = removePrefix(internalPrefix, prefixes); - } - - char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); - - if(prefixes == null || prefixes.length == 0) { - prefixes = new char[1][0]; - } else { - int length = prefixes.length; - System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length); - prefixes[length] = CharOperation.NO_CHAR; - } - - if(suffixes == null || suffixes.length == 0) { - suffixes = new char[1][0]; - } else { - int length = suffixes.length; - System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length); - suffixes[length] = CharOperation.NO_CHAR; - } - - char[][] tempNames = null; - - // compute variable name for base type - try{ - nameScanner.setSource(typeName); - switch (nameScanner.getNextToken()) { - case TerminalTokens.TokenNameint : - case TerminalTokens.TokenNamebyte : - case TerminalTokens.TokenNameshort : - case TerminalTokens.TokenNamechar : - case TerminalTokens.TokenNamelong : - case TerminalTokens.TokenNamefloat : - case TerminalTokens.TokenNamedouble : - case TerminalTokens.TokenNameboolean : - - if (internalPrefix != null && internalPrefix.length > 0) return; - - char[] name = computeBaseTypeNames(typeName[0], excludedNames); - if(name != null) { - tempNames = new char[][]{name}; - } - break; - } - } catch(InvalidInputException e){ - // ignore - } - - // compute variable name for non base type - if(tempNames == null) { - tempNames = computeNames(typeName); - } - - boolean acceptDefaultName = true; - SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray(); - - next : for (int i = 0; i < tempNames.length; i++) { - char[] tempName = tempNames[i]; - if(dim > 0) { - int length = tempName.length; - if (tempName[length-1] == 's'){ - if(tempName.length > 1 && tempName[length-2] == 's') { - System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); - tempName[length] = 'e'; - tempName[length+1] = 's'; - } - } else if(tempName[length-1] == 'y') { - System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); - tempName[length-1] = 'i'; - tempName[length] = 'e'; - tempName[length+1] = 's'; - } else { - System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length); - tempName[length] = 's'; - } - } - - char[] unprefixedName = tempName; - unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]); - for (int j = 0; j <= internalPrefix.length; j++) { - if(j == internalPrefix.length || - CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) { - tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, j), unprefixedName); - if(j == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]); - for (int k = 0; k < prefixes.length; k++) { - if(prefixes[k].length > 0 - && ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) { - tempName[0] = ScannerHelper.toUpperCase(tempName[0]); - } else { - tempName[0] = ScannerHelper.toLowerCase(tempName[0]); - } - char[] prefixName = CharOperation.concat(prefixes[k], tempName); - for (int l = 0; l < suffixes.length; l++) { - char[] suffixName = CharOperation.concat(prefixName, suffixes[l]); - suffixName = - excludeNames( - suffixName, - prefixName, - suffixes[l], - excludedNames); - try{ - nameScanner.setSource(suffixName); - switch (nameScanner.getNextToken()) { - case TerminalTokens.TokenNameIdentifier : - int token = nameScanner.getNextToken(); - if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { - if (!foundNames.includes(suffixName)) { - acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - j, requestor); - foundNames.add(suffixName); - acceptDefaultName = false; - } - } - break; - default: - suffixName = CharOperation.concat( - prefixName, - String.valueOf(1).toCharArray(), - suffixes[l] - ); - suffixName = - excludeNames( - suffixName, - prefixName, - suffixes[l], - excludedNames); - nameScanner.setSource(suffixName); - switch (nameScanner.getNextToken()) { - case TerminalTokens.TokenNameIdentifier : - token = nameScanner.getNextToken(); - if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { - if (!foundNames.includes(suffixName)) { - acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - j, requestor); - foundNames.add(suffixName); - acceptDefaultName = false; - } - } - } - } - } catch(InvalidInputException e){ - // ignore - } - } - } - continue next; - } - } - } - // if no names were found - if(acceptDefaultName) { - char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excludedNames); - requestor.acceptNameWithoutPrefixAndSuffix(name, 0); - } - } private static void acceptName( char[] name, @@ -278,6 +56,15 @@ } } + private static char[][] computeBaseTypeNames(char[] typeName, boolean isConstantField, char[][] excludedNames){ + 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){ char[] name = new char[]{firstName}; @@ -294,8 +81,8 @@ return name; } - - private static char[][] computeNames(char[] sourceName){ + + private static char[][] computeNonBaseTypeNames(char[] sourceName, boolean isConstantField){ char[][] names = new char[5][]; int nameCount = 0; boolean previousIsUpperCase = false; @@ -309,7 +96,11 @@ if(nameCount == names.length) { System.arraycopy(names, 0, names = new char[nameCount * 2][], 0, nameCount); } - name[0] = ScannerHelper.toLowerCase(name[0]); + if (isConstantField) { + name = convertToConstantName(name); + } else { + name[0] = ScannerHelper.toLowerCase(name[0]); + } names[nameCount++] = name; } } @@ -317,11 +108,33 @@ previousIsLetter = isLetter; } if(nameCount == 0){ - names[nameCount++] = CharOperation.toLowerCase(sourceName); + if (isConstantField) { + names[nameCount++] = convertToConstantName(sourceName); + } else { + names[nameCount++] = CharOperation.toLowerCase(sourceName); + } } System.arraycopy(names, 0, names = new char[nameCount][], 0, nameCount); return names; } + + private static char[] convertToConstantName(char[] name) { + int length = name.length; + char[] constantName = new char[length * 2]; + int constantNamePtr = 0; + boolean wasUnderscore = true; + for (int i = 0; i < length; i++) { + if (ScannerHelper.isUpperCase(name[i])) { + if (!wasUnderscore) constantName[constantNamePtr++] = '_'; + constantName[constantNamePtr++] = name[i]; + } else { + constantName[constantNamePtr++] = ScannerHelper.toUpperCase(name[i]); + wasUnderscore = name[i] == '_'; + } + } + System.arraycopy(constantName, 0, constantName = new char[constantNamePtr], 0, constantNamePtr); + return constantName; + } private static char[] excludeNames( char[] suffixName, @@ -430,4 +243,272 @@ return false; return true; } + + 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_PARAMETER = 4; + public static final int VK_LOCAL = 5; + + public static final int BK_SIMPLE_NAME = 1; + public static final int BK_SIMPLE_TYPE_NAME = 2; + + public static void suggestVariableNames( + int variableKind, + int baseNameKind, + char[] baseName, + IJavaProject javaProject, + int dim, + char[] internalPrefix, + char[][] excluded, + boolean evaluateDefault, + INamingRequestor requestor) { + + if(baseName == null || baseName.length == 0) + return; + + Map options = javaProject.getOptions(true); + CompilerOptions compilerOptions = new CompilerOptions(options); + AssistOptions assistOptions = new AssistOptions(options); + + boolean isConstantField = false; + + char[][] prefixes = null; + char[][] suffixes = null; + switch (variableKind) { + case VK_INSTANCE_FIELD: + prefixes = assistOptions.fieldPrefixes; + suffixes = assistOptions.fieldSuffixes; + break; + case VK_STATIC_FIELD: + prefixes = assistOptions.staticFieldPrefixes; + suffixes = assistOptions.staticFieldSuffixes; + break; + case VK_CONSTANT_FIELD: + isConstantField = true; + prefixes = assistOptions.staticFinalFieldPrefixes; + suffixes = assistOptions.staticFinalFieldSuffixes; + break; + case VK_LOCAL: + prefixes = assistOptions.localPrefixes; + suffixes = assistOptions.localSuffixes; + break; + case VK_PARAMETER: + prefixes = assistOptions.argumentPrefixes; + suffixes = assistOptions.argumentSuffixes; + break; + } + + if(prefixes == null || prefixes.length == 0) { + prefixes = new char[1][0]; + } else { + int length = prefixes.length; + System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length); + prefixes[length] = CharOperation.NO_CHAR; + } + + if(suffixes == null || suffixes.length == 0) { + suffixes = new char[1][0]; + } else { + int length = suffixes.length; + System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length); + suffixes[length] = CharOperation.NO_CHAR; + } + + if(internalPrefix == null) { + internalPrefix = CharOperation.NO_CHAR; + } else { + internalPrefix = removePrefix(internalPrefix, prefixes); + } + + char[][] tempNames = null; + + Scanner nameScanner = getNameScanner(compilerOptions); + if (baseNameKind == BK_SIMPLE_TYPE_NAME) { + boolean isBaseType = false; + + try{ + nameScanner.setSource(baseName); + switch (nameScanner.getNextToken()) { + case TerminalTokens.TokenNameint : + case TerminalTokens.TokenNamebyte : + case TerminalTokens.TokenNameshort : + case TerminalTokens.TokenNamechar : + case TerminalTokens.TokenNamelong : + case TerminalTokens.TokenNamefloat : + case TerminalTokens.TokenNamedouble : + case TerminalTokens.TokenNameboolean : + isBaseType = true; + break; + } + } catch(InvalidInputException e){ + // ignore + } + if (isBaseType) { + // compute variable name from base type + if (internalPrefix.length > 0) return; + + tempNames = computeBaseTypeNames(baseName, isConstantField, excluded); + } else { + // compute variable name for non base type + tempNames = computeNonBaseTypeNames(baseName, isConstantField); + } + } else { + tempNames = new char[][]{baseName}; + } + + boolean acceptDefaultName = true; + SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray(); + + for (int i = 0; i < tempNames.length; i++) { + char[] tempName = tempNames[i]; + + // add English plural form is necessary + if(dim > 0) { + int length = tempName.length; + + if (isConstantField) { + if (tempName[length-1] == 'S'){ + if(tempName.length > 1 && tempName[length-2] == 'S') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length] = 'E'; + tempName[length+1] = 'S'; + } + } else if(tempName[length-1] == 'Y') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length-1] = 'I'; + tempName[length] = 'E'; + tempName[length+1] = 'S'; + } else { + System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length); + tempName[length] = 'S'; + } + } else { + if (tempName[length-1] == 's'){ + if(tempName.length > 1 && tempName[length-2] == 's') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length] = 'e'; + tempName[length+1] = 's'; + } + } else if(tempName[length-1] == 'y') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length-1] = 'i'; + tempName[length] = 'e'; + tempName[length+1] = 's'; + } else { + System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length); + tempName[length] = 's'; + } + } + } + + char[] unprefixedName = tempName; + + int matchingIndex = -1; + if (!isConstantField) { + unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]); + + done : for (int j = 0; j <= internalPrefix.length; j++) { + if(j == internalPrefix.length || + CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) { + matchingIndex = j; + break done; + } + } + } else { + done : for (int j = 0; j <= internalPrefix.length; j++) { + if(j == internalPrefix.length) { + matchingIndex = j; + break done; + } else if(CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) { + if (j == 0 || internalPrefix[j - 1] == '_') { + matchingIndex = j; + break done; + } + + } + } + } + + if(matchingIndex > -1) { + if (!isConstantField) { + tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, matchingIndex), unprefixedName); + if(matchingIndex == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]); + } else { + if(matchingIndex != 0 && tempName[0] != '_' && internalPrefix[matchingIndex - 1] != '_') { + tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName, '_'); + } else { + tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName); + } + } + + for (int k = 0; k < prefixes.length; k++) { + if (!isConstantField) { + if(prefixes[k].length > 0 + && ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) { + tempName[0] = ScannerHelper.toUpperCase(tempName[0]); + } else { + tempName[0] = ScannerHelper.toLowerCase(tempName[0]); + } + } + char[] prefixName = CharOperation.concat(prefixes[k], tempName); + for (int l = 0; l < suffixes.length; l++) { + char[] suffixName = CharOperation.concat(prefixName, suffixes[l]); + suffixName = + excludeNames( + suffixName, + prefixName, + suffixes[l], + excluded); + try{ + nameScanner.setSource(suffixName); + switch (nameScanner.getNextToken()) { + case TerminalTokens.TokenNameIdentifier : + int token = nameScanner.getNextToken(); + if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { + if (!foundNames.includes(suffixName)) { + acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor); + foundNames.add(suffixName); + acceptDefaultName = false; + } + } + break; + default: + suffixName = CharOperation.concat( + prefixName, + String.valueOf(1).toCharArray(), + suffixes[l] + ); + suffixName = + excludeNames( + suffixName, + prefixName, + suffixes[l], + excluded); + nameScanner.setSource(suffixName); + switch (nameScanner.getNextToken()) { + case TerminalTokens.TokenNameIdentifier : + token = nameScanner.getNextToken(); + if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { + if (!foundNames.includes(suffixName)) { + acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor); + foundNames.add(suffixName); + acceptDefaultName = false; + } + } + } + } + } catch(InvalidInputException e){ + // ignore + } + } + } + } + } + // if no names were found + if(evaluateDefault && acceptDefaultName) { + char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excluded); + requestor.acceptNameWithoutPrefixAndSuffix(name, 0); + } + } } Index: model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java,v retrieving revision 1.40 diff -u -r1.40 JavaCorePreferenceInitializer.java --- model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java 27 Jun 2008 16:03:50 -0000 1.40 +++ model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java 23 Sep 2008 08:24:56 -0000 @@ -77,10 +77,12 @@ defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED); defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED); Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.411 diff -u -r1.411 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 12 Sep 2008 15:42:59 -0000 1.411 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 23 Sep 2008 08:24:56 -0000 @@ -1979,10 +1979,12 @@ defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED); defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED); Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.625 diff -u -r1.625 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 5 Sep 2008 15:41:12 -0000 1.625 +++ model/org/eclipse/jdt/core/JavaCore.java 23 Sep 2008 08:24:55 -0000 @@ -1799,6 +1799,19 @@ */ public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$ /** + * Code assist option ID: Define the Prefixes for Static Final Field Name. + *

When the prefixes is non empty, completion for static final field name will begin with + * one of the proposed prefixes. + *

+ *
Option id:
"org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"
+ *
Possible values:
{ "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card
+ *
Default:
""
+ *
+ * @since 3.5 + * @category CodeAssistOptionID + */ + public static final String CODEASSIST_STATIC_FINAL_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldPrefixes"; //$NON-NLS-1$ + /** * Code assist option ID: 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. @@ -1851,6 +1864,19 @@ */ public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$ /** + * Code assist option ID: Define the Suffixes for Static Final Field Name. + *

When the suffixes is non empty, completion for static final field name will end with + * one of the proposed suffixes. + *

+ *
Option id:
"org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"
+ *
Possible values:
{ "<suffix>[,<suffix>]*" }< where <suffix> is a String without any wild-card
+ *
Default:
""
+ *
+ * @since 3.5 + * @category CodeAssistOptionID + */ + public static final String CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldSuffixes"; //$NON-NLS-1$ + /** * Code assist option ID: 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. 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.37 diff -u -r1.37 NamingConventions.java --- model/org/eclipse/jdt/core/NamingConventions.java 27 Jun 2008 16:04:00 -0000 1.37 +++ model/org/eclipse/jdt/core/NamingConventions.java 23 Sep 2008 08:24:55 -0000 @@ -48,10 +48,6 @@ * @noinstantiate This class is not intended to be instantiated by clients. */ public final class NamingConventions { - private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$ - private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$ - private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$ - static class NamingRequestor implements INamingRequestor { private final static int SIZE = 10; @@ -80,6 +76,45 @@ // for acceptNameWithoutPrefixAndSuffix private char[][] otherResults = new char[SIZE][]; private int otherResultsCount = 0; + public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) { + int length = this.otherResults.length; + if(length == this.otherResultsCount) { + System.arraycopy( + this.otherResults, + 0, + this.otherResults = new char[length * 2][], + 0, + length); + } + this.otherResults[this.otherResultsCount++] = name; + } + + public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) { + if(isFirstPrefix) { + int length = this.firstPrefixResults.length; + if(length == this.firstPrefixResultsCount) { + System.arraycopy( + this.firstPrefixResults, + 0, + this.firstPrefixResults = new char[length * 2][], + 0, + length); + } + this.firstPrefixResults[this.firstPrefixResultsCount++] = name; + } else{ + int length = this.prefixResults.length; + if(length == this.prefixResultsCount) { + System.arraycopy( + this.prefixResults, + 0, + this.prefixResults = new char[length * 2][], + 0, + length); + } + this.prefixResults[this.prefixResultsCount++] = name; + } + } + public void acceptNameWithPrefixAndSuffix(char[] name, boolean isFirstPrefix, boolean isFirstSuffix, int reusedCharacters) { if(isFirstPrefix && isFirstSuffix) { int length = this.firstPrefixAndFirstSuffixResults.length; @@ -128,32 +163,6 @@ } } - public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) { - if(isFirstPrefix) { - int length = this.firstPrefixResults.length; - if(length == this.firstPrefixResultsCount) { - System.arraycopy( - this.firstPrefixResults, - 0, - this.firstPrefixResults = new char[length * 2][], - 0, - length); - } - this.firstPrefixResults[this.firstPrefixResultsCount++] = name; - } else{ - int length = this.prefixResults.length; - if(length == this.prefixResultsCount) { - System.arraycopy( - this.prefixResults, - 0, - this.prefixResults = new char[length * 2][], - 0, - length); - } - this.prefixResults[this.prefixResultsCount++] = name; - } - } - public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix, int reusedCharacters) { if(isFirstSuffix) { int length = this.firstSuffixResults.length; @@ -179,19 +188,6 @@ this.suffixResults[this.suffixResultsCount++] = name; } } - - public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) { - int length = this.otherResults.length; - if(length == this.otherResultsCount) { - System.arraycopy( - this.otherResults, - 0, - this.otherResults = new char[length * 2][], - 0, - length); - } - this.otherResults[this.otherResultsCount++] = name; - } public char[][] getResults(){ int count = this.firstPrefixAndFirstSuffixResultsCount @@ -228,50 +224,119 @@ return results; } } + private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$ + private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$ + private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$ - private NamingConventions() { - // Not instantiable - } - private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) { - // remove longer prefix - char[] withoutPrefixName = name; - if (prefixes != null) { - int bestLength = 0; - for (int i= 0; i < prefixes.length; i++) { - char[] prefix = prefixes[i]; - if (CharOperation.prefixEquals(prefix, name)) { - int currLen = prefix.length; - boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); - if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { - if (bestLength < currLen && name.length != currLen) { - withoutPrefixName = CharOperation.subarray(name, currLen, name.length); - bestLength = currLen; - } - } - } - } - } + public static final int VK_STATIC_FIELD = InternalNamingConventions.VK_STATIC_FIELD; + public static final int VK_INSTANCE_FIELD = InternalNamingConventions.VK_INSTANCE_FIELD; + public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_CONSTANT_FIELD; + public static final int VK_PARAMETER = InternalNamingConventions.VK_PARAMETER; + public static final int VK_LOCAL = InternalNamingConventions.VK_LOCAL; + + public static final int BK_SIMPLE_NAME = InternalNamingConventions.BK_SIMPLE_NAME; + public static final int BK_SIMPLE_TYPE_NAME = InternalNamingConventions.BK_SIMPLE_TYPE_NAME; - // remove longer suffix - char[] withoutSuffixName = withoutPrefixName; - if(suffixes != null) { - int bestLength = 0; - for (int i = 0; i < suffixes.length; i++) { - char[] suffix = suffixes[i]; - if(CharOperation.endsWith(withoutPrefixName, suffix)) { - int currLen = suffix.length; - if(bestLength < currLen && withoutPrefixName.length != currLen) { - withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); - bestLength = currLen; - } - } + private static String[] convertCharsToString(char[][] c) { + int length = c == null ? 0 : c.length; + String[] s = new String[length]; + for (int i = 0; i < length; i++) { + s[i] = String.valueOf(c[i]); + } + return s; + } + private static char[][] convertStringToChars(String[] s) { + int length = s == null ? 0 : s.length; + char[][] c = new char[length][]; + for (int i = 0; i < length; i++) { + if(s[i] == null) { + c[i] = CharOperation.NO_CHAR; + } else { + c[i] = s[i].toCharArray(); } } + return c; + } - withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); - return withoutSuffixName; + /** + * Suggest names for a variable. The name is computed from a base name + * and possible prefixes or suffixes are added. + *

+ * The variable can be a local variable, a parameter, an instance field, a static field or a constant field. + * Each type of variable is specified by a variable kind: + *

+ * Some other kinds could be added in the future. + *

+ *

+ * 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. + * The different kinds of base name are: + *

+ * Some other kinds could be added in the future. + *

+ *

+ * Each variable kind is affected by the following JavaCore options: + *

+ *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ * + * @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}. + * @param baseNameKind specifies what type the base name is: {@link #BK_SIMPLE_NAME} or {@link #BK_SIMPLE_TYPE_NAME} + * @param baseName name used to compute the suggested names. + * @param javaProject project which contains the variable. + * @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. + * @return String[] an array of names. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + */ + public static String[] getVariableNames( + int variableKind, + int baseNameKind, + String baseName, + IJavaProject javaProject, + int dim, + String[] excluded, + boolean evaluateDefault) { + + NamingRequestor requestor = new NamingRequestor(); + InternalNamingConventions.suggestVariableNames( + variableKind, + baseNameKind, + baseName.toCharArray(), + javaProject, + dim, + null, + convertStringToChars(excluded), + evaluateDefault, + requestor); + + return convertCharsToString(requestor.getResults()); } /** @@ -296,13 +361,11 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_PARAMETER} as variable kind. */ public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) { - AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); - return removePrefixAndSuffix( - argumentName, - assistOptions.argumentPrefixes, - assistOptions.argumentSuffixes); + return removeVariablePrefixAndSuffix(VK_PARAMETER, javaProject, argumentName); } /** @@ -327,11 +390,12 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_PARAMETER} as variable kind. */ public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) { return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray())); } - /** * Remove prefix and suffix from a field name. *

@@ -358,14 +422,13 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) { boolean isStatic = Flags.isStatic(modifiers); - AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); - return removePrefixAndSuffix( - fieldName, - isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes, - isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes); + return removeVariablePrefixAndSuffix(isStatic ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, javaProject, fieldName); } /** @@ -394,10 +457,14 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) { return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers)); } + /** * Remove prefix and suffix from a local variable name. *

@@ -420,13 +487,11 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_LOCAL} as variable kind. */ public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) { - AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); - return removePrefixAndSuffix( - localName, - assistOptions.localPrefixes, - assistOptions.localSuffixes); + return removeVariablePrefixAndSuffix(VK_LOCAL, javaProject, localName); } /** @@ -451,11 +516,147 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_LOCAL} as variable kind. */ public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) { return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray())); } + private static char[] removeVariablePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) { + // remove longer prefix + char[] withoutPrefixName = name; + if (prefixes != null) { + int bestLength = 0; + for (int i= 0; i < prefixes.length; i++) { + char[] prefix = prefixes[i]; + if (CharOperation.prefixEquals(prefix, name)) { + int currLen = prefix.length; + boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); + if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { + if (bestLength < currLen && name.length != currLen) { + withoutPrefixName = CharOperation.subarray(name, currLen, name.length); + bestLength = currLen; + } + } + } + } + } + + // remove longer suffix + char[] withoutSuffixName = withoutPrefixName; + if(suffixes != null) { + int bestLength = 0; + for (int i = 0; i < suffixes.length; i++) { + char[] suffix = suffixes[i]; + if(CharOperation.endsWith(withoutPrefixName, suffix)) { + int currLen = suffix.length; + if(bestLength < currLen && withoutPrefixName.length != currLen) { + withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); + bestLength = currLen; + } + } + } + } + + withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); + return withoutSuffixName; + } + + private static char[] removeVariablePrefixAndSuffix( + int variableKind, + IJavaProject javaProject, + char[] name) { + AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); + + char[][] prefixes = null; + char[][] suffixes = null; + switch (variableKind) { + case VK_INSTANCE_FIELD: + prefixes = assistOptions.fieldPrefixes; + suffixes = assistOptions.fieldSuffixes; + break; + case VK_STATIC_FIELD: + prefixes = assistOptions.staticFieldPrefixes; + suffixes = assistOptions.staticFieldSuffixes; + break; + case VK_CONSTANT_FIELD: + prefixes = assistOptions.staticFinalFieldPrefixes; + suffixes = assistOptions.staticFinalFieldSuffixes; + break; + case VK_LOCAL: + prefixes = assistOptions.localPrefixes; + suffixes = assistOptions.localSuffixes; + break; + case VK_PARAMETER: + prefixes = assistOptions.argumentPrefixes; + suffixes = assistOptions.argumentSuffixes; + break; + } + + return removeVariablePrefixAndSuffix(name, prefixes, suffixes); + } + + /** + * Remove prefix and suffix from a variable name. + * + *

+ * The variable can be a local variable, a parameter, an instance field, a static field or a constant field. + * Each type of variable is specified by a variable kind: + *

+ *

+ *

+ * If variable name prefix is pre and variable name suffix is suf + * then for a variable named preVariablesuf the result of this method is variable. + * If there is no prefix or suffix defined in JavaCore options the result is the unchanged + * name preVariablesuf. + *

+ *

+ * For each variable kind this method is affected by the following JavaCore options: + *

+ *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ * + * @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}. + * @param javaProject project which contains the variable. + * @param name variable name. + * @return String the name without prefix and suffix. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + * + * @since 3.5 + */ + public static String removeVariablePrefixAndSuffix( + int variableKind, + IJavaProject javaProject, + String name) { + return String.valueOf(removeVariablePrefixAndSuffix(variableKind, javaProject, name.toCharArray())); + } + + private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { + char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); + if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { + name[0] = ScannerHelper.toUpperCase(name[0]); + } + return name; + } + /** * Suggest names for an argument. The name is computed from argument's type * and possible prefixes or suffixes are added. @@ -483,17 +684,21 @@ * @return char[][] an array of names. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. */ public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { NamingRequestor requestor = new NamingRequestor(); - InternalNamingConventions.suggestArgumentNames( - javaProject, - packageName, - qualifiedTypeName, - dim, - null, - excludedNames, - requestor); + InternalNamingConventions.suggestVariableNames( + VK_PARAMETER, + BK_SIMPLE_TYPE_NAME, + qualifiedTypeName, + javaProject, + dim, + null, + excludedNames, + true, + requestor); return requestor.getResults(); } @@ -525,6 +730,8 @@ * @return char[][] an array of names. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. */ public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { return convertCharsToString( @@ -535,6 +742,7 @@ dim, convertStringToChars(excludedNames))); } + /** * Suggest names for a field. The name is computed from field's type * and possible prefixes or suffixes are added. @@ -566,18 +774,22 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { NamingRequestor requestor = new NamingRequestor(); - InternalNamingConventions.suggestFieldNames( - javaProject, - packageName, - qualifiedTypeName, - dim, - modifiers, - null, - excludedNames, - requestor); + InternalNamingConventions.suggestVariableNames( + Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, + BK_SIMPLE_TYPE_NAME, + qualifiedTypeName, + javaProject, + dim, + null, + excludedNames, + true, + requestor); return requestor.getResults(); } @@ -613,6 +825,9 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) { return convertCharsToString( @@ -624,87 +839,7 @@ modifiers, convertStringToChars(excludedNames))); } - - /** - * Suggest names for a local variable. The name is computed from variable's type - * and possible prefixes or suffixes are added. - *

- * If the type of the local variable is TypeName, the prefix for local variable is pre - * and the suffix for local variable is suf then the proposed names are preTypeNamesuf - * and preNamesuf. If there is no prefix or suffix the proposals are typeName - * and name. - *

- *

- * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and - * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. - *

- *

- * For a complete description of these configurable options, see getDefaultOptions. - * For programmaticaly change these options, see JavaCore#setOptions(). - *

- * - * @param javaProject project which contains the variable. - * @param packageName package of the variable's type. - * @param qualifiedTypeName variable's type. - * @param dim variable's dimension (0 if the variable is not an array). - * @param excludedNames a list of names which cannot be suggested (already used names). - * Can be null if there is no excluded names. - * @return char[][] an array of names. - * @see JavaCore#setOptions(java.util.Hashtable) - * @see JavaCore#getDefaultOptions() - */ - public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { - NamingRequestor requestor = new NamingRequestor(); - InternalNamingConventions.suggestLocalVariableNames( - javaProject, - packageName, - qualifiedTypeName, - dim, - null, - excludedNames, - requestor); - - return requestor.getResults(); - } - - /** - * Suggest names for a local variable. The name is computed from variable's type - * and possible prefixes or suffixes are added. - *

- * If the type of the local variable is TypeName, the prefix for local variable is pre - * and the suffix for local variable is suf then the proposed names are preTypeNamesuf - * and preNamesuf. If there is no prefix or suffix the proposals are typeName - * and name. - *

- *

- * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and - * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. - *

- *

- * For a complete description of these configurable options, see getDefaultOptions. - * For programmaticaly change these options, see JavaCore#setOptions(). - *

- * - * @param javaProject project which contains the variable. - * @param packageName package of the variable's type. - * @param qualifiedTypeName variable's type. - * @param dim variable's dimension (0 if the variable is not an array). - * @param excludedNames a list of names which cannot be suggested (already used names). - * Can be null if there is no excluded names. - * @return char[][] an array of names. - * @see JavaCore#setOptions(java.util.Hashtable) - * @see JavaCore#getDefaultOptions() - */ - public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { - return convertCharsToString( - suggestLocalVariableNames( - javaProject, - packageName.toCharArray(), - qualifiedTypeName.toCharArray(), - dim, - convertStringToChars(excludedNames))); - } - + /** * Suggest name for a getter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -756,7 +891,6 @@ ); } } - /** * Suggest name for a getter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -797,7 +931,109 @@ isBoolean, convertStringToChars(excludedNames))); } + /** + * Suggest names for a local variable. The name is computed from variable's type + * and possible prefixes or suffixes are added. + *

+ * If the type of the local variable is TypeName, the prefix for local variable is pre + * and the suffix for local variable is suf then the proposed names are preTypeNamesuf + * and preNamesuf. If there is no prefix or suffix the proposals are typeName + * and name. + *

+ *

+ * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and + * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. + *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ * + * @param javaProject project which contains the variable. + * @param packageName package of the variable's type. + * @param qualifiedTypeName variable's type. + * @param dim variable's dimension (0 if the variable is not an array). + * @param excludedNames a list of names which cannot be suggested (already used names). + * Can be null if there is no excluded names. + * @return char[][] an array of names. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. + */ + public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { + NamingRequestor requestor = new NamingRequestor(); + InternalNamingConventions.suggestVariableNames( + VK_LOCAL, + BK_SIMPLE_TYPE_NAME, + qualifiedTypeName, + javaProject, + dim, + null, + excludedNames, + true, + requestor); + + return requestor.getResults(); + } + /** + * Suggest names for a local variable. The name is computed from variable's type + * and possible prefixes or suffixes are added. + *

+ * If the type of the local variable is TypeName, the prefix for local variable is pre + * and the suffix for local variable is suf then the proposed names are preTypeNamesuf + * and preNamesuf. If there is no prefix or suffix the proposals are typeName + * and name. + *

+ *

+ * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and + * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. + *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ * + * @param javaProject project which contains the variable. + * @param packageName package of the variable's type. + * @param qualifiedTypeName variable's type. + * @param dim variable's dimension (0 if the variable is not an array). + * @param excludedNames a list of names which cannot be suggested (already used names). + * Can be null if there is no excluded names. + * @return char[][] an array of names. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. + */ + public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { + return convertCharsToString( + suggestLocalVariableNames( + javaProject, + packageName.toCharArray(), + qualifiedTypeName.toCharArray(), + dim, + convertStringToChars(excludedNames))); + } + private static char[] suggestNewName(char[] name, char[][] excludedNames){ + if(excludedNames == null) { + return name; + } + char[] newName = name; + int count = 2; + int i = 0; + while (i < excludedNames.length) { + if(CharOperation.equals(newName, excludedNames[i], false)) { + newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); + i = 0; + } else { + i++; + } + } + return newName; + } + /** * Suggest name for a setter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -853,7 +1089,6 @@ ); } } - /** * Suggest name for a setter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -893,53 +1128,8 @@ isBoolean, convertStringToChars(excludedNames))); } - - private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { - char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); - if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { - name[0] = ScannerHelper.toUpperCase(name[0]); - } - return name; - } - - private static char[] suggestNewName(char[] name, char[][] excludedNames){ - if(excludedNames == null) { - return name; - } - - char[] newName = name; - int count = 2; - int i = 0; - while (i < excludedNames.length) { - if(CharOperation.equals(newName, excludedNames[i], false)) { - newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); - i = 0; - } else { - i++; - } - } - return newName; - } - - private static String[] convertCharsToString(char[][] c) { - int length = c == null ? 0 : c.length; - String[] s = new String[length]; - for (int i = 0; i < length; i++) { - s[i] = String.valueOf(c[i]); - } - return s; - } - - private static char[][] convertStringToChars(String[] s) { - int length = s == null ? 0 : s.length; - char[][] c = new char[length][]; - for (int i = 0; i < length; i++) { - if(s[i] == null) { - c[i] = CharOperation.NO_CHAR; - } else { - c[i] = s[i].toCharArray(); - } - } - return c; + + private NamingConventions() { + // Not instantiable } } Index: compiler/org/eclipse/jdt/core/compiler/CharOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CharOperation.java,v retrieving revision 1.85 diff -u -r1.85 CharOperation.java --- compiler/org/eclipse/jdt/core/compiler/CharOperation.java 27 Jun 2008 16:04:14 -0000 1.85 +++ compiler/org/eclipse/jdt/core/compiler/CharOperation.java 23 Sep 2008 08:24:54 -0000 @@ -3582,6 +3582,54 @@ } /** + * Answers the result of a char[] conversion to uppercase. Answers null if the given chars array is null. + *
+ * NOTE: If no conversion was necessary, then answers back the argument one. + *
+ *
+ * For example: + *
    + *
  1. + *    chars = { 'A' , 'B' }
    + *    result => { 'A' , 'B' }
    + * 
    + *
  2. + *
  3. + *    array = { 'a', 'B' }
    + *    result => { 'A' , 'B' }
    + * 
    + *
  4. + *
+ * + * @param chars the chars to convert + * @return the result of a char[] conversion to uppercase + * + * @since 3.5 + */ +final static public char[] toUpperCase(char[] chars) { + if (chars == null) + return null; + int length = chars.length; + char[] upperChars = null; + for (int i = 0; i < length; i++) { + char c = chars[i]; + char lc = ScannerHelper.toUpperCase(c); + if ((c != lc) || (upperChars != null)) { + if (upperChars == null) { + System.arraycopy( + chars, + 0, + upperChars = new char[length], + 0, + i); + } + upperChars[i] = lc; + } + } + return upperChars == null ? chars : upperChars; +} + +/** * Answers a new array removing leading and trailing spaces (' '). Answers the given array if there is no * space characters to remove. *
Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java,v retrieving revision 1.28 diff -u -r1.28 AssistOptions.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java 27 Jun 2008 16:04:06 -0000 1.28 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java 23 Sep 2008 08:24:54 -0000 @@ -28,6 +28,8 @@ "org.eclipse.jdt.core.codeComplete.fieldPrefixes"; //$NON-NLS-1$ public static final String OPTION_StaticFieldPrefixes = "org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"; //$NON-NLS-1$ + public static final String OPTION_StaticFinalFieldPrefixes = + "org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"; //$NON-NLS-1$ public static final String OPTION_LocalPrefixes = "org.eclipse.jdt.core.codeComplete.localPrefixes"; //$NON-NLS-1$ public static final String OPTION_ArgumentPrefixes = @@ -36,6 +38,8 @@ "org.eclipse.jdt.core.codeComplete.fieldSuffixes"; //$NON-NLS-1$ public static final String OPTION_StaticFieldSuffixes = "org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"; //$NON-NLS-1$ + public static final String OPTION_StaticFinalFieldSuffixes = + "org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"; //$NON-NLS-1$ public static final String OPTION_LocalSuffixes = "org.eclipse.jdt.core.codeComplete.localSuffixes"; //$NON-NLS-1$ public static final String OPTION_ArgumentSuffixes = @@ -61,10 +65,12 @@ public boolean suggestStaticImport = true; public char[][] fieldPrefixes = null; public char[][] staticFieldPrefixes = null; + public char[][] staticFinalFieldPrefixes = null; public char[][] localPrefixes = null; public char[][] argumentPrefixes = null; public char[][] fieldSuffixes = null; public char[][] staticFieldSuffixes = null; + public char[][] staticFinalFieldSuffixes = null; public char[][] localSuffixes = null; public char[][] argumentSuffixes = null; @@ -121,6 +127,16 @@ } } } + if ((optionValue = optionsMap.get(OPTION_StaticFinalFieldPrefixes)) != null) { + if (optionValue instanceof String) { + String stringValue = (String) optionValue; + if (stringValue.length() > 0){ + this.staticFinalFieldPrefixes = splitAndTrimOn(',', stringValue.toCharArray()); + } else { + this.staticFinalFieldPrefixes = null; + } + } + } if ((optionValue = optionsMap.get(OPTION_LocalPrefixes)) != null) { if (optionValue instanceof String) { String stringValue = (String) optionValue; @@ -161,6 +177,16 @@ } } } + if ((optionValue = optionsMap.get(OPTION_StaticFinalFieldSuffixes)) != null) { + if (optionValue instanceof String) { + String stringValue = (String) optionValue; + if (stringValue.length() > 0){ + this.staticFinalFieldSuffixes = splitAndTrimOn(',', stringValue.toCharArray()); + } else { + this.staticFinalFieldSuffixes = null; + } + } + } if ((optionValue = optionsMap.get(OPTION_LocalSuffixes)) != null) { if (optionValue instanceof String) { String stringValue = (String) optionValue; 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.376 diff -u -r1.376 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 18 Sep 2008 14:06:39 -0000 1.376 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 23 Sep 2008 08:24:54 -0000 @@ -262,10 +262,6 @@ private final static int SUPERTYPE = 1; private final static int SUBTYPE = 2; - private final static int FIELD = 0; - private final static int LOCAL = 1; - private final static int ARGUMENT = 2; - int expectedTypesPtr = -1; TypeBinding[] expectedTypes = new TypeBinding[1]; int expectedTypesFilter; @@ -1585,8 +1581,15 @@ } this.completionToken = method.selector; - - findVariableNames(this.completionToken, method.returnType, excludeNames, null, FIELD, method.modifiers); + + int kind = + (method.modifiers & ClassFileConstants.AccStatic) == 0 ? + InternalNamingConventions.VK_INSTANCE_FIELD : + (method.modifiers & ClassFileConstants.AccFinal) == 0 ? + InternalNamingConventions.VK_STATIC_FIELD : + InternalNamingConventions.VK_CONSTANT_FIELD; + + findVariableNames(this.completionToken, method.returnType, excludeNames, null, kind); } } else if (astNode instanceof CompletionOnFieldName) { if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) { @@ -1599,8 +1602,15 @@ } this.completionToken = field.realName; - - findVariableNames(field.realName, field.type, excludeNames, null, FIELD, field.modifiers); + + int kind = + (field.modifiers & ClassFileConstants.AccStatic) == 0 ? + InternalNamingConventions.VK_INSTANCE_FIELD : + (field.modifiers & ClassFileConstants.AccFinal) == 0 ? + InternalNamingConventions.VK_STATIC_FIELD : + InternalNamingConventions.VK_CONSTANT_FIELD; + + findVariableNames(field.realName, field.type, excludeNames, null, kind); } } else if (astNode instanceof CompletionOnLocalName || astNode instanceof CompletionOnArgumentName) { if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) { @@ -1609,11 +1619,11 @@ int kind; if (variable instanceof CompletionOnLocalName){ this.completionToken = ((CompletionOnLocalName) variable).realName; - kind = LOCAL; + kind = InternalNamingConventions.VK_LOCAL; } else { CompletionOnArgumentName arg = (CompletionOnArgumentName) variable; this.completionToken = arg.realName; - kind = arg.isCatchArgument ? LOCAL : ARGUMENT; + kind = arg.isCatchArgument ? InternalNamingConventions.VK_LOCAL : InternalNamingConventions.VK_PARAMETER; } char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, variable); @@ -1631,7 +1641,7 @@ System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount); - findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind, variable.modifiers); + findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind); } } else if (astNode instanceof CompletionOnKeyword) { if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) { @@ -8898,8 +8908,7 @@ char[][] discouragedNames, final char[][] forbiddenNames, int dim, - int kind, - int modifiers){ + int kind){ findVariableName( token, qualifiedPackageName, @@ -8910,8 +8919,7 @@ forbiddenNames, false, dim, - kind, - modifiers); + kind); } private void findVariableName( char[] token, @@ -8923,8 +8931,7 @@ final char[][] forbiddenNames, boolean forCollection, int dim, - int kind, - int modifiers){ + int kind){ if(sourceName == null || sourceName.length == 0) return; @@ -9004,39 +9011,16 @@ } }; - switch (kind) { - case FIELD : - InternalNamingConventions.suggestFieldNames( - this.javaProject, - qualifiedPackageName, - qualifiedSourceName, - dim, - modifiers, - token, - discouragedNames, - namingRequestor); - break; - case LOCAL : - InternalNamingConventions.suggestLocalVariableNames( - this.javaProject, - qualifiedPackageName, - qualifiedSourceName, - dim, - token, - discouragedNames, - namingRequestor); - break; - case ARGUMENT : - InternalNamingConventions.suggestArgumentNames( - this.javaProject, - qualifiedPackageName, - qualifiedSourceName, - dim, - token, - discouragedNames, - namingRequestor); - break; - } + InternalNamingConventions.suggestVariableNames( + kind, + InternalNamingConventions.BK_SIMPLE_TYPE_NAME, + qualifiedSourceName, + this.javaProject, + dim, + token, + discouragedNames, + true, + namingRequestor); } private void findVariableNameForCollection( @@ -9047,8 +9031,7 @@ final TypeBinding typeBinding, char[][] discouragedNames, final char[][] forbiddenNames, - int kind, - int modifiers){ + int kind){ findVariableName( token, @@ -9060,11 +9043,10 @@ forbiddenNames, false, 1, - kind, - modifiers); + kind); } - private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind, int modifiers){ + private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind){ if(type != null && type.resolvedType != null) { TypeBinding tb = type.resolvedType; @@ -9080,8 +9062,7 @@ discouragedNames, forbiddenNames, type.dimensions(), - kind, - modifiers); + kind); if (tb.isParameterizedType() && tb.findSuperTypeOriginatingFrom(TypeIds.T_JavaUtilCollection, false) != null) { @@ -9097,8 +9078,7 @@ tb, discouragedNames, forbiddenNames, - kind, - modifiers); + kind); } } }