View | Details | Raw Unified | Return to bug 38111 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (-5 / +122 lines)
Lines 5160-5167 Link Here
5160
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5160
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5161
5161
5162
	assertResults(
5162
	assertResults(
5163
			"nameRequestor[VARIABLE_DECLARATION]{nameRequestor, null, Ltest.TypeNameRequestor;, nameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
5163
			"nameTypeNameRequestor[VARIABLE_DECLARATION]{nameTypeNameRequestor, null, Ltest.TypeNameRequestor;, nameTypeNameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
5164
			"nameTypeNameRequestor[VARIABLE_DECLARATION]{nameTypeNameRequestor, null, Ltest.TypeNameRequestor;, nameTypeNameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
5164
			"nameRequestor[VARIABLE_DECLARATION]{nameRequestor, null, Ltest.TypeNameRequestor;, nameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NAME_LESS_NEW_CHARACTERS + R_NON_RESTRICTED) + "}",
5165
			requestor.getResults());
5166
}
5167
5168
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5169
public void testCompletionFieldName3() throws JavaModelException { 
5170
	this.workingCopies = new ICompilationUnit[1];
5171
	this.workingCopies[0] = getWorkingCopy(
5172
		"/Completion/src/test/TypeNameRequestor.java",
5173
		"package test;"+
5174
		"public class TypeNameRequestor {\n" +
5175
		"  public static final TypeNameRequestor \n" +
5176
		"}\n");
5177
5178
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5179
	String str = this.workingCopies[0].getSource();
5180
	String completeBehind = "final TypeNameRequestor ";
5181
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5182
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5183
5184
	assertResults(
5185
			"NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
5186
			"REQUESTOR[VARIABLE_DECLARATION]{REQUESTOR, null, Ltest.TypeNameRequestor;, REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
5187
			"TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
5188
			requestor.getResults());
5189
}
5190
5191
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5192
public void testCompletionFieldName4() throws JavaModelException { 
5193
	this.workingCopies = new ICompilationUnit[1];
5194
	this.workingCopies[0] = getWorkingCopy(
5195
		"/Completion/src/test/TypeNameRequestor.java",
5196
		"package test;"+
5197
		"public class TypeNameRequestor {\n" +
5198
		"  public static final TypeNameRequestor nam\n" +
5199
		"}\n");
5200
5201
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5202
	String str = this.workingCopies[0].getSource();
5203
	String completeBehind = "final TypeNameRequestor nam";
5204
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5205
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5206
5207
	assertResults(
5208
			"NAM_REQUESTOR[VARIABLE_DECLARATION]{NAM_REQUESTOR, null, Ltest.TypeNameRequestor;, NAM_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
5209
			"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" +
5210
			"NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NAME_LESS_NEW_CHARACTERS+ R_NON_RESTRICTED) + "}",
5211
			requestor.getResults());
5212
}
5213
5214
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5215
public void testCompletionFieldName5() throws JavaModelException { 
5216
	this.workingCopies = new ICompilationUnit[1];
5217
	this.workingCopies[0] = getWorkingCopy(
5218
		"/Completion/src/test/TypeNameRequestor.java",
5219
		"package test;"+
5220
		"public class TypeNameRequestor {\n" +
5221
		"  public static final TypeNameRequestor ZZ\n" +
5222
		"}\n");
5223
5224
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5225
	String str = this.workingCopies[0].getSource();
5226
	String completeBehind = "final TypeNameRequestor ZZ";
5227
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5228
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5229
5230
	assertResults(
5231
			"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" +
5232
			"ZZ_REQUESTOR[VARIABLE_DECLARATION]{ZZ_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" +
5233
			"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) + "}",
5234
			requestor.getResults());
5235
}
5236
5237
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5238
public void testCompletionFieldName6() throws JavaModelException { 
5239
	this.workingCopies = new ICompilationUnit[1];
5240
	this.workingCopies[0] = getWorkingCopy(
5241
		"/Completion/src/test/TypeNameRequestor.java",
5242
		"package test;"+
5243
		"public class TypeNameRequestor {\n" +
5244
		"  public static final TypeNameRequestor ZZN\n" +
5245
		"}\n");
5246
5247
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5248
	String str = this.workingCopies[0].getSource();
5249
	String completeBehind = "final TypeNameRequestor ZZN";
5250
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5251
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5252
5253
	assertResults(
5254
			"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" +
5255
			"ZZN_REQUESTOR[VARIABLE_DECLARATION]{ZZN_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" +
5256
			"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) + "}",
5257
			requestor.getResults());
5258
}
5259
5260
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5261
public void testCompletionFieldName7() throws JavaModelException { 
5262
	this.workingCopies = new ICompilationUnit[1];
5263
	this.workingCopies[0] = getWorkingCopy(
5264
		"/Completion/src/test/TypeNameRequestor.java",
5265
		"package test;"+
5266
		"public class TypeNameRequestor {\n" +
5267
		"  public static final TypeNameRequestor ZZ_N\n" +
5268
		"}\n");
5269
5270
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5271
	String str = this.workingCopies[0].getSource();
5272
	String completeBehind = "final TypeNameRequestor ZZ_N";
5273
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5274
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5275
5276
	assertResults(
5277
			"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" +
5278
			"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" +
5279
			"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) + "}",
5165
			requestor.getResults());
5280
			requestor.getResults());
5166
}
5281
}
5167
5282
Lines 13906-13912 Link Here
13906
14021
13907
	assertEquals(
14022
	assertEquals(
13908
		"element:class1    completion:class1    relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14023
		"element:class1    completion:class1    relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
13909
		"element:myClass    completion:myClass    relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED),
14024
		"element:fooMyClass    completion:fooMyClass    relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14025
		"element:myClass    completion:myClass    relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14026
		"element:testFooMyClass    completion:testFooMyClass    relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED),
13910
		requestor.getResults());
14027
		requestor.getResults());
13911
}
14028
}
13912
public void testCompletionVariableName10() throws JavaModelException {
14029
public void testCompletionVariableName10() throws JavaModelException {
Lines 14296-14305 Link Here
14296
	cu.codeComplete(cursorLocation, requestor);
14413
	cu.codeComplete(cursorLocation, requestor);
14297
14414
14298
	assertEquals(
14415
	assertEquals(
14299
		"element:bar_MyClass    completion:bar_MyClass    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14416
		"element:barMyClass    completion:barMyClass    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14300
		"element:class1    completion:class1    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14417
		"element:class1    completion:class1    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14301
		"element:myClass    completion:myClass    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14418
		"element:myClass    completion:myClass    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" +
14302
		"element:test_Bar_MyClass    completion:test_Bar_MyClass    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE+ R_NON_RESTRICTED),
14419
		"element:testBarMyClass    completion:testBarMyClass    relevance:"+(R_DEFAULT  + R_INTERESTING + R_CASE+ R_NON_RESTRICTED),
14303
		requestor.getResults());
14420
		requestor.getResults());
14304
}
14421
}
14305
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228
14422
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228
(-)src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java (-202 / +627 lines)
Lines 41-47 Link Here
41
	super.setUp();
41
	super.setUp();
42
	this.project = createJavaProject("P", new String[]{"src"}, "bin"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
42
	this.project = createJavaProject("P", new String[]{"src"}, "bin"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
43
	this.oldOptions = JavaCore.getOptions();
43
	this.oldOptions = JavaCore.getOptions();
44
	this.abortOnFailure = false; // some tests have failing one time on macos boxes => do not abort on failures
44
//	this.abortOnFailure = false; // some tests have failing one time on macos boxes => do not abort on failures
45
}
45
}
46
/**
46
/**
47
 * Cleanup after the previous test.
47
 * Cleanup after the previous test.
Lines 53-97 Link Here
53
53
54
	super.tearDown();
54
	super.tearDown();
55
}
55
}
56
private String toString(char[][] suggestions) {
56
/*
57
	if(suggestions == null) {
57
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
58
		return ""; //$NON-NLS-1$
58
 */
59
	}
59
public void testGetBaseName001() {
60
60
	String baseName = NamingConventions.getBaseName(
61
	StringBuffer buffer = new StringBuffer();
61
			NamingConventions.VK_INSTANCE_FIELD,
62
	for (int i = 0; i < suggestions.length; i++) {
62
			"OneName", //$NON-NLS-1$
63
		if(i != 0) {
63
			this.project);
64
			buffer.append('\n');
64
	
65
		}
65
	assertEquals(
66
		buffer.append(suggestions[i]);
66
			"OneName", //$NON-NLS-1$
67
	}
67
			baseName);
68
	return buffer.toString();
68
}
69
/*
70
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
71
 */
72
public void testGetBaseName002() {
73
	String baseName = NamingConventions.getBaseName(
74
			NamingConventions.VK_CONSTANT_FIELD,
75
			"ONE_NAME", //$NON-NLS-1$
76
			this.project);
77
	
78
	assertEquals(
79
			"OneName", //$NON-NLS-1$
80
			baseName);
81
}
82
/*
83
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
84
 */
85
public void testGetBaseName003() {
86
	Hashtable options = JavaCore.getOptions();
87
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
88
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
89
	JavaCore.setOptions(options);
90
	
91
	String baseName = NamingConventions.getBaseName(
92
			NamingConventions.VK_INSTANCE_FIELD,
93
			"preOneNamesuf", //$NON-NLS-1$
94
			this.project);
95
	
96
	assertEquals(
97
			"OneName", //$NON-NLS-1$
98
			baseName);
99
}
100
/*
101
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
102
 */
103
public void testGetBaseName004() {
104
	Hashtable options = JavaCore.getOptions();
105
	options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
106
	options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
107
	JavaCore.setOptions(options);
108
	
109
	String baseName = NamingConventions.getBaseName(
110
			NamingConventions.VK_CONSTANT_FIELD,
111
			"preONE_NAMEsuf", //$NON-NLS-1$
112
			this.project);
113
	
114
	assertEquals(
115
			"OneName", //$NON-NLS-1$
116
			baseName);
69
}
117
}
70
public void testSuggestFieldName001() {
118
public void testSuggestFieldName001() {
71
	char[][] suggestions = NamingConventions.suggestFieldNames(
119
	String[] suggestions = NamingConventions.suggestVariableNames(
72
		this.project,
120
			NamingConventions.VK_INSTANCE_FIELD,
73
		"a.b.c".toCharArray(), //$NON-NLS-1$
121
			NamingConventions.BK_TYPE_NAME,
74
		"OneName".toCharArray(), //$NON-NLS-1$
122
			"OneName", //$NON-NLS-1$
75
		0,
123
			this.project,
76
		0,
124
			0,
77
		CharOperation.NO_CHAR_CHAR);
125
			new String[]{},
126
			true);
127
78
	assumeEquals(
128
	assumeEquals(
79
		"name\n" + //$NON-NLS-1$
129
		"oneName\n" + //$NON-NLS-1$
80
		"oneName", //$NON-NLS-1$
130
		"name", //$NON-NLS-1$
81
		toString(suggestions));
131
		toString(suggestions));
82
}
132
}
83
public void testSuggestFieldName002() {
133
public void testSuggestFieldName002() {
84
	char[][] suggestions = NamingConventions.suggestFieldNames(
134
	String[] suggestions = NamingConventions.suggestVariableNames(
85
		this.project,
135
			NamingConventions.VK_INSTANCE_FIELD,
86
		"a.b.c".toCharArray(), //$NON-NLS-1$
136
			NamingConventions.BK_TYPE_NAME,
87
		"OneClass".toCharArray(), //$NON-NLS-1$
137
			"OneClass", //$NON-NLS-1$
88
		0,
138
			this.project,
89
		0,
139
			0,
90
		CharOperation.NO_CHAR_CHAR);
140
			new String[]{},
91
141
			true);
142
	
92
	assumeEquals(
143
	assumeEquals(
93
		"class1\n" + //$NON-NLS-1$
144
		"oneClass\n" + //$NON-NLS-1$
94
		"oneClass", //$NON-NLS-1$
145
		"class1", //$NON-NLS-1$
95
		toString(suggestions));
146
		toString(suggestions));
96
}
147
}
97
public void testSuggestFieldName003() {
148
public void testSuggestFieldName003() {
Lines 99-117 Link Here
99
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
150
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
100
	JavaCore.setOptions(options);
151
	JavaCore.setOptions(options);
101
152
102
	char[][] suggestions = NamingConventions.suggestFieldNames(
153
	String[] suggestions = NamingConventions.suggestVariableNames(
103
		this.project,
154
			NamingConventions.VK_INSTANCE_FIELD,
104
		"a.b.c".toCharArray(), //$NON-NLS-1$
155
			NamingConventions.BK_TYPE_NAME,
105
		"OneName".toCharArray(), //$NON-NLS-1$
156
			"OneName", //$NON-NLS-1$
106
		0,
157
			this.project,
107
		0,
158
			0,
108
		CharOperation.NO_CHAR_CHAR);
159
			new String[]{},
160
			true);
109
161
110
	assumeEquals(
162
	assumeEquals(
111
		"fName\n" + //$NON-NLS-1$
112
		"fOneName\n" + //$NON-NLS-1$
163
		"fOneName\n" + //$NON-NLS-1$
113
		"name\n" + //$NON-NLS-1$
164
		"fName\n" + //$NON-NLS-1$
114
		"oneName", //$NON-NLS-1$
165
		"oneName\n" + //$NON-NLS-1$
166
		"name", //$NON-NLS-1$
115
		toString(suggestions));
167
		toString(suggestions));
116
}
168
}
117
public void testSuggestFieldName004() {
169
public void testSuggestFieldName004() {
Lines 119-137 Link Here
119
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"_"); //$NON-NLS-1$
171
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"_"); //$NON-NLS-1$
120
	JavaCore.setOptions(options);
172
	JavaCore.setOptions(options);
121
173
122
	char[][] suggestions = NamingConventions.suggestFieldNames(
174
	String[] suggestions = NamingConventions.suggestVariableNames(
123
		this.project,
175
			NamingConventions.VK_INSTANCE_FIELD,
124
		"a.b.c".toCharArray(), //$NON-NLS-1$
176
			NamingConventions.BK_TYPE_NAME,
125
		"OneName".toCharArray(), //$NON-NLS-1$
177
			"OneName", //$NON-NLS-1$
126
		0,
178
			this.project,
127
		0,
179
			0,
128
		CharOperation.NO_CHAR_CHAR);
180
			new String[]{},
181
			true);
129
182
130
	assumeEquals(
183
	assumeEquals(
131
		"_name\n" + //$NON-NLS-1$
132
		"_oneName\n" + //$NON-NLS-1$
184
		"_oneName\n" + //$NON-NLS-1$
133
		"name\n" + //$NON-NLS-1$
185
		"_name\n" + //$NON-NLS-1$
134
		"oneName", //$NON-NLS-1$
186
		"oneName\n" + //$NON-NLS-1$
187
		"name", //$NON-NLS-1$
135
		toString(suggestions));
188
		toString(suggestions));
136
}
189
}
137
public void testSuggestFieldName005() {
190
public void testSuggestFieldName005() {
Lines 139-158 Link Here
139
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
192
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
140
	options.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,"fg"); //$NON-NLS-1$
193
	options.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,"fg"); //$NON-NLS-1$
141
	JavaCore.setOptions(options);
194
	JavaCore.setOptions(options);
142
195
	
143
	char[][] suggestions = NamingConventions.suggestFieldNames(
196
	String[] suggestions = NamingConventions.suggestVariableNames(
144
		this.project,
197
			NamingConventions.VK_STATIC_FIELD,
145
		"a.b.c".toCharArray(), //$NON-NLS-1$
198
			NamingConventions.BK_TYPE_NAME,
146
		"OneName".toCharArray(), //$NON-NLS-1$
199
			"OneName", //$NON-NLS-1$
147
		0,
200
			this.project,
148
		Flags.AccStatic,
201
			0,
149
		CharOperation.NO_CHAR_CHAR);
202
			new String[]{},
203
			true);
150
204
151
	assumeEquals(
205
	assumeEquals(
152
		"fgName\n" + //$NON-NLS-1$
153
		"fgOneName\n" + //$NON-NLS-1$
206
		"fgOneName\n" + //$NON-NLS-1$
154
		"name\n" + //$NON-NLS-1$
207
		"fgName\n" + //$NON-NLS-1$
155
		"oneName", //$NON-NLS-1$
208
		"oneName\n" + //$NON-NLS-1$
209
		"name", //$NON-NLS-1$
156
		toString(suggestions));
210
		toString(suggestions));
157
}
211
}
158
public void testSuggestFieldName006() {
212
public void testSuggestFieldName006() {
Lines 161-183 Link Here
161
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
215
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
162
	JavaCore.setOptions(options);
216
	JavaCore.setOptions(options);
163
217
164
	char[][] suggestions = NamingConventions.suggestFieldNames(
218
	String[] suggestions = NamingConventions.suggestVariableNames(
165
		this.project,
219
			NamingConventions.VK_INSTANCE_FIELD,
166
		"a.b.c".toCharArray(), //$NON-NLS-1$
220
			NamingConventions.BK_TYPE_NAME,
167
		"OneName".toCharArray(), //$NON-NLS-1$
221
			"OneName", //$NON-NLS-1$
168
		0,
222
			this.project,
169
		0,
223
			0,
170
		CharOperation.NO_CHAR_CHAR);
224
			new String[]{},
225
			true);
171
226
172
	assumeEquals(
227
	assumeEquals(
173
		"preNamesuf\n" + //$NON-NLS-1$
174
		"preOneNamesuf\n" + //$NON-NLS-1$
228
		"preOneNamesuf\n" + //$NON-NLS-1$
175
		"preName\n" + //$NON-NLS-1$
229
		"preNamesuf\n" + //$NON-NLS-1$
176
		"preOneName\n" + //$NON-NLS-1$
230
		"preOneName\n" + //$NON-NLS-1$
177
		"namesuf\n" + //$NON-NLS-1$
231
		"preName\n" + //$NON-NLS-1$
178
		"oneNamesuf\n" + //$NON-NLS-1$
232
		"oneNamesuf\n" + //$NON-NLS-1$
179
		"name\n" + //$NON-NLS-1$
233
		"namesuf\n" + //$NON-NLS-1$
180
		"oneName", //$NON-NLS-1$
234
		"oneName\n" + //$NON-NLS-1$
235
		"name", //$NON-NLS-1$
181
		toString(suggestions));
236
		toString(suggestions));
182
}
237
}
183
public void testSuggestFieldName007() {
238
public void testSuggestFieldName007() {
Lines 186-198 Link Here
186
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
241
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
187
	JavaCore.setOptions(options);
242
	JavaCore.setOptions(options);
188
243
189
	char[][] suggestions = NamingConventions.suggestFieldNames(
244
	String[] suggestions = NamingConventions.suggestVariableNames(
190
		this.project,
245
			NamingConventions.VK_INSTANCE_FIELD,
191
		"a.b.c".toCharArray(), //$NON-NLS-1$
246
			NamingConventions.BK_TYPE_NAME,
192
		"int".toCharArray(), //$NON-NLS-1$
247
			"int", //$NON-NLS-1$
193
		0,
248
			this.project,
194
		0,
249
			0,
195
		CharOperation.NO_CHAR_CHAR);
250
			new String[]{},
251
			true);
196
252
197
	assumeEquals(
253
	assumeEquals(
198
		"preIsuf\n" + //$NON-NLS-1$
254
		"preIsuf\n" + //$NON-NLS-1$
Lines 202-218 Link Here
202
		toString(suggestions));
258
		toString(suggestions));
203
}
259
}
204
public void testSuggestFieldName008() {
260
public void testSuggestFieldName008() {
205
	char[][] suggestions = NamingConventions.suggestFieldNames(
261
	String[] suggestions = NamingConventions.suggestVariableNames(
206
		this.project,
262
			NamingConventions.VK_INSTANCE_FIELD,
207
		"a.b.c".toCharArray(), //$NON-NLS-1$
263
			NamingConventions.BK_TYPE_NAME,
208
		"OneName".toCharArray(), //$NON-NLS-1$
264
			"OneName", //$NON-NLS-1$
209
		0,
265
			this.project,
210
		0,
266
			0,
211
		new char[][]{"name".toCharArray()}); //$NON-NLS-1$
267
			new String[]{"name"}, //$NON-NLS-1$
268
			true);
212
269
213
	assumeEquals(
270
	assumeEquals(
214
		"name2\n" + //$NON-NLS-1$
271
		"oneName\n" + //$NON-NLS-1$
215
		"oneName", //$NON-NLS-1$
272
		"name2", //$NON-NLS-1$
216
		toString(suggestions));
273
		toString(suggestions));
217
}
274
}
218
public void testSuggestFieldName009() {
275
public void testSuggestFieldName009() {
Lines 221-243 Link Here
221
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
278
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
222
	JavaCore.setOptions(options);
279
	JavaCore.setOptions(options);
223
280
224
	char[][] suggestions = NamingConventions.suggestFieldNames(
281
	String[] suggestions = NamingConventions.suggestVariableNames(
225
		this.project,
282
			NamingConventions.VK_INSTANCE_FIELD,
226
		"a.b.c".toCharArray(), //$NON-NLS-1$
283
			NamingConventions.BK_TYPE_NAME,
227
		"OneName".toCharArray(), //$NON-NLS-1$
284
			"OneName", //$NON-NLS-1$
228
		0,
285
			this.project,
229
		0,
286
			0,
230
		new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$
287
			new String[]{"preNamesuf"}, //$NON-NLS-1$
231
288
			true);
289
	
232
	assumeEquals(
290
	assumeEquals(
233
		"preName2suf\n" + //$NON-NLS-1$
234
		"preOneNamesuf\n" + //$NON-NLS-1$
291
		"preOneNamesuf\n" + //$NON-NLS-1$
235
		"preName\n" + //$NON-NLS-1$
292
		"preName2suf\n" + //$NON-NLS-1$
236
		"preOneName\n" + //$NON-NLS-1$
293
		"preOneName\n" + //$NON-NLS-1$
237
		"namesuf\n" + //$NON-NLS-1$
294
		"preName\n" + //$NON-NLS-1$
238
		"oneNamesuf\n" + //$NON-NLS-1$
295
		"oneNamesuf\n" + //$NON-NLS-1$
239
		"name\n" + //$NON-NLS-1$
296
		"namesuf\n" + //$NON-NLS-1$
240
		"oneName", //$NON-NLS-1$
297
		"oneName\n" + //$NON-NLS-1$
298
		"name", //$NON-NLS-1$
241
		toString(suggestions));
299
		toString(suggestions));
242
}
300
}
243
public void testSuggestFieldName010() {
301
public void testSuggestFieldName010() {
Lines 245-344 Link Here
245
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
303
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
246
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
304
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
247
	JavaCore.setOptions(options);
305
	JavaCore.setOptions(options);
248
306
	
249
	char[][] suggestions = NamingConventions.suggestFieldNames(
307
	String[] suggestions = NamingConventions.suggestVariableNames(
250
		this.project,
308
			NamingConventions.VK_INSTANCE_FIELD,
251
		"a.b.c".toCharArray(), //$NON-NLS-1$
309
			NamingConventions.BK_TYPE_NAME,
252
		"OneName".toCharArray(), //$NON-NLS-1$
310
			"OneName", //$NON-NLS-1$
253
		1,
311
			this.project,
254
		0,
312
			1,
255
		new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$
313
			new String[]{"preNamesuf"}, //$NON-NLS-1$
314
			true);
256
315
257
	assumeEquals(
316
	assumeEquals(
258
		"preNamessuf\n" + //$NON-NLS-1$
259
		"preOneNamessuf\n" + //$NON-NLS-1$
317
		"preOneNamessuf\n" + //$NON-NLS-1$
260
		"preNames\n" + //$NON-NLS-1$
318
		"preNamessuf\n" + //$NON-NLS-1$
261
		"preOneNames\n" + //$NON-NLS-1$
319
		"preOneNames\n" + //$NON-NLS-1$
262
		"namessuf\n" + //$NON-NLS-1$
320
		"preNames\n" + //$NON-NLS-1$
263
		"oneNamessuf\n" + //$NON-NLS-1$
321
		"oneNamessuf\n" + //$NON-NLS-1$
264
		"names\n" + //$NON-NLS-1$
322
		"namessuf\n" + //$NON-NLS-1$
265
		"oneNames", //$NON-NLS-1$
323
		"oneNames\n" + //$NON-NLS-1$
324
		"names", //$NON-NLS-1$
266
		toString(suggestions));
325
		toString(suggestions));
267
}
326
}
268
public void testSuggestFieldName011() {
327
public void testSuggestFieldName011() {
269
	char[][] suggestions = NamingConventions.suggestFieldNames(
328
	
270
		this.project,
329
	String[] suggestions = NamingConventions.suggestVariableNames(
271
		"a.b.c".toCharArray(), //$NON-NLS-1$
330
			NamingConventions.VK_INSTANCE_FIELD,
272
		"Factory".toCharArray(), //$NON-NLS-1$
331
			NamingConventions.BK_TYPE_NAME,
273
		1,
332
			"Factory", //$NON-NLS-1$
274
		0,
333
			this.project,
275
		CharOperation.NO_CHAR_CHAR); //$NON-NLS-1$
334
			1,
335
			new String[]{},
336
			true);
276
337
277
	assumeEquals(
338
	assumeEquals(
278
		"factories", //$NON-NLS-1$
339
		"factories", //$NON-NLS-1$
279
		toString(suggestions));
340
		toString(suggestions));
280
}
341
}
281
public void testSuggestFieldName012() {
342
public void testSuggestFieldName012() {
282
	String[] suggestions = NamingConventions.suggestFieldNames(
343
	String[] suggestions = NamingConventions.suggestVariableNames(
283
		this.project,
344
			NamingConventions.VK_INSTANCE_FIELD,
284
		"a.b.c", //$NON-NLS-1$
345
			NamingConventions.BK_TYPE_NAME,
285
		"FooBar", //$NON-NLS-1$
346
			"FooBar", //$NON-NLS-1$
286
		0,
347
			this.project,
287
		0,
348
			0,
288
		new String[]{"bar"}); //$NON-NLS-1$
349
			new String[]{"bar"}, //$NON-NLS-1$
350
			true);
289
351
290
	assumeEquals(
352
	assumeEquals(
291
		"bar2\n" + //$NON-NLS-1$
353
		"fooBar\n" + //$NON-NLS-1$
292
		"fooBar", //$NON-NLS-1$
354
		"bar2", //$NON-NLS-1$
293
		toString(suggestions));
355
		toString(suggestions));
294
}
356
}
295
public void testSuggestFieldName013() {
357
public void testSuggestFieldName013() {
296
	char[][] suggestions = NamingConventions.suggestFieldNames(
358
	String[] suggestions = NamingConventions.suggestVariableNames(
297
		this.project,
359
			NamingConventions.VK_INSTANCE_FIELD,
298
		"java.lang".toCharArray(), //$NON-NLS-1$
360
			NamingConventions.BK_TYPE_NAME,
299
		"Class".toCharArray(), //$NON-NLS-1$
361
			"Class", //$NON-NLS-1$
300
		0,
362
			this.project,
301
		0,
363
			0,
302
		CharOperation.NO_CHAR_CHAR);
364
			new String[]{},
365
			true);
303
366
304
	assumeEquals(
367
	assumeEquals(
305
		"class1",//$NON-NLS-1$
368
		"class1",//$NON-NLS-1$
306
		toString(suggestions));
369
		toString(suggestions));
307
}
370
}
308
public void testSuggestFieldName014() {
371
public void testSuggestFieldName014() {
309
	char[][] suggestions = NamingConventions.suggestFieldNames(
372
	String[] suggestions = NamingConventions.suggestVariableNames(
310
		this.project,
373
			NamingConventions.VK_INSTANCE_FIELD,
311
		"java.lang".toCharArray(), //$NON-NLS-1$
374
			NamingConventions.BK_TYPE_NAME,
312
		"Class".toCharArray(), //$NON-NLS-1$
375
			"Class", //$NON-NLS-1$
313
		0,
376
			this.project,
314
		0,
377
			0,
315
		new char[][]{"class1".toCharArray()}); //$NON-NLS-1$
378
			new String[]{"class1"}, //$NON-NLS-1$
379
			true);
316
380
317
	assumeEquals(
381
	assumeEquals(
318
		"class2",//$NON-NLS-1$
382
		"class2",//$NON-NLS-1$
319
		toString(suggestions));
383
		toString(suggestions));
320
}
384
}
321
public void testSuggestFieldName015() {
385
public void testSuggestFieldName015() {
322
	char[][] suggestions = NamingConventions.suggestFieldNames(
386
	String[] suggestions = NamingConventions.suggestVariableNames(
323
		this.project,
387
			NamingConventions.VK_INSTANCE_FIELD,
324
		"".toCharArray(), //$NON-NLS-1$
388
			NamingConventions.BK_TYPE_NAME,
325
		"#".toCharArray(), //$NON-NLS-1$
389
			"#", //$NON-NLS-1$
326
		0,
390
			this.project,
327
		0,
391
			0,
328
		CharOperation.NO_CHAR_CHAR);
392
			new String[]{},
393
			true);
329
394
330
	assumeEquals(
395
	assumeEquals(
331
		"name",//$NON-NLS-1$
396
		"name",//$NON-NLS-1$
332
		toString(suggestions));
397
		toString(suggestions));
333
}
398
}
334
public void testSuggestFieldName016() {
399
public void testSuggestFieldName016() {
335
	char[][] suggestions = NamingConventions.suggestFieldNames(
400
	String[] suggestions = NamingConventions.suggestVariableNames(
336
		this.project,
401
			NamingConventions.VK_INSTANCE_FIELD,
337
		"".toCharArray(), //$NON-NLS-1$
402
			NamingConventions.BK_TYPE_NAME,
338
		"#".toCharArray(), //$NON-NLS-1$
403
			"#", //$NON-NLS-1$
339
		0,
404
			this.project,
340
		0,
405
			0,
341
		new char[][]{"name".toCharArray()}); //$NON-NLS-1$
406
			new String[]{"name"}, //$NON-NLS-1$
407
			true);
342
408
343
	assumeEquals(
409
	assumeEquals(
344
		"name2",//$NON-NLS-1$
410
		"name2",//$NON-NLS-1$
Lines 348-360 Link Here
348
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
414
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
349
 */
415
 */
350
public void testSuggestFieldName017() {
416
public void testSuggestFieldName017() {
351
	char[][] suggestions = NamingConventions.suggestFieldNames(
417
	String[] suggestions = NamingConventions.suggestVariableNames(
352
		this.project,
418
			NamingConventions.VK_INSTANCE_FIELD,
353
		"".toCharArray(), //$NON-NLS-1$
419
			NamingConventions.BK_TYPE_NAME,
354
		"names".toCharArray(), //$NON-NLS-1$
420
			"names", //$NON-NLS-1$
355
		0,
421
			this.project,
356
		0,
422
			0,
357
		new char[][]{});
423
			new String[]{},
424
			true);
358
425
359
	assumeEquals(
426
	assumeEquals(
360
		"names",//$NON-NLS-1$
427
		"names",//$NON-NLS-1$
Lines 364-376 Link Here
364
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
431
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
365
 */
432
 */
366
public void testSuggestFieldName018() {
433
public void testSuggestFieldName018() {
367
	char[][] suggestions = NamingConventions.suggestFieldNames(
434
	String[] suggestions = NamingConventions.suggestVariableNames(
368
		this.project,
435
			NamingConventions.VK_INSTANCE_FIELD,
369
		"".toCharArray(), //$NON-NLS-1$
436
			NamingConventions.BK_TYPE_NAME,
370
		"names".toCharArray(), //$NON-NLS-1$
437
			"names", //$NON-NLS-1$
371
		1,
438
			this.project,
372
		0,
439
			1,
373
		new char[][]{});
440
			new String[]{},
441
			true);
374
442
375
	assumeEquals(
443
	assumeEquals(
376
		"names",//$NON-NLS-1$
444
		"names",//$NON-NLS-1$
Lines 380-415 Link Here
380
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
448
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
381
 */
449
 */
382
public void testSuggestFieldName019() {
450
public void testSuggestFieldName019() {
383
	char[][] suggestions = NamingConventions.suggestFieldNames(
451
	String[] suggestions = NamingConventions.suggestVariableNames(
384
		this.project,
452
			NamingConventions.VK_INSTANCE_FIELD,
385
		"".toCharArray(), //$NON-NLS-1$
453
			NamingConventions.BK_TYPE_NAME,
386
		"MyClass".toCharArray(), //$NON-NLS-1$
454
			"MyClass", //$NON-NLS-1$
387
		0,
455
			this.project,
388
		0,
456
			0,
389
		new char[][]{});
457
			new String[]{},
458
			true);
390
459
391
	assumeEquals(
460
	assumeEquals(
392
		"class1\n" + //$NON-NLS-1$
461
		"myClass\n" + //$NON-NLS-1$
393
		"myClass", //$NON-NLS-1$
462
		"class1", //$NON-NLS-1$
394
		toString(suggestions));
463
		toString(suggestions));
395
}
464
}
396
/*
465
/*
397
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
466
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
398
 */
467
 */
399
public void testSuggestFieldName020() {
468
public void testSuggestFieldName020() {
400
	char[][] suggestions = NamingConventions.suggestFieldNames(
469
	String[] suggestions = NamingConventions.suggestVariableNames(
401
		this.project,
470
			NamingConventions.VK_INSTANCE_FIELD,
402
		"".toCharArray(), //$NON-NLS-1$
471
			NamingConventions.BK_TYPE_NAME,
403
		"MyClass".toCharArray(), //$NON-NLS-1$
472
			"MyClass", //$NON-NLS-1$
404
		1,
473
			this.project,
405
		0,
474
			1,
406
		new char[][]{});
475
			new String[]{},
476
			true);
477
478
	assumeEquals(
479
		"myClasses\n" + //$NON-NLS-1$
480
		"classes", //$NON-NLS-1$
481
		toString(suggestions));
482
}
483
/*
484
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
485
 */
486
public void testSuggestFieldName021() {
487
	String[] suggestions = NamingConventions.suggestVariableNames(
488
			NamingConventions.VK_CONSTANT_FIELD,
489
			NamingConventions.BK_TYPE_NAME,
490
			"MyType", //$NON-NLS-1$
491
			this.project,
492
			0,
493
			new String[]{},
494
			true);
495
496
	assumeEquals(
497
		"MY_TYPE\n" + //$NON-NLS-1$
498
		"TYPE", //$NON-NLS-1$
499
		toString(suggestions));
500
}
501
/*
502
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
503
 */
504
public void testSuggestFieldName022() {
505
	Hashtable options = JavaCore.getOptions();
506
	options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
507
	options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
508
	JavaCore.setOptions(options);
509
	
510
	String[] suggestions = NamingConventions.suggestVariableNames(
511
			NamingConventions.VK_CONSTANT_FIELD,
512
			NamingConventions.BK_TYPE_NAME,
513
			"MyType", //$NON-NLS-1$
514
			this.project,
515
			0,
516
			new String[]{},
517
			true);
518
519
	assumeEquals(
520
		"preMY_TYPEsuf\n" + //$NON-NLS-1$
521
		"preTYPEsuf\n" + //$NON-NLS-1$
522
		"preMY_TYPE\n" + //$NON-NLS-1$
523
		"preTYPE\n" + //$NON-NLS-1$
524
		"MY_TYPEsuf\n" + //$NON-NLS-1$
525
		"TYPEsuf\n" + //$NON-NLS-1$
526
		"MY_TYPE\n" + //$NON-NLS-1$
527
		"TYPE", //$NON-NLS-1$
528
		toString(suggestions));
529
}
530
/*
531
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
532
 */
533
public void testSuggestFieldName023() {
534
	String[] suggestions = NamingConventions.suggestVariableNames(
535
			NamingConventions.VK_INSTANCE_FIELD,
536
			NamingConventions.BK_NAME,
537
			"oneName", //$NON-NLS-1$
538
			this.project,
539
			0,
540
			new String[]{},
541
			true);
542
543
	assumeEquals(
544
		"oneName", //$NON-NLS-1$
545
		toString(suggestions));
546
}
547
/*
548
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
549
 */
550
public void testSuggestFieldName024() {
551
	Hashtable options = JavaCore.getOptions();
552
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
553
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
554
	JavaCore.setOptions(options);
555
	
556
	String[] suggestions = NamingConventions.suggestVariableNames(
557
			NamingConventions.VK_INSTANCE_FIELD,
558
			NamingConventions.BK_NAME,
559
			"oneName", //$NON-NLS-1$
560
			this.project,
561
			0,
562
			new String[]{},
563
			true);
564
565
	assumeEquals(
566
		"preOneNamesuf\n" + //$NON-NLS-1$
567
		"preOneName\n" + //$NON-NLS-1$
568
		"oneNamesuf\n" + //$NON-NLS-1$
569
		"oneName", //$NON-NLS-1$
570
		toString(suggestions));
571
}
572
/*
573
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
574
 */
575
public void testSuggestFieldName025() {
576
	String[] suggestions = NamingConventions.suggestVariableNames(
577
			NamingConventions.VK_CONSTANT_FIELD,
578
			NamingConventions.BK_TYPE_NAME,
579
			"My_Type", //$NON-NLS-1$
580
			this.project,
581
			0,
582
			new String[]{},
583
			true);
584
585
	assumeEquals(
586
		"MY_TYPE\n" + //$NON-NLS-1$
587
		"TYPE", //$NON-NLS-1$
588
		toString(suggestions));
589
}
590
/*
591
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
592
 */
593
public void testSuggestFieldName026() {
594
	String[] suggestions = NamingConventions.suggestVariableNames(
595
			NamingConventions.VK_CONSTANT_FIELD,
596
			NamingConventions.BK_TYPE_NAME,
597
			"_MyType", //$NON-NLS-1$
598
			this.project,
599
			0,
600
			new String[]{},
601
			true);
602
603
	assumeEquals(
604
		"MY_TYPE\n" + //$NON-NLS-1$
605
		"TYPE", //$NON-NLS-1$
606
		toString(suggestions));
607
}
608
/*
609
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
610
 */
611
public void testSuggestFieldName027() {
612
	String[] suggestions = NamingConventions.suggestVariableNames(
613
			NamingConventions.VK_CONSTANT_FIELD,
614
			NamingConventions.BK_TYPE_NAME,
615
			"MyType_", //$NON-NLS-1$
616
			this.project,
617
			0,
618
			new String[]{},
619
			true);
620
621
	assumeEquals(
622
		"MY_TYPE\n" + //$NON-NLS-1$
623
		"TYPE", //$NON-NLS-1$
624
		toString(suggestions));
625
}
626
/*
627
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
628
 */
629
public void testSuggestFieldName028() {
630
	String[] suggestions = NamingConventions.suggestVariableNames(
631
			NamingConventions.VK_CONSTANT_FIELD,
632
			NamingConventions.BK_TYPE_NAME,
633
			"MyTyp_e", //$NON-NLS-1$
634
			this.project,
635
			0,
636
			new String[]{},
637
			true);
638
639
	assumeEquals(
640
		"MY_TYP_E\n" + //$NON-NLS-1$
641
		"TYP_E\n" + //$NON-NLS-1$
642
		"E", //$NON-NLS-1$
643
		toString(suggestions));
644
}
645
/*
646
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
647
 */
648
public void testSuggestFieldName029() {
649
	String[] suggestions = NamingConventions.suggestVariableNames(
650
			NamingConventions.VK_INSTANCE_FIELD,
651
			NamingConventions.BK_TYPE_NAME,
652
			"My1Type", //$NON-NLS-1$
653
			this.project,
654
			0,
655
			new String[]{},
656
			true);
657
658
	assumeEquals(
659
		"my1Type\n" + //$NON-NLS-1$
660
		"type", //$NON-NLS-1$
661
		toString(suggestions));
662
}
663
/*
664
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
665
 */
666
public void testSuggestFieldName030() {
667
	String[] suggestions = NamingConventions.suggestVariableNames(
668
			NamingConventions.VK_INSTANCE_FIELD,
669
			NamingConventions.BK_TYPE_NAME,
670
			"M1yType", //$NON-NLS-1$
671
			this.project,
672
			0,
673
			new String[]{},
674
			true);
675
676
	assumeEquals(
677
		"m1yType\n" + //$NON-NLS-1$
678
		"type", //$NON-NLS-1$
679
		toString(suggestions));
680
}
681
/*
682
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
683
 */
684
public void testSuggestFieldName031() {
685
	String[] suggestions = NamingConventions.suggestVariableNames(
686
			NamingConventions.VK_INSTANCE_FIELD,
687
			NamingConventions.BK_TYPE_NAME,
688
			"MY1Type", //$NON-NLS-1$
689
			this.project,
690
			0,
691
			new String[]{},
692
			true);
693
694
	assumeEquals(
695
		"my1Type\n" + //$NON-NLS-1$
696
		"type", //$NON-NLS-1$
697
		toString(suggestions));
698
}
699
/*
700
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
701
 */
702
public void testSuggestFieldName032() {
703
	String[] suggestions = NamingConventions.suggestVariableNames(
704
			NamingConventions.VK_INSTANCE_FIELD,
705
			NamingConventions.BK_TYPE_NAME,
706
			"M1YType", //$NON-NLS-1$
707
			this.project,
708
			0,
709
			new String[]{},
710
			true);
711
712
	assumeEquals(
713
		"m1yType\n" + //$NON-NLS-1$
714
		"type", //$NON-NLS-1$
715
		toString(suggestions));
716
}
717
/*
718
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
719
 */
720
public void testSuggestFieldName033() {
721
	String[] suggestions = NamingConventions.suggestVariableNames(
722
			NamingConventions.VK_INSTANCE_FIELD,
723
			NamingConventions.BK_TYPE_NAME,
724
			"My_First_Type", //$NON-NLS-1$
725
			this.project,
726
			0,
727
			new String[]{},
728
			true);
729
730
	assumeEquals(
731
		"myFirstType\n" +  //$NON-NLS-1$
732
		"firstType\n" +  //$NON-NLS-1$
733
		"type", //$NON-NLS-1$
734
		toString(suggestions));
735
}
736
/*
737
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
738
 */
739
public void testSuggestFieldName034() {
740
	String[] suggestions = NamingConventions.suggestVariableNames(
741
			NamingConventions.VK_INSTANCE_FIELD,
742
			NamingConventions.BK_TYPE_NAME,
743
			"MY_FIRST_Type", //$NON-NLS-1$
744
			this.project,
745
			0,
746
			new String[]{},
747
			true);
748
749
	assumeEquals(
750
		"myFirstType\n" +  //$NON-NLS-1$
751
		"firstType\n" +  //$NON-NLS-1$
752
		"type", //$NON-NLS-1$
753
		toString(suggestions));
754
}
755
/*
756
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
757
 */
758
public void testSuggestFieldName035() {
759
	String[] suggestions = NamingConventions.suggestVariableNames(
760
			NamingConventions.VK_INSTANCE_FIELD,
761
			NamingConventions.BK_TYPE_NAME,
762
			"my_first_Type", //$NON-NLS-1$
763
			this.project,
764
			0,
765
			new String[]{},
766
			true);
767
768
	assumeEquals(
769
		"myFirstType\n" + //$NON-NLS-1$
770
		"firstType\n" + //$NON-NLS-1$
771
		"type", //$NON-NLS-1$
772
		toString(suggestions));
773
}
774
/*
775
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
776
 */
777
public void testSuggestFieldName036() {
778
	String[] suggestions = NamingConventions.suggestVariableNames(
779
			NamingConventions.VK_INSTANCE_FIELD,
780
			NamingConventions.BK_TYPE_NAME,
781
			"MyFirst_9_Type", //$NON-NLS-1$
782
			this.project,
783
			0,
784
			new String[]{},
785
			true);
786
787
	assumeEquals(
788
		"myFirst_9Type\n" + //$NON-NLS-1$
789
		"first_9Type\n" + //$NON-NLS-1$
790
		"type", //$NON-NLS-1$
791
		toString(suggestions));
792
}
793
/*
794
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
795
 */
796
public void testSuggestFieldName037() {
797
	String[] suggestions = NamingConventions.suggestVariableNames(
798
			NamingConventions.VK_INSTANCE_FIELD,
799
			NamingConventions.BK_TYPE_NAME,
800
			"AType", //$NON-NLS-1$
801
			this.project,
802
			0,
803
			new String[]{},
804
			true);
805
806
	assumeEquals(
807
		"aType\n" + //$NON-NLS-1$
808
		"type", //$NON-NLS-1$
809
		toString(suggestions));
810
}
811
/*
812
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
813
 */
814
public void testSuggestFieldName038() {
815
	String[] suggestions = NamingConventions.suggestVariableNames(
816
			NamingConventions.VK_INSTANCE_FIELD,
817
			NamingConventions.BK_TYPE_NAME,
818
			"aType", //$NON-NLS-1$
819
			this.project,
820
			0,
821
			new String[]{},
822
			true);
407
823
408
	assumeEquals(
824
	assumeEquals(
409
		"classes\n" + //$NON-NLS-1$
825
		"aType\n" + //$NON-NLS-1$
410
		"myClasses", //$NON-NLS-1$
826
		"type", //$NON-NLS-1$
411
		toString(suggestions));
827
		toString(suggestions));
412
}
828
}
829
/** @deprecated */
413
public void testRemovePrefixAndSuffixForFieldName001() {
830
public void testRemovePrefixAndSuffixForFieldName001() {
414
	Hashtable options = JavaCore.getOptions();
831
	Hashtable options = JavaCore.getOptions();
415
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
832
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
Lines 425-430 Link Here
425
		"oneName", //$NON-NLS-1$
842
		"oneName", //$NON-NLS-1$
426
		new String(name));
843
		new String(name));
427
}
844
}
845
/** @deprecated */
428
public void testRemovePrefixAndSuffixForFieldName002() {
846
public void testRemovePrefixAndSuffixForFieldName002() {
429
	Hashtable options = JavaCore.getOptions();
847
	Hashtable options = JavaCore.getOptions();
430
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pr, pre"); //$NON-NLS-1$
848
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pr, pre"); //$NON-NLS-1$
Lines 440-445 Link Here
440
		"preOneNamesuf", //$NON-NLS-1$
858
		"preOneNamesuf", //$NON-NLS-1$
441
		new String(name));
859
		new String(name));
442
}
860
}
861
/** @deprecated */
443
public void testRemovePrefixAndSuffixForFieldName003() {
862
public void testRemovePrefixAndSuffixForFieldName003() {
444
	Hashtable options = JavaCore.getOptions();
863
	Hashtable options = JavaCore.getOptions();
445
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pr, pre"); //$NON-NLS-1$
864
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pr, pre"); //$NON-NLS-1$
Lines 456-461 Link Here
456
		new String(name));
875
		new String(name));
457
}
876
}
458
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=114086
877
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=114086
878
/** @deprecated */
459
public void testRemovePrefixAndSuffixForFieldName004() {
879
public void testRemovePrefixAndSuffixForFieldName004() {
460
	Hashtable options = JavaCore.getOptions();
880
	Hashtable options = JavaCore.getOptions();
461
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre,"); //$NON-NLS-1$
881
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre,"); //$NON-NLS-1$
Lines 470-475 Link Here
470
		"oneName", //$NON-NLS-1$
890
		"oneName", //$NON-NLS-1$
471
		new String(name));
891
		new String(name));
472
}
892
}
893
/** @deprecated */
473
public void testRemovePrefixAndSuffixForLocalName001() {
894
public void testRemovePrefixAndSuffixForLocalName001() {
474
	Hashtable options = JavaCore.getOptions();
895
	Hashtable options = JavaCore.getOptions();
475
	options.put(JavaCore.CODEASSIST_LOCAL_PREFIXES,"pr, pre"); //$NON-NLS-1$
896
	options.put(JavaCore.CODEASSIST_LOCAL_PREFIXES,"pr, pre"); //$NON-NLS-1$
Lines 633-644 Link Here
633
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
1054
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
634
		this.project.setOptions(newOptions);
1055
		this.project.setOptions(newOptions);
635
1056
636
		String[] suggestions = NamingConventions.suggestLocalVariableNames(
1057
		String[] suggestions = NamingConventions.suggestVariableNames(
1058
			NamingConventions.VK_LOCAL,
1059
			NamingConventions.BK_TYPE_NAME,
1060
			"Enum",
637
			this.project,
1061
			this.project,
638
			"",//$NON-NLS-1$
639
			"Enum",//$NON-NLS-1$
640
			0,
1062
			0,
641
			new String[]{"o"});
1063
			new String[]{"o"}, //$NON-NLS-1$
1064
			true);
642
1065
643
		assumeEquals(
1066
		assumeEquals(
644
			"enum1", //$NON-NLS-1$
1067
			"enum1", //$NON-NLS-1$
Lines 659-670 Link Here
659
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
1082
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
660
		this.project.setOptions(newOptions);
1083
		this.project.setOptions(newOptions);
661
1084
662
		String[] suggestions = NamingConventions.suggestLocalVariableNames(
1085
		String[] suggestions = NamingConventions.suggestVariableNames(
1086
			NamingConventions.VK_LOCAL,
1087
			NamingConventions.BK_TYPE_NAME,
1088
			"Enums",
663
			this.project,
1089
			this.project,
664
			"",//$NON-NLS-1$
665
			"Enums",//$NON-NLS-1$
666
			0,
1090
			0,
667
			new String[]{"o"});
1091
			new String[]{"o"}, //$NON-NLS-1$
1092
			true);
668
1093
669
		assumeEquals(
1094
		assumeEquals(
670
			"enums", //$NON-NLS-1$
1095
			"enums", //$NON-NLS-1$
(-)model/org/eclipse/jdt/internal/core/InternalNamingConventions.java (+589 lines)
Lines 14-19 Link Here
14
14
15
import org.eclipse.jdt.core.Flags;
15
import org.eclipse.jdt.core.Flags;
16
import org.eclipse.jdt.core.IJavaProject;
16
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.core.JavaCore;
17
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.InvalidInputException;
19
import org.eclipse.jdt.core.compiler.InvalidInputException;
19
import org.eclipse.jdt.internal.codeassist.impl.AssistOptions;
20
import org.eclipse.jdt.internal.codeassist.impl.AssistOptions;
Lines 53-58 Link Here
53
			getNameScanner(compilerOptions),
54
			getNameScanner(compilerOptions),
54
			requestor);
55
			requestor);
55
	}
56
	}
57
	
56
	public static void suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) {
58
	public static void suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) {
57
		boolean isStatic = Flags.isStatic(modifiers);
59
		boolean isStatic = Flags.isStatic(modifiers);
58
60
Lines 258-263 Link Here
258
			requestor.acceptNameWithoutPrefixAndSuffix(name, 0);
260
			requestor.acceptNameWithoutPrefixAndSuffix(name, 0);
259
		}
261
		}
260
	}
262
	}
263
	
261
264
262
	private static void acceptName(
265
	private static void acceptName(
263
		char[] name,
266
		char[] name,
Lines 278-283 Link Here
278
		}
281
		}
279
	}
282
	}
280
283
284
	private static char[][] computeBaseTypeNames(char[] typeName, boolean isConstantField, char[][] excludedNames){
285
		char[] name = computeBaseTypeNames(typeName[0], excludedNames);
286
		if(name != null) {
287
			return new char[][]{name};
288
		} else {
289
			// compute variable name like from non base type
290
			return  computeNonBaseTypeNames(typeName, isConstantField);
291
		}
292
	}
281
	private static char[] computeBaseTypeNames(char firstName, char[][] excludedNames){
293
	private static char[] computeBaseTypeNames(char firstName, char[][] excludedNames){
282
		char[] name = new char[]{firstName};
294
		char[] name = new char[]{firstName};
283
295
Lines 322-327 Link Here
322
		System.arraycopy(names, 0, names = new char[nameCount][], 0, nameCount);
334
		System.arraycopy(names, 0, names = new char[nameCount][], 0, nameCount);
323
		return names;
335
		return names;
324
	}
336
	}
337
	
338
	
339
	private static char[][] computeNonBaseTypeNames(char[] sourceName, boolean isConstantField){
340
		int length = sourceName.length;
341
		
342
		if (length == 0) {
343
			return CharOperation.NO_CHAR_CHAR;
344
		}
345
		
346
		if (length == 1) {
347
			return new char[][]{CharOperation.toLowerCase(sourceName)};
348
		}
349
		
350
		char[][] nameParts = new char[length][];
351
		int namePartsPtr = -1;
352
		
353
		int endIndex = length;
354
		char c = sourceName[length - 1];
355
		
356
		final int IS_LOWER_CASE = 1;
357
		final int IS_UPPER_CASE = 2;
358
		final int IS_UNDERSCORE = 3;
359
		final int IS_OTHER = 4;
360
		
361
		int previousCharKind =
362
			ScannerHelper.isLowerCase(c) ? IS_LOWER_CASE :
363
				ScannerHelper.isUpperCase(c) ? IS_UPPER_CASE :
364
					c == '_' ? IS_UNDERSCORE : IS_OTHER;
365
		
366
		for(int i = length - 1 ; i >= 0 ; i--){
367
			c = sourceName[i];
368
			
369
			int charKind =
370
				ScannerHelper.isLowerCase(c) ? IS_LOWER_CASE :
371
					ScannerHelper.isUpperCase(c) ? IS_UPPER_CASE :
372
						c == '_' ? IS_UNDERSCORE : IS_OTHER;
373
			
374
			switch (charKind) {
375
				case IS_LOWER_CASE:
376
					if (previousCharKind == IS_UPPER_CASE) {
377
						nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, i + 1, endIndex);
378
						endIndex = i + 1;
379
					}
380
					previousCharKind = IS_LOWER_CASE;
381
					break;
382
				case IS_UPPER_CASE:
383
					if (previousCharKind == IS_LOWER_CASE) {
384
						nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, i, endIndex);
385
						if (i > 0) {
386
							char pc = sourceName[i - 1];
387
							previousCharKind =
388
								ScannerHelper.isLowerCase(pc) ? IS_LOWER_CASE :
389
									ScannerHelper.isUpperCase(pc) ? IS_UPPER_CASE :
390
										pc == '_' ? IS_UNDERSCORE : IS_OTHER;
391
						}
392
						endIndex = i;
393
					} else {
394
						previousCharKind = IS_UPPER_CASE;
395
					}
396
					break;
397
				case IS_UNDERSCORE:
398
					switch (previousCharKind) {
399
						case IS_UNDERSCORE:
400
							if (i > 0) {
401
								char pc = sourceName[i - 1];
402
								previousCharKind =
403
									ScannerHelper.isLowerCase(pc) ? IS_LOWER_CASE :
404
										ScannerHelper.isUpperCase(pc) ? IS_UPPER_CASE :
405
											pc == '_' ? IS_UNDERSCORE : IS_OTHER;
406
							}
407
							endIndex = i;
408
							break;
409
						case IS_LOWER_CASE:
410
						case IS_UPPER_CASE:
411
							nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, i + 1, endIndex);
412
							if (i > 0) {
413
								char pc = sourceName[i - 1];
414
								previousCharKind =
415
									ScannerHelper.isLowerCase(pc) ? IS_LOWER_CASE :
416
										ScannerHelper.isUpperCase(pc) ? IS_UPPER_CASE :
417
											pc == '_' ? IS_UNDERSCORE : IS_OTHER;
418
							}
419
							endIndex = i;
420
							break;
421
						default:
422
							previousCharKind = IS_UNDERSCORE;
423
							break;
424
					}
425
					break;
426
				default:
427
					previousCharKind = IS_OTHER;
428
					break;
429
			}
430
		}
431
		if (endIndex > 0) {
432
			nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, 0, endIndex);
433
		}
434
		
435
		if (isConstantField) {
436
			return generateConstantName(nameParts, namePartsPtr);
437
		} else {
438
			return generateNonConstantName(nameParts, namePartsPtr);
439
		}
440
	}
441
	
442
	
325
443
326
	private static char[] excludeNames(
444
	private static char[] excludeNames(
327
		char[] suffixName,
445
		char[] suffixName,
Lines 344-349 Link Here
344
		}
462
		}
345
		return suffixName;
463
		return suffixName;
346
	}
464
	}
465
	
466
	private static char[][] generateNonConstantName(char[][] nameParts, int namePartsPtr) {
467
		char[][] names = new char[namePartsPtr + 1][];
468
		
469
		char[] namePart = CharOperation.toLowerCase(nameParts[0]);
470
		int namePartLength = namePart.length;
471
		System.arraycopy(namePart, 0, namePart, 0, namePartLength);
472
		
473
		char[] name = namePart;
474
		
475
		names[namePartsPtr] = name;
476
		
477
		for (int i = 1; i <= namePartsPtr; i++) {
478
			namePart = CharOperation.toLowerCase(nameParts[i]);
479
			namePartLength = namePart.length;
480
			name = CharOperation.concat(namePart, name);
481
			name[namePartLength] = ScannerHelper.toUpperCase(name[namePartLength]);
482
			
483
			names[namePartsPtr - i] = name;
484
		}
485
		return names;
486
	}
487
488
	private static char[][] generateConstantName(char[][] nameParts, int namePartsPtr) {
489
		char[][] names = new char[namePartsPtr + 1][];
490
		
491
		char[] namePart = CharOperation.toUpperCase(nameParts[0]);
492
		int namePartLength = namePart.length;
493
		System.arraycopy(namePart, 0, namePart, 0, namePartLength);
494
		
495
		char[] name = namePart;
496
		
497
		names[namePartsPtr] = name;
498
		
499
		for (int i = 1; i <= namePartsPtr; i++) {
500
			namePart = CharOperation.toUpperCase(nameParts[i]);
501
			namePartLength = namePart.length;
502
			if (namePart[namePartLength - 1] != '_') {
503
				name = CharOperation.concat(namePart, name, '_');
504
			} else {
505
				name = CharOperation.concat(namePart, name);
506
			}
507
			
508
			names[namePartsPtr - i] = name;
509
		}
510
		return names;
511
	}
512
	
513
	public static char[] getBaseName(
514
			int variableKind,
515
			IJavaProject javaProject,
516
			char[] name) {
517
		
518
		AssistOptions assistOptions;
519
		if (javaProject != null) {
520
			assistOptions = new AssistOptions(javaProject.getOptions(true));
521
		} else {
522
			assistOptions = new AssistOptions(JavaCore.getOptions());
523
		}
524
		
525
		char[][] prefixes = null;
526
		char[][] suffixes = null;
527
		switch (variableKind) {
528
			case VK_INSTANCE_FIELD:
529
				prefixes = assistOptions.fieldPrefixes;
530
				suffixes = assistOptions.fieldSuffixes;
531
				break;
532
			case VK_STATIC_FIELD:
533
				prefixes = assistOptions.staticFieldPrefixes;
534
				suffixes = assistOptions.staticFieldSuffixes;
535
				break;
536
			case VK_CONSTANT_FIELD:
537
				prefixes = assistOptions.staticFinalFieldPrefixes;
538
				suffixes = assistOptions.staticFinalFieldSuffixes;
539
				break;
540
			case VK_LOCAL:
541
				prefixes = assistOptions.localPrefixes;
542
				suffixes = assistOptions.localSuffixes;
543
				break;
544
			case VK_PARAMETER:
545
				prefixes = assistOptions.argumentPrefixes;
546
				suffixes = assistOptions.argumentSuffixes;
547
				break;
548
		}
549
		
550
		
551
		return getBaseName(name, prefixes, suffixes, variableKind == VK_CONSTANT_FIELD);
552
	}
553
554
	private static char[] getBaseName(char[] name, char[][] prefixes, char[][] suffixes, boolean isConstant) {
555
		char[] nameWithoutPrefixAndSiffix = removeVariablePrefixAndSuffix(name, prefixes, suffixes, false);
556
		
557
		char[] baseName;
558
		if (isConstant) {
559
			int length = nameWithoutPrefixAndSiffix.length;
560
			baseName = new char[length];
561
			int baseNamePtr = -1;
562
			
563
			boolean previousIsUnderscore = false;
564
			for (int i = 0; i < length; i++) {
565
				char c = nameWithoutPrefixAndSiffix[i];
566
				if (c != '_') {
567
					if (previousIsUnderscore || i == 0) {
568
						baseName[++baseNamePtr] = ScannerHelper.toUpperCase(c);
569
						previousIsUnderscore = false;
570
					} else {
571
						baseName[++baseNamePtr] = ScannerHelper.toLowerCase(c);
572
					}
573
				} else {
574
					previousIsUnderscore = true;
575
				}
576
			}
577
			System.arraycopy(baseName, 0, baseName = new char[baseNamePtr + 1], 0, baseNamePtr + 1);
578
		} else {
579
			baseName = nameWithoutPrefixAndSiffix;
580
		}
581
		
582
		return baseName;
583
	}
584
	
585
	public static char[] removeVariablePrefixAndSuffix(
586
			int variableKind,
587
			IJavaProject javaProject,
588
			char[] name) {
589
		AssistOptions assistOptions;
590
		if (javaProject != null) {
591
			assistOptions = new AssistOptions(javaProject.getOptions(true));
592
		} else {
593
			assistOptions = new AssistOptions(JavaCore.getOptions());
594
		}
595
		
596
		char[][] prefixes = null;
597
		char[][] suffixes = null;
598
		switch (variableKind) {
599
			case VK_INSTANCE_FIELD:
600
				prefixes = assistOptions.fieldPrefixes;
601
				suffixes = assistOptions.fieldSuffixes;
602
				break;
603
			case VK_STATIC_FIELD:
604
				prefixes = assistOptions.staticFieldPrefixes;
605
				suffixes = assistOptions.staticFieldSuffixes;
606
				break;
607
			case VK_CONSTANT_FIELD:
608
				prefixes = assistOptions.staticFinalFieldPrefixes;
609
				suffixes = assistOptions.staticFinalFieldSuffixes;
610
				break;
611
			case VK_LOCAL:
612
				prefixes = assistOptions.localPrefixes;
613
				suffixes = assistOptions.localSuffixes;
614
				break;
615
			case VK_PARAMETER:
616
				prefixes = assistOptions.argumentPrefixes;
617
				suffixes = assistOptions.argumentSuffixes;
618
				break;
619
		}
620
		
621
		return InternalNamingConventions.removeVariablePrefixAndSuffix(name,	prefixes, suffixes, true);
622
	}
623
	
624
	private static char[] removeVariablePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes, boolean updateFirstCharacter) {
625
		// remove longer prefix
626
		char[] withoutPrefixName = name;
627
		if (prefixes != null) {
628
			int bestLength = 0;
629
			for (int i= 0; i < prefixes.length; i++) {
630
				char[] prefix = prefixes[i];
631
				if (CharOperation.prefixEquals(prefix, name)) {
632
					int currLen = prefix.length;
633
					boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]);
634
					if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) {
635
						if (bestLength < currLen && name.length != currLen) {
636
							withoutPrefixName = CharOperation.subarray(name, currLen, name.length);
637
							bestLength = currLen;
638
						}
639
					}
640
				}
641
			}
642
		}
643
644
		// remove longer suffix
645
		char[] withoutSuffixName = withoutPrefixName;
646
		if(suffixes != null) {
647
			int bestLength = 0;
648
			for (int i = 0; i < suffixes.length; i++) {
649
				char[] suffix = suffixes[i];
650
				if(CharOperation.endsWith(withoutPrefixName, suffix)) {
651
					int currLen = suffix.length;
652
					if(bestLength < currLen && withoutPrefixName.length != currLen) {
653
						withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen);
654
						bestLength = currLen;
655
					}
656
				}
657
			}
658
		}
659
660
		if (updateFirstCharacter) withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]);
661
		return withoutSuffixName;
662
	}
347
663
348
	private static char[] removePrefix(char[] name, char[][] prefixes) {
664
	private static char[] removePrefix(char[] name, char[][] prefixes) {
349
		// remove longer prefix
665
		// remove longer prefix
Lines 430-433 Link Here
430
					return false;
746
					return false;
431
			return true;
747
			return true;
432
	}
748
	}
749
	
750
	public static final int VK_STATIC_FIELD = 1;
751
	public static final int VK_INSTANCE_FIELD = 2;
752
	public static final int VK_CONSTANT_FIELD = 3;
753
	public static final int VK_PARAMETER = 4;
754
	public static final int VK_LOCAL = 5;
755
	
756
	public static final int BK_SIMPLE_NAME = 1;
757
	public static final int BK_SIMPLE_TYPE_NAME = 2;
758
759
	public static void suggestVariableNames(
760
			int variableKind,
761
			int baseNameKind,
762
			char[] baseName,
763
			IJavaProject javaProject,
764
			int dim,
765
			char[] internalPrefix,
766
			char[][] excluded,
767
			boolean evaluateDefault,
768
			INamingRequestor requestor) {
769
		
770
		if(baseName == null || baseName.length == 0)
771
			return;
772
		
773
		Map options;
774
		if (javaProject != null) {
775
			options = javaProject.getOptions(true);
776
		} else {
777
			options = JavaCore.getOptions();
778
		}
779
		CompilerOptions compilerOptions = new CompilerOptions(options);
780
		AssistOptions assistOptions = new AssistOptions(options);
781
		
782
		boolean isConstantField = false;
783
		
784
		char[][] prefixes = null;
785
		char[][] suffixes = null;
786
		switch (variableKind) {
787
			case VK_INSTANCE_FIELD:
788
				prefixes = assistOptions.fieldPrefixes;
789
				suffixes = assistOptions.fieldSuffixes;
790
				break;
791
			case VK_STATIC_FIELD:
792
				prefixes = assistOptions.staticFieldPrefixes;
793
				suffixes = assistOptions.staticFieldSuffixes;
794
				break;
795
			case VK_CONSTANT_FIELD:
796
				isConstantField = true;
797
				prefixes = assistOptions.staticFinalFieldPrefixes;
798
				suffixes = assistOptions.staticFinalFieldSuffixes;
799
				break;
800
			case VK_LOCAL:
801
				prefixes = assistOptions.localPrefixes;
802
				suffixes = assistOptions.localSuffixes;
803
				break;
804
			case VK_PARAMETER:
805
				prefixes = assistOptions.argumentPrefixes;
806
				suffixes = assistOptions.argumentSuffixes;
807
				break;
808
		}
809
		
810
		if(prefixes == null || prefixes.length == 0) {
811
			prefixes = new char[1][0];
812
		} else {
813
			int length = prefixes.length;
814
			System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length);
815
			prefixes[length] = CharOperation.NO_CHAR;
816
		}
817
818
		if(suffixes == null || suffixes.length == 0) {
819
			suffixes = new char[1][0];
820
		} else {
821
			int length = suffixes.length;
822
			System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length);
823
			suffixes[length] = CharOperation.NO_CHAR;
824
		}
825
		
826
		if(internalPrefix == null) {
827
			internalPrefix = CharOperation.NO_CHAR;
828
		} else {
829
			internalPrefix = removePrefix(internalPrefix, prefixes);
830
		}
831
832
		char[][] tempNames = null;
833
		
834
		Scanner nameScanner = getNameScanner(compilerOptions);
835
		if (baseNameKind == BK_SIMPLE_TYPE_NAME) {
836
			boolean isBaseType = false;
837
			
838
			try{
839
				nameScanner.setSource(baseName);
840
				switch (nameScanner.getNextToken()) {
841
					case TerminalTokens.TokenNameint :
842
					case TerminalTokens.TokenNamebyte :
843
					case TerminalTokens.TokenNameshort :
844
					case TerminalTokens.TokenNamechar :
845
					case TerminalTokens.TokenNamelong :
846
					case TerminalTokens.TokenNamefloat :
847
					case TerminalTokens.TokenNamedouble :
848
					case TerminalTokens.TokenNameboolean :
849
						isBaseType = true;
850
						break;
851
				}
852
			} catch(InvalidInputException e){
853
				// ignore
854
			}
855
			if (isBaseType) {
856
				// compute variable name from base type
857
				if (internalPrefix.length > 0) return;
858
	
859
				tempNames = computeBaseTypeNames(baseName, isConstantField, excluded);
860
			} else {
861
				// compute variable name for non base type
862
				tempNames = computeNonBaseTypeNames(baseName, isConstantField);
863
			}
864
		} else {
865
			tempNames = new char[][]{baseName};
866
		}
867
868
		boolean acceptDefaultName = true;
869
		SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray();
870
871
		for (int i = 0; i < tempNames.length; i++) {
872
			char[] tempName = tempNames[i];
873
			
874
			// add English plural form is necessary
875
			if(dim > 0) {
876
				int length = tempName.length;
877
				
878
				if (isConstantField) {
879
					if (tempName[length-1] == 'S'){
880
						if(tempName.length > 1 && tempName[length-2] == 'S') {
881
							System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
882
							tempName[length] = 'E';
883
							tempName[length+1] = 'S';
884
						}
885
					} else if(tempName[length-1] == 'Y') {
886
						System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
887
						tempName[length-1] = 'I';
888
						tempName[length] = 'E';
889
						tempName[length+1] = 'S';
890
					} else {
891
						System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
892
						tempName[length] = 'S';
893
					}
894
				} else {
895
					if (tempName[length-1] == 's'){
896
						if(tempName.length > 1 && tempName[length-2] == 's') {
897
							System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
898
							tempName[length] = 'e';
899
							tempName[length+1] = 's';
900
						}
901
					} else if(tempName[length-1] == 'y') {
902
						System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
903
						tempName[length-1] = 'i';
904
						tempName[length] = 'e';
905
						tempName[length+1] = 's';
906
					} else {
907
						System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
908
						tempName[length] = 's';
909
					}
910
				}
911
			}
912
			
913
			char[] unprefixedName = tempName;
914
			
915
			int matchingIndex = -1;
916
			if (!isConstantField) {
917
				unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]);
918
				
919
				done : for (int j = 0; j <= internalPrefix.length; j++) {
920
					if(j == internalPrefix.length ||
921
							CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
922
						matchingIndex = j;
923
						break done;
924
					}
925
				}
926
			} else {
927
				done : for (int j = 0; j <= internalPrefix.length; j++) {
928
					if(j == internalPrefix.length) {
929
						matchingIndex = j;
930
						break done;
931
					} else if(CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
932
						if (j == 0 || internalPrefix[j - 1] == '_') {
933
							matchingIndex = j;
934
							break done;
935
						}
936
						
937
					}
938
				}
939
			}
940
941
			if(matchingIndex > -1) {
942
				if (!isConstantField) {
943
					tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, matchingIndex), unprefixedName);
944
					if(matchingIndex == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
945
				} else {
946
					if(matchingIndex != 0 && tempName[0] != '_' && internalPrefix[matchingIndex - 1] != '_') {
947
						tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName, '_');
948
					} else {
949
						tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName);
950
					}
951
				}
952
				
953
				for (int k = 0; k < prefixes.length; k++) {
954
					if (!isConstantField) {
955
						if(prefixes[k].length > 0
956
							&& ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) {
957
							tempName[0] = ScannerHelper.toUpperCase(tempName[0]);
958
						} else {
959
							tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
960
						}
961
					}
962
					char[] prefixName = CharOperation.concat(prefixes[k], tempName);
963
					for (int l = 0; l < suffixes.length; l++) {
964
						char[] suffixName = CharOperation.concat(prefixName, suffixes[l]);
965
						suffixName =
966
							excludeNames(
967
								suffixName,
968
								prefixName,
969
								suffixes[l],
970
								excluded);
971
						try{
972
							nameScanner.setSource(suffixName);
973
							switch (nameScanner.getNextToken()) {
974
								case TerminalTokens.TokenNameIdentifier :
975
									int token = nameScanner.getNextToken();
976
									if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
977
										if (!foundNames.includes(suffixName)) {
978
											acceptName(suffixName, prefixes[k], suffixes[l],  k == 0, l == 0, internalPrefix.length - matchingIndex, requestor);
979
											foundNames.add(suffixName);
980
											acceptDefaultName = false;
981
										}
982
									}
983
									break;
984
								default:
985
									suffixName = CharOperation.concat(
986
										prefixName,
987
										String.valueOf(1).toCharArray(),
988
										suffixes[l]
989
									);
990
									suffixName =
991
										excludeNames(
992
											suffixName,
993
											prefixName,
994
											suffixes[l],
995
											excluded);
996
									nameScanner.setSource(suffixName);
997
									switch (nameScanner.getNextToken()) {
998
										case TerminalTokens.TokenNameIdentifier :
999
											token = nameScanner.getNextToken();
1000
											if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
1001
												if (!foundNames.includes(suffixName)) {
1002
													acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor);
1003
													foundNames.add(suffixName);
1004
													acceptDefaultName = false;
1005
												}
1006
											}
1007
									}
1008
							}
1009
						} catch(InvalidInputException e){
1010
							// ignore
1011
						}
1012
					}
1013
				}
1014
			}
1015
		}
1016
		// if no names were found
1017
		if(evaluateDefault && acceptDefaultName) {
1018
			char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excluded);
1019
			requestor.acceptNameWithoutPrefixAndSuffix(name, 0);
1020
		}
1021
	}
433
}
1022
}
(-)model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java (+2 lines)
Lines 77-86 Link Here
77
		defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
77
		defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
78
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
78
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
79
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
79
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
80
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$
80
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
81
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
81
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
82
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
82
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
83
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
83
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
84
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
85
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$
84
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
86
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
85
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
87
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
86
		defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
88
		defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (+2 lines)
Lines 1965-1974 Link Here
1965
		defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
1965
		defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
1966
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
1966
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
1967
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
1967
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
1968
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$
1968
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
1969
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
1969
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
1970
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
1970
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1971
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1971
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1972
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1973
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1972
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
1974
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
1973
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
1975
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
1974
		defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
1976
		defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
(-)model/org/eclipse/jdt/core/JavaCore.java (+26 lines)
Lines 1812-1817 Link Here
1812
	 */
1812
	 */
1813
	public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
1813
	public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
1814
	/**
1814
	/**
1815
	 * Code assist option ID: Define the Prefixes for Static Final Field Name.
1816
	 * <p>When the prefixes is non empty, completion for static final field name will begin with
1817
	 *    one of the proposed prefixes.
1818
	 * <dl>
1819
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"</code></dd>
1820
	 * <dt>Possible values:</dt><dd><code>{ "&lt;prefix&gt;[,&lt;prefix&gt;]*" }</code> where <code>&lt;prefix&gt;</code> is a String without any wild-card</dd>
1821
	 * <dt>Default:</dt><dd><code>""</code></dd>
1822
	 * </dl>
1823
	 * @since 3.5
1824
	 * @category CodeAssistOptionID
1825
	 */
1826
	public static final String CODEASSIST_STATIC_FINAL_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldPrefixes"; //$NON-NLS-1$
1827
	/**
1815
	 * Code assist option ID: Define the Prefixes for Local Variable Name.
1828
	 * Code assist option ID: Define the Prefixes for Local Variable Name.
1816
	 * <p>When the prefixes is non empty, completion for local variable name will begin with
1829
	 * <p>When the prefixes is non empty, completion for local variable name will begin with
1817
	 *    one of the proposed prefixes.
1830
	 *    one of the proposed prefixes.
Lines 1864-1869 Link Here
1864
	 */
1877
	 */
1865
	public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
1878
	public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
1866
	/**
1879
	/**
1880
	 * Code assist option ID: Define the Suffixes for Static Final Field Name.
1881
	 * <p>When the suffixes is non empty, completion for static final field name will end with
1882
	 *    one of the proposed suffixes.
1883
	 * <dl>
1884
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"</code></dd>
1885
	 * <dt>Possible values:</dt><dd><code>{ "&lt;suffix&gt;[,&lt;suffix&gt;]*" }</code>< where <code>&lt;suffix&gt;</code> is a String without any wild-card</dd>
1886
	 * <dt>Default:</dt><dd><code>""</code></dd>
1887
	 * </dl>
1888
	 * @since 3.5
1889
	 * @category CodeAssistOptionID
1890
	 */
1891
	public static final String CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldSuffixes"; //$NON-NLS-1$
1892
	/**
1867
	 * Code assist option ID: Define the Suffixes for Local Variable Name.
1893
	 * Code assist option ID: Define the Suffixes for Local Variable Name.
1868
	 * <p>When the suffixes is non empty, completion for local variable name will end with
1894
	 * <p>When the suffixes is non empty, completion for local variable name will end with
1869
	 *    one of the proposed suffixes.
1895
	 *    one of the proposed suffixes.
(-)model/org/eclipse/jdt/core/NamingConventions.java (-175 / +372 lines)
Lines 48-57 Link Here
48
 * @noinstantiate This class is not intended to be instantiated by clients.
48
 * @noinstantiate This class is not intended to be instantiated by clients.
49
 */
49
 */
50
public final class NamingConventions {
50
public final class NamingConventions {
51
	private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$
52
	private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$
53
	private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$
54
55
	static class NamingRequestor implements INamingRequestor {
51
	static class NamingRequestor implements INamingRequestor {
56
		private final static int SIZE = 10;
52
		private final static int SIZE = 10;
57
53
Lines 80-85 Link Here
80
		// for acceptNameWithoutPrefixAndSuffix
76
		// for acceptNameWithoutPrefixAndSuffix
81
		private char[][] otherResults = new char[SIZE][];
77
		private char[][] otherResults = new char[SIZE][];
82
		private int otherResultsCount = 0;
78
		private int otherResultsCount = 0;
79
		public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) {
80
			int length = this.otherResults.length;
81
			if(length == this.otherResultsCount) {
82
				System.arraycopy(
83
					this.otherResults,
84
					0,
85
					this.otherResults = new char[length * 2][],
86
					0,
87
					length);
88
			}
89
			this.otherResults[this.otherResultsCount++] = name;
90
		}
91
92
		public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) {
93
			if(isFirstPrefix) {
94
				int length = this.firstPrefixResults.length;
95
				if(length == this.firstPrefixResultsCount) {
96
					System.arraycopy(
97
						this.firstPrefixResults,
98
						0,
99
						this.firstPrefixResults = new char[length * 2][],
100
						0,
101
						length);
102
				}
103
				this.firstPrefixResults[this.firstPrefixResultsCount++] = name;
104
			} else{
105
				int length = this.prefixResults.length;
106
				if(length == this.prefixResultsCount) {
107
					System.arraycopy(
108
						this.prefixResults,
109
						0,
110
						this.prefixResults = new char[length * 2][],
111
						0,
112
						length);
113
				}
114
				this.prefixResults[this.prefixResultsCount++] = name;
115
			}
116
		}
117
83
		public void acceptNameWithPrefixAndSuffix(char[] name, boolean isFirstPrefix, boolean isFirstSuffix, int reusedCharacters) {
118
		public void acceptNameWithPrefixAndSuffix(char[] name, boolean isFirstPrefix, boolean isFirstSuffix, int reusedCharacters) {
84
			if(isFirstPrefix && isFirstSuffix) {
119
			if(isFirstPrefix && isFirstSuffix) {
85
				int length = this.firstPrefixAndFirstSuffixResults.length;
120
				int length = this.firstPrefixAndFirstSuffixResults.length;
Lines 128-159 Link Here
128
			}
163
			}
129
		}
164
		}
130
165
131
		public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) {
132
			if(isFirstPrefix) {
133
				int length = this.firstPrefixResults.length;
134
				if(length == this.firstPrefixResultsCount) {
135
					System.arraycopy(
136
						this.firstPrefixResults,
137
						0,
138
						this.firstPrefixResults = new char[length * 2][],
139
						0,
140
						length);
141
				}
142
				this.firstPrefixResults[this.firstPrefixResultsCount++] = name;
143
			} else{
144
				int length = this.prefixResults.length;
145
				if(length == this.prefixResultsCount) {
146
					System.arraycopy(
147
						this.prefixResults,
148
						0,
149
						this.prefixResults = new char[length * 2][],
150
						0,
151
						length);
152
				}
153
				this.prefixResults[this.prefixResultsCount++] = name;
154
			}
155
		}
156
157
		public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix, int reusedCharacters) {
166
		public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix, int reusedCharacters) {
158
			if(isFirstSuffix) {
167
			if(isFirstSuffix) {
159
				int length = this.firstSuffixResults.length;
168
				int length = this.firstSuffixResults.length;
Lines 179-197 Link Here
179
				this.suffixResults[this.suffixResultsCount++] = name;
188
				this.suffixResults[this.suffixResultsCount++] = name;
180
			}
189
			}
181
		}
190
		}
182
183
		public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) {
184
			int length = this.otherResults.length;
185
			if(length == this.otherResultsCount) {
186
				System.arraycopy(
187
					this.otherResults,
188
					0,
189
					this.otherResults = new char[length * 2][],
190
					0,
191
					length);
192
			}
193
			this.otherResults[this.otherResultsCount++] = name;
194
		}
195
		public char[][] getResults(){
191
		public char[][] getResults(){
196
			int count =
192
			int count =
197
				this.firstPrefixAndFirstSuffixResultsCount
193
				this.firstPrefixAndFirstSuffixResultsCount
Lines 228-237 Link Here
228
			return results;
224
			return results;
229
		}
225
		}
230
	}
226
	}
227
	private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$
228
	private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$
231
229
230
	private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$
232
231
233
	private NamingConventions() {
232
234
		// Not instantiable
233
	/**
234
	 * Variable kind which represents a static field.
235
	 * 
236
	 * @since 3.5
237
	 */
238
	public static final int VK_STATIC_FIELD = InternalNamingConventions.VK_STATIC_FIELD;
239
	/**
240
	 * Variable kind which represents an instance field.
241
	 * 
242
	 * @since 3.5
243
	 */
244
	public static final int VK_INSTANCE_FIELD = InternalNamingConventions.VK_INSTANCE_FIELD;
245
	/**
246
	 * Variable kind which represents a constant field (static final).
247
	 * 
248
	 * @since 3.5
249
	 */
250
	public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_CONSTANT_FIELD;
251
	/**
252
	 * Variable kind which represents an argument.
253
	 * 
254
	 * @since 3.5
255
	 */
256
	public static final int VK_PARAMETER = InternalNamingConventions.VK_PARAMETER;
257
	/**
258
	 * Variable kind which represents a local variable.
259
	 * 
260
	 * @since 3.5
261
	 */
262
	public static final int VK_LOCAL = InternalNamingConventions.VK_LOCAL;
263
	
264
	/**
265
	 * The base name associated to this base name kind is a simple name.
266
	 * When this base name is used the whole name is considered.
267
	 * 
268
	 * @see #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)
269
	 * 
270
	 * @since 3.5
271
	 */
272
	public static final int BK_NAME = InternalNamingConventions.BK_SIMPLE_NAME;
273
	
274
	/**
275
	 * The base name associated to this base name kind is a simple type name.
276
	 * When this base name is used to all the words of the name are considered.
277
	 * 
278
	 * @see #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)
279
	 * 
280
	 * @since 3.5
281
	 */
282
	public static final int BK_TYPE_NAME = InternalNamingConventions.BK_SIMPLE_TYPE_NAME;
283
284
	private static String[] convertCharsToString(char[][] c) {
285
		int length = c == null ? 0 : c.length;
286
		String[] s = new String[length];
287
		for (int i = 0; i < length; i++) {
288
			s[i] = String.valueOf(c[i]);
289
		}
290
		return s;
291
	}
292
	private static char[][] convertStringToChars(String[] s) {
293
		int length = s == null ? 0 : s.length;
294
		char[][] c = new char[length][];
295
		for (int i = 0; i < length; i++) {
296
			if(s[i] == null) {
297
				c[i] = CharOperation.NO_CHAR;
298
			} else {
299
				c[i] = s[i].toCharArray();
300
			}
301
		}
302
		return c;
235
	}
303
	}
236
304
237
	private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) {
305
	private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) {
Lines 296-301 Link Here
296
	 * @return char[] the name without prefix and suffix.
364
	 * @return char[] the name without prefix and suffix.
297
	 * @see JavaCore#setOptions(java.util.Hashtable)
365
	 * @see JavaCore#setOptions(java.util.Hashtable)
298
	 * @see JavaCore#getDefaultOptions()
366
	 * @see JavaCore#getDefaultOptions()
367
	 * 
368
	 * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_PARAMETER} as variable kind.
299
	 */
369
	 */
300
	public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) {
370
	public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) {
301
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
371
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
Lines 327-337 Link Here
327
	 * @return char[] the name without prefix and suffix.
397
	 * @return char[] the name without prefix and suffix.
328
	 * @see JavaCore#setOptions(java.util.Hashtable)
398
	 * @see JavaCore#setOptions(java.util.Hashtable)
329
	 * @see JavaCore#getDefaultOptions()
399
	 * @see JavaCore#getDefaultOptions()
400
	 * 
401
	 * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_PARAMETER} as variable kind.
330
	 */
402
	 */
331
	public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) {
403
	public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) {
332
		return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray()));
404
		return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray()));
333
	}
405
	}
334
335
	/**
406
	/**
336
	 * Remove prefix and suffix from a field name.
407
	 * Remove prefix and suffix from a field name.
337
	 * <p>
408
	 * <p>
Lines 358-363 Link Here
358
	 * @see Flags
429
	 * @see Flags
359
	 * @see JavaCore#setOptions(java.util.Hashtable)
430
	 * @see JavaCore#setOptions(java.util.Hashtable)
360
	 * @see JavaCore#getDefaultOptions()
431
	 * @see JavaCore#getDefaultOptions()
432
	 * 
433
	 * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead
434
	 * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind.
361
	 */
435
	 */
362
	public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) {
436
	public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) {
363
		boolean isStatic = Flags.isStatic(modifiers);
437
		boolean isStatic = Flags.isStatic(modifiers);
Lines 394-403 Link Here
394
	 * @see Flags
468
	 * @see Flags
395
	 * @see JavaCore#setOptions(java.util.Hashtable)
469
	 * @see JavaCore#setOptions(java.util.Hashtable)
396
	 * @see JavaCore#getDefaultOptions()
470
	 * @see JavaCore#getDefaultOptions()
471
	 * 
472
	 * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead
473
	 * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind.
397
	 */
474
	 */
398
	public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) {
475
	public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) {
399
		return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers));
476
		return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers));
400
	}
477
	}
478
401
	/**
479
	/**
402
	 * Remove prefix and suffix from a local variable name.
480
	 * Remove prefix and suffix from a local variable name.
403
	 * <p>
481
	 * <p>
Lines 420-425 Link Here
420
	 * @return char[] the name without prefix and suffix.
498
	 * @return char[] the name without prefix and suffix.
421
	 * @see JavaCore#setOptions(java.util.Hashtable)
499
	 * @see JavaCore#setOptions(java.util.Hashtable)
422
	 * @see JavaCore#getDefaultOptions()
500
	 * @see JavaCore#getDefaultOptions()
501
	 * 
502
	 * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_LOCAL} as variable kind.
423
	 */
503
	 */
424
	public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) {
504
	public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) {
425
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
505
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
Lines 451-460 Link Here
451
	 * @return char[] the name without prefix and suffix.
531
	 * @return char[] the name without prefix and suffix.
452
	 * @see JavaCore#setOptions(java.util.Hashtable)
532
	 * @see JavaCore#setOptions(java.util.Hashtable)
453
	 * @see JavaCore#getDefaultOptions()
533
	 * @see JavaCore#getDefaultOptions()
534
	 * 
535
	 * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_LOCAL} as variable kind.
454
	 */
536
	 */
455
	public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) {
537
	public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) {
456
		return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray()));
538
		return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray()));
457
	}
539
	}
540
	
541
	/**
542
	 * Returns a base name which could be used to generate this variable name with {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)}.
543
	 * <p>
544
	 * e.g.<br>
545
	 * If the variable is a {@link #VK_LOCAL} and the variable name is <code>variableName</code> then the base name will be <code>VariableName</code>.<br>
546
	 * If the variable is a {@link #VK_CONSTANT_FIELD} and the variable name is <code>VARIABLE_NAME</code> then the base name will be <code>VariableName</code>.<br>
547
	 * </p>
548
	 * 
549
	 * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD},
550
	 * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}.
551
	 * @param variableName a variable name
552
	 * @param javaProject project which contains the variable or <code>null</code> to take into account only workspace settings.
553
	 * 
554
	 * @see #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)
555
	 * @since 3.5
556
	 */
557
	public static String getBaseName(
558
			int variableKind,
559
			String variableName,
560
			IJavaProject javaProject) {
561
		return String.valueOf(InternalNamingConventions.getBaseName(variableKind, javaProject, variableName.toCharArray()));
562
	}
563
564
	private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) {
565
		char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers);
566
		if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) {
567
			name[0] = ScannerHelper.toUpperCase(name[0]);
568
		}
569
		return name;
570
	}
458
571
459
	/**
572
	/**
460
	 * Suggest names for an argument. The name is computed from argument's type
573
	 * Suggest names for an argument. The name is computed from argument's type
Lines 483-488 Link Here
483
	 * @return char[][] an array of names.
596
	 * @return char[][] an array of names.
484
	 * @see JavaCore#setOptions(java.util.Hashtable)
597
	 * @see JavaCore#setOptions(java.util.Hashtable)
485
	 * @see JavaCore#getDefaultOptions()
598
	 * @see JavaCore#getDefaultOptions()
599
	 * 
600
	 * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind.
486
	 */
601
	 */
487
	public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
602
	public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
488
		NamingRequestor requestor = new NamingRequestor();
603
		NamingRequestor requestor = new NamingRequestor();
Lines 525-530 Link Here
525
	 * @return char[][] an array of names.
640
	 * @return char[][] an array of names.
526
	 * @see JavaCore#setOptions(java.util.Hashtable)
641
	 * @see JavaCore#setOptions(java.util.Hashtable)
527
	 * @see JavaCore#getDefaultOptions()
642
	 * @see JavaCore#getDefaultOptions()
643
	 * 
644
	 * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind.
528
	 */
645
	 */
529
	public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
646
	public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
530
		return convertCharsToString(
647
		return convertCharsToString(
Lines 535-540 Link Here
535
				dim,
652
				dim,
536
				convertStringToChars(excludedNames)));
653
				convertStringToChars(excludedNames)));
537
	}
654
	}
655
538
	/**
656
	/**
539
	 * Suggest names for a field. The name is computed from field's type
657
	 * Suggest names for a field. The name is computed from field's type
540
	 * and possible prefixes or suffixes are added.
658
	 * and possible prefixes or suffixes are added.
Lines 566-571 Link Here
566
	 * @see Flags
684
	 * @see Flags
567
	 * @see JavaCore#setOptions(java.util.Hashtable)
685
	 * @see JavaCore#setOptions(java.util.Hashtable)
568
	 * @see JavaCore#getDefaultOptions()
686
	 * @see JavaCore#getDefaultOptions()
687
	 * 
688
	 * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead 
689
	 * with {@link #VK_INSTANCE_FIELD} or  {@link #VK_STATIC_FIELD} as variable kind.
569
	 */
690
	 */
570
	public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) {
691
	public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) {
571
		NamingRequestor requestor = new NamingRequestor();
692
		NamingRequestor requestor = new NamingRequestor();
Lines 613-618 Link Here
613
	 * @see Flags
734
	 * @see Flags
614
	 * @see JavaCore#setOptions(java.util.Hashtable)
735
	 * @see JavaCore#setOptions(java.util.Hashtable)
615
	 * @see JavaCore#getDefaultOptions()
736
	 * @see JavaCore#getDefaultOptions()
737
	 * 
738
	 * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead 
739
	 * with {@link #VK_INSTANCE_FIELD} or  {@link #VK_STATIC_FIELD} as variable kind.
616
	 */
740
	 */
617
	public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) {
741
	public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) {
618
		return convertCharsToString(
742
		return convertCharsToString(
Lines 624-710 Link Here
624
				modifiers,
748
				modifiers,
625
				convertStringToChars(excludedNames)));
749
				convertStringToChars(excludedNames)));
626
	}
750
	}
627
751
	
628
	/**
629
	 * Suggest names for a local variable. The name is computed from variable's type
630
	 * and possible prefixes or suffixes are added.
631
	 * <p>
632
	 * If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code>
633
	 * and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code>
634
	 * and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code>
635
	 * and <code>name</code>.
636
	 * </p>
637
	 * <p>
638
	 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and
639
	 *  {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}.
640
	 * </p>
641
	 * <p>
642
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
643
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
644
	 * </p>
645
	 *
646
	 * @param javaProject project which contains the variable.
647
	 * @param packageName package of the variable's type.
648
	 * @param qualifiedTypeName variable's type.
649
	 * @param dim variable's dimension (0 if the variable is not an array).
650
	 * @param excludedNames a list of names which cannot be suggested (already used names).
651
	 *         Can be <code>null</code> if there is no excluded names.
652
	 * @return char[][] an array of names.
653
	 * @see JavaCore#setOptions(java.util.Hashtable)
654
	 * @see JavaCore#getDefaultOptions()
655
	 */
656
	public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
657
		NamingRequestor requestor = new NamingRequestor();
658
		InternalNamingConventions.suggestLocalVariableNames(
659
			javaProject,
660
			packageName,
661
			qualifiedTypeName,
662
			dim,
663
			null,
664
			excludedNames,
665
			requestor);
666
667
		return requestor.getResults();
668
	}
669
670
	/**
671
	 * Suggest names for a local variable. The name is computed from variable's type
672
	 * and possible prefixes or suffixes are added.
673
	 * <p>
674
	 * If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code>
675
	 * and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code>
676
	 * and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code>
677
	 * and <code>name</code>.
678
	 * </p>
679
	 * <p>
680
	 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and
681
	 *  {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}.
682
	 * </p>
683
	 * <p>
684
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
685
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
686
	 * </p>
687
	 *
688
	 * @param javaProject project which contains the variable.
689
	 * @param packageName package of the variable's type.
690
	 * @param qualifiedTypeName variable's type.
691
	 * @param dim variable's dimension (0 if the variable is not an array).
692
	 * @param excludedNames a list of names which cannot be suggested (already used names).
693
	 *         Can be <code>null</code> if there is no excluded names.
694
	 * @return char[][] an array of names.
695
	 * @see JavaCore#setOptions(java.util.Hashtable)
696
	 * @see JavaCore#getDefaultOptions()
697
	 */
698
	public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
699
		return convertCharsToString(
700
			suggestLocalVariableNames(
701
				javaProject,
702
				packageName.toCharArray(),
703
				qualifiedTypeName.toCharArray(),
704
				dim,
705
				convertStringToChars(excludedNames)));
706
	}
707
708
	/**
752
	/**
709
	 * Suggest name for a getter method. The name is computed from field's name
753
	 * Suggest name for a getter method. The name is computed from field's name
710
	 * and possible prefixes or suffixes are removed.
754
	 * and possible prefixes or suffixes are removed.
Lines 756-762 Link Here
756
			);
800
			);
757
		}
801
		}
758
	}
802
	}
759
760
	/**
803
	/**
761
	 * Suggest name for a getter method. The name is computed from field's name
804
	 * Suggest name for a getter method. The name is computed from field's name
762
	 * and possible prefixes or suffixes are removed.
805
	 * and possible prefixes or suffixes are removed.
Lines 797-803 Link Here
797
				isBoolean,
840
				isBoolean,
798
				convertStringToChars(excludedNames)));
841
				convertStringToChars(excludedNames)));
799
	}
842
	}
843
	/**
844
	 * Suggest names for a local variable. The name is computed from variable's type
845
	 * and possible prefixes or suffixes are added.
846
	 * <p>
847
	 * If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code>
848
	 * and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code>
849
	 * and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code>
850
	 * and <code>name</code>.
851
	 * </p>
852
	 * <p>
853
	 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and
854
	 *  {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}.
855
	 * </p>
856
	 * <p>
857
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
858
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
859
	 * </p>
860
	 *
861
	 * @param javaProject project which contains the variable.
862
	 * @param packageName package of the variable's type.
863
	 * @param qualifiedTypeName variable's type.
864
	 * @param dim variable's dimension (0 if the variable is not an array).
865
	 * @param excludedNames a list of names which cannot be suggested (already used names).
866
	 *         Can be <code>null</code> if there is no excluded names.
867
	 * @return char[][] an array of names.
868
	 * @see JavaCore#setOptions(java.util.Hashtable)
869
	 * @see JavaCore#getDefaultOptions()
870
	 * 
871
	 * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind.
872
	 */
873
	public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
874
		NamingRequestor requestor = new NamingRequestor();
875
		InternalNamingConventions.suggestLocalVariableNames(
876
			javaProject,
877
			packageName,
878
			qualifiedTypeName,
879
			dim,
880
			null,
881
			excludedNames,
882
			requestor);
800
883
884
		return requestor.getResults();
885
	}
886
	/**
887
	 * Suggest names for a local variable. The name is computed from variable's type
888
	 * and possible prefixes or suffixes are added.
889
	 * <p>
890
	 * If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code>
891
	 * and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code>
892
	 * and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code>
893
	 * and <code>name</code>.
894
	 * </p>
895
	 * <p>
896
	 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and
897
	 *  {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}.
898
	 * </p>
899
	 * <p>
900
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
901
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
902
	 * </p>
903
	 *
904
	 * @param javaProject project which contains the variable.
905
	 * @param packageName package of the variable's type.
906
	 * @param qualifiedTypeName variable's type.
907
	 * @param dim variable's dimension (0 if the variable is not an array).
908
	 * @param excludedNames a list of names which cannot be suggested (already used names).
909
	 *         Can be <code>null</code> if there is no excluded names.
910
	 * @return char[][] an array of names.
911
	 * @see JavaCore#setOptions(java.util.Hashtable)
912
	 * @see JavaCore#getDefaultOptions()
913
	 * 
914
	 * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind.
915
	 */
916
	public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
917
		return convertCharsToString(
918
			suggestLocalVariableNames(
919
				javaProject,
920
				packageName.toCharArray(),
921
				qualifiedTypeName.toCharArray(),
922
				dim,
923
				convertStringToChars(excludedNames)));
924
	}
925
	private static char[] suggestNewName(char[] name, char[][] excludedNames){
926
		if(excludedNames == null) {
927
			return name;
928
		}
929
930
		char[] newName = name;
931
		int count = 2;
932
		int i = 0;
933
		while (i < excludedNames.length) {
934
			if(CharOperation.equals(newName, excludedNames[i], false)) {
935
				newName = CharOperation.concat(name, String.valueOf(count++).toCharArray());
936
				i = 0;
937
			} else {
938
				i++;
939
			}
940
		}
941
		return newName;
942
	}
943
	
801
	/**
944
	/**
802
	 * Suggest name for a setter method. The name is computed from field's name
945
	 * Suggest name for a setter method. The name is computed from field's name
803
	 * and possible prefixes or suffixes are removed.
946
	 * and possible prefixes or suffixes are removed.
Lines 853-859 Link Here
853
			);
996
			);
854
		}
997
		}
855
	}
998
	}
856
857
	/**
999
	/**
858
	 * Suggest name for a setter method. The name is computed from field's name
1000
	 * Suggest name for a setter method. The name is computed from field's name
859
	 * and possible prefixes or suffixes are removed.
1001
	 * and possible prefixes or suffixes are removed.
Lines 893-945 Link Here
893
				isBoolean,
1035
				isBoolean,
894
				convertStringToChars(excludedNames)));
1036
				convertStringToChars(excludedNames)));
895
	}
1037
	}
1038
	
1039
	/**
1040
	 * Suggests names for a variable. The name is computed from a base name and possible prefixes or suffixes are added.
1041
	 *
1042
	 * <p>
1043
	 * The base name is used to compute the variable name.
1044
	 * Some different kinds of base name are possible and each kind is associated to a different heuristic to compute variable names.<br>
1045
	 * The heuristic depends also of the kind of the variable. Each kind of variable is identified by a constant starting with <code>VK_</code>.<br>
1046
	 * When a prefix and a suffix can be added then all combinations of prefix and suffix are suggested.
1047
	 * If the name is <code>name</code>, the prefix is <code>pre</code> and the suffix is <code>suf</code> then the suggested names will be
1048
	 * <code>prenamesuf</code>, <code>prename</code>, <code>namesuf</code> and <code>name</code>.<br>
1049
	 * <br>
1050
	 * The different kinds of base name are:
1051
	 * <ul>
1052
	 * <li>{@link #BK_NAME}: the base name is a Java name and the whole base name is considered to compute the variable names. A prefix and a suffix can be added.<br>
1053
	 * There is an heuristic by variable kind.
1054
	 * <ul>
1055
	 * <li>{@link #VK_PARAMETER}, {@link #VK_LOCAL}, {@link #VK_INSTANCE_FIELD} and {@link #VK_STATIC_FIELD}:<br>
1056
	 * In this case the first character will be converted to lower case and the other characters won't be changed.<br>
1057
	 * If the base name is <code>SimpleName</code> then the suggested name will be <code>simpleName</code>.<br></li>
1058
	 * <li>{@link #VK_CONSTANT_FIELD} :<br>
1059
	 * In this case all letters of the name will be converted to upper case and words will be separated by an underscore (<code>"_"</code>).<br>
1060
	 * If the base name is <code>SimpleName</code> then the suggested name will be <code>SIMPLE_NAME</code>.</li>
1061
	 * </ul></li>
1062
	 * <li>{@link #BK_TYPE_NAME}: the base name is a Java simple type name (e.g. <code>HashMap</code>) and all the words of the base name are considered to compute the variable names. A prefix and a suffix can be added to these names.<br>
1063
	 * There is an heuristic by variable kind.
1064
	 * <ul>
1065
	 * <li>{@link #VK_PARAMETER}, {@link #VK_LOCAL}, {@link #VK_INSTANCE_FIELD} and {@link #VK_STATIC_FIELD}:<br>
1066
	 * In this case a variable name will contain some words of the base name and the first character will be converted to lower case.<br>
1067
	 * If the type is <code>TypeName</code> then the suggested names will be <code>typeName</code> and <code>name</code>.</li>
1068
	 * <li>{@link #VK_CONSTANT_FIELD} :<br>
1069
	 * In this case a variable name will contain some words of the base name, all letters of the name will be converted to upper case and segments will be separated by a underscore (<code>"_"</code>).<br>
1070
	 * If the base name is <code>TypeName</code> then the suggested name will be <code>TYPE_NAME</code> and <code>NAME</code>.</li>
1071
	 * </ul></li>
1072
	 * </ul>
1073
	 * Some other kinds could be added in the future.
1074
	 * </p>
1075
	 * <p>
1076
	 * Each variable kind is affected by the following JavaCore options:
1077
	 * <ul>
1078
	 * <li>{@link #VK_PARAMETER}: {@link JavaCore#CODEASSIST_ARGUMENT_PREFIXES} and {@link JavaCore#CODEASSIST_ARGUMENT_SUFFIXES}</li>
1079
	 * <li>{@link #VK_LOCAL}: {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}</li>
1080
	 * <li>{@link #VK_INSTANCE_FIELD}: {@link JavaCore#CODEASSIST_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_FIELD_SUFFIXES}</li>
1081
	 * <li>{@link #VK_STATIC_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES}</li>
1082
	 * <li>{@link #VK_CONSTANT_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES}</li>
1083
	 * </ul>
1084
	 * </p>
1085
	 * <p>
1086
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
1087
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
1088
	 * </p>
1089
	 * <p>
1090
	 * Proposed names are sorted by relevance (best proposal first).<br>
1091
	 * The names are proposed in the following order:
1092
	 * <ol>
1093
	 * <li>Names with prefix and suffix. Longest name are proposed first</li>
1094
	 * <li>Names with prefix. Longest name are proposed first</li>
1095
	 * <li>Names with suffix. Longest name are proposed first</li>
1096
	 * <li>Names without prefix and suffix. Longest name are proposed first</li>
1097
	 * </ol>
1098
	 * </p>
1099
	 *
1100
	 * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD},
1101
	 * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}.
1102
	 * @param baseNameKind specifies what type the base name is: {@link #BK_NAME} or {@link #BK_TYPE_NAME}
1103
	 * @param baseName name used to compute the suggested names.
1104
	 * @param javaProject project which contains the variable or <code>null</code> to take into account only workspace settings.
1105
	 * @param dim variable dimension (0 if the field is not an array).
1106
	 * @param excluded a list of names which cannot be suggested (already used names).
1107
	 *         Can be <code>null</code> if there is no excluded names.
1108
	 * @param evaluateDefault if set, the result is guaranteed to contain at least one result. If not, the result can be an empty array. 
1109
	 * @return String[] an array of names.
1110
	 * @see JavaCore#setOptions(java.util.Hashtable)
1111
	 * @see JavaCore#getDefaultOptions()
1112
	 * 
1113
	 * @since 3.5
1114
	 */
1115
	public static String[] suggestVariableNames(
1116
			int variableKind,
1117
			int baseNameKind,
1118
			String baseName,
1119
			IJavaProject javaProject,
1120
			int dim,
1121
			String[] excluded,
1122
			boolean evaluateDefault) {
1123
		
1124
		NamingRequestor requestor = new NamingRequestor();
1125
		InternalNamingConventions.suggestVariableNames(
1126
			variableKind,
1127
			baseNameKind,
1128
			baseName.toCharArray(),
1129
			javaProject,
1130
			dim,
1131
			null,
1132
			convertStringToChars(excluded),
1133
			evaluateDefault,
1134
			requestor);
896
1135
897
	private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) {
1136
		return convertCharsToString(requestor.getResults());
898
		char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers);
899
		if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) {
900
			name[0] = ScannerHelper.toUpperCase(name[0]);
901
		}
902
		return name;
903
	}
904
905
	private static char[] suggestNewName(char[] name, char[][] excludedNames){
906
		if(excludedNames == null) {
907
			return name;
908
		}
909
910
		char[] newName = name;
911
		int count = 2;
912
		int i = 0;
913
		while (i < excludedNames.length) {
914
			if(CharOperation.equals(newName, excludedNames[i], false)) {
915
				newName = CharOperation.concat(name, String.valueOf(count++).toCharArray());
916
				i = 0;
917
			} else {
918
				i++;
919
			}
920
		}
921
		return newName;
922
	}
923
924
	private static String[] convertCharsToString(char[][] c) {
925
		int length = c == null ? 0 : c.length;
926
		String[] s = new String[length];
927
		for (int i = 0; i < length; i++) {
928
			s[i] = String.valueOf(c[i]);
929
		}
930
		return s;
931
	}
1137
	}
932
1138
	
933
	private static char[][] convertStringToChars(String[] s) {
1139
	private NamingConventions() {
934
		int length = s == null ? 0 : s.length;
1140
		// Not instantiable
935
		char[][] c = new char[length][];
936
		for (int i = 0; i < length; i++) {
937
			if(s[i] == null) {
938
				c[i] = CharOperation.NO_CHAR;
939
			} else {
940
				c[i] = s[i].toCharArray();
941
			}
942
		}
943
		return c;
944
	}
1141
	}
945
}
1142
}
(-)compiler/org/eclipse/jdt/core/compiler/CharOperation.java (+48 lines)
Lines 3582-3587 Link Here
3582
}
3582
}
3583
3583
3584
/**
3584
/**
3585
 * Answers the result of a char[] conversion to uppercase. Answers null if the given chars array is null.
3586
 * <br>
3587
 * NOTE: If no conversion was necessary, then answers back the argument one.
3588
 * <br>
3589
 * <br>
3590
 * For example:
3591
 * <ol>
3592
 * <li><pre>
3593
 *    chars = { 'A' , 'B' }
3594
 *    result => { 'A' , 'B' }
3595
 * </pre>
3596
 * </li>
3597
 * <li><pre>
3598
 *    array = { 'a', 'B' }
3599
 *    result => { 'A' , 'B' }
3600
 * </pre>
3601
 * </li>
3602
 * </ol>
3603
 *
3604
 * @param chars the chars to convert
3605
 * @return the result of a char[] conversion to uppercase
3606
 * 
3607
 * @since 3.5
3608
 */
3609
final static public char[] toUpperCase(char[] chars) {
3610
	if (chars == null)
3611
		return null;
3612
	int length = chars.length;
3613
	char[] upperChars = null;
3614
	for (int i = 0; i < length; i++) {
3615
		char c = chars[i];
3616
		char lc = ScannerHelper.toUpperCase(c);
3617
		if ((c != lc) || (upperChars != null)) {
3618
			if (upperChars == null) {
3619
				System.arraycopy(
3620
					chars,
3621
					0,
3622
					upperChars = new char[length],
3623
					0,
3624
					i);
3625
			}
3626
			upperChars[i] = lc;
3627
		}
3628
	}
3629
	return upperChars == null ? chars : upperChars;
3630
}
3631
3632
/**
3585
 * Answers a new array removing leading and trailing spaces (' '). Answers the given array if there is no
3633
 * Answers a new array removing leading and trailing spaces (' '). Answers the given array if there is no
3586
 * space characters to remove.
3634
 * space characters to remove.
3587
 * <br>
3635
 * <br>
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java (+26 lines)
Lines 28-33 Link Here
28
		"org.eclipse.jdt.core.codeComplete.fieldPrefixes"; 	//$NON-NLS-1$
28
		"org.eclipse.jdt.core.codeComplete.fieldPrefixes"; 	//$NON-NLS-1$
29
	public static final String OPTION_StaticFieldPrefixes =
29
	public static final String OPTION_StaticFieldPrefixes =
30
		"org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"; 	//$NON-NLS-1$
30
		"org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"; 	//$NON-NLS-1$
31
	public static final String OPTION_StaticFinalFieldPrefixes =
32
		"org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"; 	//$NON-NLS-1$
31
	public static final String OPTION_LocalPrefixes =
33
	public static final String OPTION_LocalPrefixes =
32
		"org.eclipse.jdt.core.codeComplete.localPrefixes"; 	//$NON-NLS-1$
34
		"org.eclipse.jdt.core.codeComplete.localPrefixes"; 	//$NON-NLS-1$
33
	public static final String OPTION_ArgumentPrefixes =
35
	public static final String OPTION_ArgumentPrefixes =
Lines 36-41 Link Here
36
		"org.eclipse.jdt.core.codeComplete.fieldSuffixes"; 	//$NON-NLS-1$
38
		"org.eclipse.jdt.core.codeComplete.fieldSuffixes"; 	//$NON-NLS-1$
37
	public static final String OPTION_StaticFieldSuffixes =
39
	public static final String OPTION_StaticFieldSuffixes =
38
		"org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"; 	//$NON-NLS-1$
40
		"org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"; 	//$NON-NLS-1$
41
	public static final String OPTION_StaticFinalFieldSuffixes =
42
		"org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"; 	//$NON-NLS-1$
39
	public static final String OPTION_LocalSuffixes =
43
	public static final String OPTION_LocalSuffixes =
40
		"org.eclipse.jdt.core.codeComplete.localSuffixes"; 	//$NON-NLS-1$
44
		"org.eclipse.jdt.core.codeComplete.localSuffixes"; 	//$NON-NLS-1$
41
	public static final String OPTION_ArgumentSuffixes =
45
	public static final String OPTION_ArgumentSuffixes =
Lines 61-70 Link Here
61
	public boolean suggestStaticImport = true;
65
	public boolean suggestStaticImport = true;
62
	public char[][] fieldPrefixes = null;
66
	public char[][] fieldPrefixes = null;
63
	public char[][] staticFieldPrefixes = null;
67
	public char[][] staticFieldPrefixes = null;
68
	public char[][] staticFinalFieldPrefixes = null;
64
	public char[][] localPrefixes = null;
69
	public char[][] localPrefixes = null;
65
	public char[][] argumentPrefixes = null;
70
	public char[][] argumentPrefixes = null;
66
	public char[][] fieldSuffixes = null;
71
	public char[][] fieldSuffixes = null;
67
	public char[][] staticFieldSuffixes = null;
72
	public char[][] staticFieldSuffixes = null;
73
	public char[][] staticFinalFieldSuffixes = null;
68
	public char[][] localSuffixes = null;
74
	public char[][] localSuffixes = null;
69
	public char[][] argumentSuffixes = null;
75
	public char[][] argumentSuffixes = null;
70
76
Lines 121-126 Link Here
121
				}
127
				}
122
			}
128
			}
123
		}
129
		}
130
		if ((optionValue = optionsMap.get(OPTION_StaticFinalFieldPrefixes)) != null) {
131
			if (optionValue instanceof String) {
132
				String stringValue = (String) optionValue;
133
				if (stringValue.length() > 0){
134
					this.staticFinalFieldPrefixes = splitAndTrimOn(',', stringValue.toCharArray());
135
				} else {
136
					this.staticFinalFieldPrefixes = null;
137
				}
138
			}
139
		}
124
		if ((optionValue = optionsMap.get(OPTION_LocalPrefixes)) != null) {
140
		if ((optionValue = optionsMap.get(OPTION_LocalPrefixes)) != null) {
125
			if (optionValue instanceof String) {
141
			if (optionValue instanceof String) {
126
				String stringValue = (String) optionValue;
142
				String stringValue = (String) optionValue;
Lines 161-166 Link Here
161
				}
177
				}
162
			}
178
			}
163
		}
179
		}
180
		if ((optionValue = optionsMap.get(OPTION_StaticFinalFieldSuffixes)) != null) {
181
			if (optionValue instanceof String) {
182
				String stringValue = (String) optionValue;
183
				if (stringValue.length() > 0){
184
					this.staticFinalFieldSuffixes = splitAndTrimOn(',', stringValue.toCharArray());
185
				} else {
186
					this.staticFinalFieldSuffixes = null;
187
				}
188
			}
189
		}
164
		if ((optionValue = optionsMap.get(OPTION_LocalSuffixes)) != null) {
190
		if ((optionValue = optionsMap.get(OPTION_LocalSuffixes)) != null) {
165
			if (optionValue instanceof String) {
191
			if (optionValue instanceof String) {
166
				String stringValue = (String) optionValue;
192
				String stringValue = (String) optionValue;
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-57 / +39 lines)
Lines 342-351 Link Here
342
	private final static int SUPERTYPE = 1;
342
	private final static int SUPERTYPE = 1;
343
	private final static int SUBTYPE = 2;
343
	private final static int SUBTYPE = 2;
344
	
344
	
345
	private final static int FIELD = 0;
346
	private final static int LOCAL = 1;
347
	private final static int ARGUMENT = 2;
348
	
349
	int expectedTypesPtr = -1;
345
	int expectedTypesPtr = -1;
350
	TypeBinding[] expectedTypes = new TypeBinding[1];
346
	TypeBinding[] expectedTypes = new TypeBinding[1];
351
	int expectedTypesFilter;
347
	int expectedTypesFilter;
Lines 1559-1565 Link Here
1559
1555
1560
			this.completionToken = field.realName;
1556
			this.completionToken = field.realName;
1561
1557
1562
			findVariableNames(field.realName, field.type, excludeNames, null, FIELD, field.modifiers);
1558
			
1559
			int kind =
1560
				 (field.modifiers & ClassFileConstants.AccStatic) == 0 ? 
1561
						InternalNamingConventions.VK_INSTANCE_FIELD :
1562
							(field.modifiers & ClassFileConstants.AccFinal) == 0 ? 
1563
									InternalNamingConventions.VK_STATIC_FIELD :
1564
										InternalNamingConventions.VK_CONSTANT_FIELD;
1565
			
1566
			findVariableNames(field.realName, field.type, excludeNames, null, kind);
1563
		}
1567
		}
1564
	}
1568
	}
1565
	
1569
	
Lines 1826-1836 Link Here
1826
			int kind;
1830
			int kind;
1827
			if (variable instanceof CompletionOnLocalName){
1831
			if (variable instanceof CompletionOnLocalName){
1828
				this.completionToken = ((CompletionOnLocalName) variable).realName;
1832
				this.completionToken = ((CompletionOnLocalName) variable).realName;
1829
				kind = LOCAL;
1833
				kind = InternalNamingConventions.VK_LOCAL;
1830
			} else {
1834
			} else {
1831
				CompletionOnArgumentName arg = (CompletionOnArgumentName) variable;
1835
				CompletionOnArgumentName arg = (CompletionOnArgumentName) variable;
1832
				this.completionToken = arg.realName;
1836
				this.completionToken = arg.realName;
1833
				kind = arg.isCatchArgument ? LOCAL : ARGUMENT;
1837
				kind = arg.isCatchArgument ? InternalNamingConventions.VK_LOCAL : InternalNamingConventions.VK_PARAMETER;
1834
			}
1838
			}
1835
1839
1836
			char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, variable);
1840
			char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, variable);
Lines 1848-1854 Link Here
1848
1852
1849
			System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount);
1853
			System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount);
1850
1854
1851
			findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind, variable.modifiers);
1855
			findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind);
1852
		}
1856
		}
1853
	}
1857
	}
1854
	
1858
	
Lines 2166-2172 Link Here
2166
2170
2167
			this.completionToken = method.selector;
2171
			this.completionToken = method.selector;
2168
2172
2169
			findVariableNames(this.completionToken, method.returnType, excludeNames, null, FIELD, method.modifiers);
2173
			
2174
			int kind =
2175
				 (method.modifiers & ClassFileConstants.AccStatic) == 0 ? 
2176
						InternalNamingConventions.VK_INSTANCE_FIELD :
2177
							(method.modifiers & ClassFileConstants.AccFinal) == 0 ? 
2178
									InternalNamingConventions.VK_STATIC_FIELD :
2179
										InternalNamingConventions.VK_CONSTANT_FIELD;
2180
						
2181
			findVariableNames(this.completionToken, method.returnType, excludeNames, null, kind);
2170
		}
2182
		}
2171
	}
2183
	}
2172
	
2184
	
Lines 9674-9681 Link Here
9674
			final char[][] forbiddenNames,
9686
			final char[][] forbiddenNames,
9675
			boolean forCollection,
9687
			boolean forCollection,
9676
			int dim,
9688
			int dim,
9677
			int kind,
9689
			int kind){
9678
			int modifiers){
9679
9690
9680
		if(sourceName == null || sourceName.length == 0)
9691
		if(sourceName == null || sourceName.length == 0)
9681
			return;
9692
			return;
Lines 9755-9793 Link Here
9755
			}
9766
			}
9756
		};
9767
		};
9757
9768
9758
		switch (kind) {
9769
		InternalNamingConventions.suggestVariableNames(
9759
			case FIELD :
9770
				kind,
9760
				InternalNamingConventions.suggestFieldNames(
9771
				InternalNamingConventions.BK_SIMPLE_TYPE_NAME,
9761
					this.javaProject,
9772
				qualifiedSourceName,
9762
					qualifiedPackageName,
9773
				this.javaProject,
9763
					qualifiedSourceName,
9774
				dim,
9764
					dim,
9775
				token,
9765
					modifiers,
9776
				discouragedNames,
9766
					token,
9777
				true,
9767
					discouragedNames,
9778
				namingRequestor);
9768
					namingRequestor);
9769
				break;
9770
			case LOCAL :
9771
				InternalNamingConventions.suggestLocalVariableNames(
9772
					this.javaProject,
9773
					qualifiedPackageName,
9774
					qualifiedSourceName,
9775
					dim,
9776
					token,
9777
					discouragedNames,
9778
					namingRequestor);
9779
				break;
9780
			case ARGUMENT :
9781
				InternalNamingConventions.suggestArgumentNames(
9782
					this.javaProject,
9783
					qualifiedPackageName,
9784
					qualifiedSourceName,
9785
					dim,
9786
					token,
9787
					discouragedNames,
9788
					namingRequestor);
9789
				break;
9790
		}
9791
	}
9779
	}
9792
9780
9793
	// Helper method for private void findVariableNames(char[] name, TypeReference type )
9781
	// Helper method for private void findVariableNames(char[] name, TypeReference type )
Lines 9800-9807 Link Here
9800
			char[][] discouragedNames,
9788
			char[][] discouragedNames,
9801
			final char[][] forbiddenNames,
9789
			final char[][] forbiddenNames,
9802
			int dim,
9790
			int dim,
9803
			int kind,
9791
			int kind){
9804
			int modifiers){
9805
		findVariableName(
9792
		findVariableName(
9806
				token,
9793
				token,
9807
				qualifiedPackageName,
9794
				qualifiedPackageName,
Lines 9812-9819 Link Here
9812
				forbiddenNames,
9799
				forbiddenNames,
9813
				false,
9800
				false,
9814
				dim,
9801
				dim,
9815
				kind,
9802
				kind);
9816
				modifiers);
9817
	}
9803
	}
9818
	private void findVariableNameForCollection(
9804
	private void findVariableNameForCollection(
9819
			char[] token,
9805
			char[] token,
Lines 9823-9830 Link Here
9823
			final TypeBinding typeBinding,
9809
			final TypeBinding typeBinding,
9824
			char[][] discouragedNames,
9810
			char[][] discouragedNames,
9825
			final char[][] forbiddenNames,
9811
			final char[][] forbiddenNames,
9826
			int kind,
9812
			int kind){
9827
			int modifiers){
9828
9813
9829
		findVariableName(
9814
		findVariableName(
9830
				token,
9815
				token,
Lines 9836-9845 Link Here
9836
				forbiddenNames,
9821
				forbiddenNames,
9837
				false,
9822
				false,
9838
				1,
9823
				1,
9839
				kind,
9824
				kind);
9840
				modifiers);
9841
	}
9825
	}
9842
	private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind, int modifiers){
9826
	private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind){
9843
		if(type != null &&
9827
		if(type != null &&
9844
			type.resolvedType != null) {
9828
			type.resolvedType != null) {
9845
			TypeBinding tb = type.resolvedType;
9829
			TypeBinding tb = type.resolvedType;
Lines 9855-9862 Link Here
9855
					discouragedNames,
9839
					discouragedNames,
9856
					forbiddenNames,
9840
					forbiddenNames,
9857
					type.dimensions(),
9841
					type.dimensions(),
9858
					kind,
9842
					kind);
9859
					modifiers);
9860
				
9843
				
9861
				if (tb.isParameterizedType() &&
9844
				if (tb.isParameterizedType() &&
9862
						tb.findSuperTypeOriginatingFrom(TypeIds.T_JavaUtilCollection, false) != null) {
9845
						tb.findSuperTypeOriginatingFrom(TypeIds.T_JavaUtilCollection, false) != null) {
Lines 9872-9879 Link Here
9872
							tb,
9855
							tb,
9873
							discouragedNames,
9856
							discouragedNames,
9874
							forbiddenNames,
9857
							forbiddenNames,
9875
							kind,
9858
							kind);
9876
							modifiers);
9877
					}
9859
					}
9878
				}
9860
				}
9879
			}
9861
			}

Return to bug 38111