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 (+115 lines)
Lines 5079-5084 Link Here
5079
			requestor.getResults());
5079
			requestor.getResults());
5080
}
5080
}
5081
5081
5082
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5083
public void testCompletionFieldName3() throws JavaModelException { 
5084
	this.workingCopies = new ICompilationUnit[1];
5085
	this.workingCopies[0] = getWorkingCopy(
5086
		"/Completion/src/test/TypeNameRequestor.java",
5087
		"package test;"+
5088
		"public class TypeNameRequestor {\n" +
5089
		"  public static final TypeNameRequestor \n" +
5090
		"}\n");
5091
5092
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5093
	String str = this.workingCopies[0].getSource();
5094
	String completeBehind = "final TypeNameRequestor ";
5095
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5096
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5097
5098
	assertResults(
5099
			"NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
5100
			"REQUESTOR[VARIABLE_DECLARATION]{REQUESTOR, null, Ltest.TypeNameRequestor;, REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
5101
			"TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
5102
			requestor.getResults());
5103
}
5104
5105
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5106
public void testCompletionFieldName4() throws JavaModelException { 
5107
	this.workingCopies = new ICompilationUnit[1];
5108
	this.workingCopies[0] = getWorkingCopy(
5109
		"/Completion/src/test/TypeNameRequestor.java",
5110
		"package test;"+
5111
		"public class TypeNameRequestor {\n" +
5112
		"  public static final TypeNameRequestor nam\n" +
5113
		"}\n");
5114
5115
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5116
	String str = this.workingCopies[0].getSource();
5117
	String completeBehind = "final TypeNameRequestor nam";
5118
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5119
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5120
5121
	assertResults(
5122
			"NAM_REQUESTOR[VARIABLE_DECLARATION]{NAM_REQUESTOR, null, Ltest.TypeNameRequestor;, NAM_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
5123
			"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" +
5124
			"NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NAME_LESS_NEW_CHARACTERS+ R_NON_RESTRICTED) + "}",
5125
			requestor.getResults());
5126
}
5127
5128
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5129
public void testCompletionFieldName5() throws JavaModelException { 
5130
	this.workingCopies = new ICompilationUnit[1];
5131
	this.workingCopies[0] = getWorkingCopy(
5132
		"/Completion/src/test/TypeNameRequestor.java",
5133
		"package test;"+
5134
		"public class TypeNameRequestor {\n" +
5135
		"  public static final TypeNameRequestor ZZ\n" +
5136
		"}\n");
5137
5138
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5139
	String str = this.workingCopies[0].getSource();
5140
	String completeBehind = "final TypeNameRequestor ZZ";
5141
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5142
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5143
5144
	assertResults(
5145
			"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" +
5146
			"ZZ_REQUESTOR[VARIABLE_DECLARATION]{ZZ_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" +
5147
			"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) + "}",
5148
			requestor.getResults());
5149
}
5150
5151
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5152
public void testCompletionFieldName6() throws JavaModelException { 
5153
	this.workingCopies = new ICompilationUnit[1];
5154
	this.workingCopies[0] = getWorkingCopy(
5155
		"/Completion/src/test/TypeNameRequestor.java",
5156
		"package test;"+
5157
		"public class TypeNameRequestor {\n" +
5158
		"  public static final TypeNameRequestor ZZN\n" +
5159
		"}\n");
5160
5161
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5162
	String str = this.workingCopies[0].getSource();
5163
	String completeBehind = "final TypeNameRequestor ZZN";
5164
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5165
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5166
5167
	assertResults(
5168
			"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" +
5169
			"ZZN_REQUESTOR[VARIABLE_DECLARATION]{ZZN_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" +
5170
			"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) + "}",
5171
			requestor.getResults());
5172
}
5173
5174
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
5175
public void testCompletionFieldName7() throws JavaModelException { 
5176
	this.workingCopies = new ICompilationUnit[1];
5177
	this.workingCopies[0] = getWorkingCopy(
5178
		"/Completion/src/test/TypeNameRequestor.java",
5179
		"package test;"+
5180
		"public class TypeNameRequestor {\n" +
5181
		"  public static final TypeNameRequestor ZZ_N\n" +
5182
		"}\n");
5183
5184
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
5185
	String str = this.workingCopies[0].getSource();
5186
	String completeBehind = "final TypeNameRequestor ZZ_N";
5187
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5188
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
5189
5190
	assertResults(
5191
			"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" +
5192
			"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" +
5193
			"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) + "}",
5194
			requestor.getResults());
5195
}
5196
5082
/**
5197
/**
5083
 * Complete the type "A" from "new A".
5198
 * Complete the type "A" from "new A".
5084
 */
5199
 */
(-)src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java (-197 / +277 lines)
Lines 16-22 Link Here
16
16
17
import junit.framework.Test;
17
import junit.framework.Test;
18
18
19
import org.eclipse.jdt.core.Flags;
20
import org.eclipse.jdt.core.JavaCore;
19
import org.eclipse.jdt.core.JavaCore;
21
import org.eclipse.jdt.core.NamingConventions;
20
import org.eclipse.jdt.core.NamingConventions;
22
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 53-94 Link Here
53
52
54
	super.tearDown();
53
	super.tearDown();
55
}
54
}
56
private String toString(char[][] suggestions) {
57
	if(suggestions == null) {
58
		return ""; //$NON-NLS-1$
59
	}
60
61
	StringBuffer buffer = new StringBuffer();
62
	for (int i = 0; i < suggestions.length; i++) {
63
		if(i != 0) {
64
			buffer.append('\n');
65
		}
66
		buffer.append(suggestions[i]);
67
	}
68
	return buffer.toString();
69
}
70
public void testSuggestFieldName001() {
55
public void testSuggestFieldName001() {
71
	char[][] suggestions = NamingConventions.suggestFieldNames(
56
	String[] suggestions = NamingConventions.getVariableNames(
72
		this.project,
57
			NamingConventions.VK_INSTANCE_FIELD,
73
		"a.b.c".toCharArray(), //$NON-NLS-1$
58
			NamingConventions.BK_SIMPLE_TYPE_NAME,
74
		"OneName".toCharArray(), //$NON-NLS-1$
59
			"OneName", //$NON-NLS-1$
75
		0,
60
			this.project,
76
		0,
61
			0,
77
		CharOperation.NO_CHAR_CHAR);
62
			new String[]{},
63
			true);
64
78
	assumeEquals(
65
	assumeEquals(
79
		"name\n" + //$NON-NLS-1$
66
		"name\n" + //$NON-NLS-1$
80
		"oneName", //$NON-NLS-1$
67
		"oneName", //$NON-NLS-1$
81
		toString(suggestions));
68
		toString(suggestions));
82
}
69
}
83
public void testSuggestFieldName002() {
70
public void testSuggestFieldName002() {
84
	char[][] suggestions = NamingConventions.suggestFieldNames(
71
	String[] suggestions = NamingConventions.getVariableNames(
85
		this.project,
72
			NamingConventions.VK_INSTANCE_FIELD,
86
		"a.b.c".toCharArray(), //$NON-NLS-1$
73
			NamingConventions.BK_SIMPLE_TYPE_NAME,
87
		"OneClass".toCharArray(), //$NON-NLS-1$
74
			"OneClass", //$NON-NLS-1$
88
		0,
75
			this.project,
89
		0,
76
			0,
90
		CharOperation.NO_CHAR_CHAR);
77
			new String[]{},
91
78
			true);
79
	
92
	assumeEquals(
80
	assumeEquals(
93
		"class1\n" + //$NON-NLS-1$
81
		"class1\n" + //$NON-NLS-1$
94
		"oneClass", //$NON-NLS-1$
82
		"oneClass", //$NON-NLS-1$
Lines 99-111 Link Here
99
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
87
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
100
	JavaCore.setOptions(options);
88
	JavaCore.setOptions(options);
101
89
102
	char[][] suggestions = NamingConventions.suggestFieldNames(
90
	String[] suggestions = NamingConventions.getVariableNames(
103
		this.project,
91
			NamingConventions.VK_INSTANCE_FIELD,
104
		"a.b.c".toCharArray(), //$NON-NLS-1$
92
			NamingConventions.BK_SIMPLE_TYPE_NAME,
105
		"OneName".toCharArray(), //$NON-NLS-1$
93
			"OneName", //$NON-NLS-1$
106
		0,
94
			this.project,
107
		0,
95
			0,
108
		CharOperation.NO_CHAR_CHAR);
96
			new String[]{},
97
			true);
109
98
110
	assumeEquals(
99
	assumeEquals(
111
		"fName\n" + //$NON-NLS-1$
100
		"fName\n" + //$NON-NLS-1$
Lines 119-131 Link Here
119
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"_"); //$NON-NLS-1$
108
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"_"); //$NON-NLS-1$
120
	JavaCore.setOptions(options);
109
	JavaCore.setOptions(options);
121
110
122
	char[][] suggestions = NamingConventions.suggestFieldNames(
111
	String[] suggestions = NamingConventions.getVariableNames(
123
		this.project,
112
			NamingConventions.VK_INSTANCE_FIELD,
124
		"a.b.c".toCharArray(), //$NON-NLS-1$
113
			NamingConventions.BK_SIMPLE_TYPE_NAME,
125
		"OneName".toCharArray(), //$NON-NLS-1$
114
			"OneName", //$NON-NLS-1$
126
		0,
115
			this.project,
127
		0,
116
			0,
128
		CharOperation.NO_CHAR_CHAR);
117
			new String[]{},
118
			true);
129
119
130
	assumeEquals(
120
	assumeEquals(
131
		"_name\n" + //$NON-NLS-1$
121
		"_name\n" + //$NON-NLS-1$
Lines 139-152 Link Here
139
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
129
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$
140
	options.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,"fg"); //$NON-NLS-1$
130
	options.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,"fg"); //$NON-NLS-1$
141
	JavaCore.setOptions(options);
131
	JavaCore.setOptions(options);
142
132
	
143
	char[][] suggestions = NamingConventions.suggestFieldNames(
133
	String[] suggestions = NamingConventions.getVariableNames(
144
		this.project,
134
			NamingConventions.VK_STATIC_FIELD,
145
		"a.b.c".toCharArray(), //$NON-NLS-1$
135
			NamingConventions.BK_SIMPLE_TYPE_NAME,
146
		"OneName".toCharArray(), //$NON-NLS-1$
136
			"OneName", //$NON-NLS-1$
147
		0,
137
			this.project,
148
		Flags.AccStatic,
138
			0,
149
		CharOperation.NO_CHAR_CHAR);
139
			new String[]{},
140
			true);
150
141
151
	assumeEquals(
142
	assumeEquals(
152
		"fgName\n" + //$NON-NLS-1$
143
		"fgName\n" + //$NON-NLS-1$
Lines 161-173 Link Here
161
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
152
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
162
	JavaCore.setOptions(options);
153
	JavaCore.setOptions(options);
163
154
164
	char[][] suggestions = NamingConventions.suggestFieldNames(
155
	String[] suggestions = NamingConventions.getVariableNames(
165
		this.project,
156
			NamingConventions.VK_INSTANCE_FIELD,
166
		"a.b.c".toCharArray(), //$NON-NLS-1$
157
			NamingConventions.BK_SIMPLE_TYPE_NAME,
167
		"OneName".toCharArray(), //$NON-NLS-1$
158
			"OneName", //$NON-NLS-1$
168
		0,
159
			this.project,
169
		0,
160
			0,
170
		CharOperation.NO_CHAR_CHAR);
161
			new String[]{},
162
			true);
171
163
172
	assumeEquals(
164
	assumeEquals(
173
		"preNamesuf\n" + //$NON-NLS-1$
165
		"preNamesuf\n" + //$NON-NLS-1$
Lines 186-198 Link Here
186
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
178
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
187
	JavaCore.setOptions(options);
179
	JavaCore.setOptions(options);
188
180
189
	char[][] suggestions = NamingConventions.suggestFieldNames(
181
	String[] suggestions = NamingConventions.getVariableNames(
190
		this.project,
182
			NamingConventions.VK_INSTANCE_FIELD,
191
		"a.b.c".toCharArray(), //$NON-NLS-1$
183
			NamingConventions.BK_SIMPLE_TYPE_NAME,
192
		"int".toCharArray(), //$NON-NLS-1$
184
			"int", //$NON-NLS-1$
193
		0,
185
			this.project,
194
		0,
186
			0,
195
		CharOperation.NO_CHAR_CHAR);
187
			new String[]{},
188
			true);
196
189
197
	assumeEquals(
190
	assumeEquals(
198
		"preIsuf\n" + //$NON-NLS-1$
191
		"preIsuf\n" + //$NON-NLS-1$
Lines 202-214 Link Here
202
		toString(suggestions));
195
		toString(suggestions));
203
}
196
}
204
public void testSuggestFieldName008() {
197
public void testSuggestFieldName008() {
205
	char[][] suggestions = NamingConventions.suggestFieldNames(
198
	String[] suggestions = NamingConventions.getVariableNames(
206
		this.project,
199
			NamingConventions.VK_INSTANCE_FIELD,
207
		"a.b.c".toCharArray(), //$NON-NLS-1$
200
			NamingConventions.BK_SIMPLE_TYPE_NAME,
208
		"OneName".toCharArray(), //$NON-NLS-1$
201
			"OneName", //$NON-NLS-1$
209
		0,
202
			this.project,
210
		0,
203
			0,
211
		new char[][]{"name".toCharArray()}); //$NON-NLS-1$
204
			new String[]{"name"}, //$NON-NLS-1$
205
			true);
212
206
213
	assumeEquals(
207
	assumeEquals(
214
		"name2\n" + //$NON-NLS-1$
208
		"name2\n" + //$NON-NLS-1$
Lines 221-234 Link Here
221
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
215
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
222
	JavaCore.setOptions(options);
216
	JavaCore.setOptions(options);
223
217
224
	char[][] suggestions = NamingConventions.suggestFieldNames(
218
	String[] suggestions = NamingConventions.getVariableNames(
225
		this.project,
219
			NamingConventions.VK_INSTANCE_FIELD,
226
		"a.b.c".toCharArray(), //$NON-NLS-1$
220
			NamingConventions.BK_SIMPLE_TYPE_NAME,
227
		"OneName".toCharArray(), //$NON-NLS-1$
221
			"OneName", //$NON-NLS-1$
228
		0,
222
			this.project,
229
		0,
223
			0,
230
		new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$
224
			new String[]{"preNamesuf"}, //$NON-NLS-1$
231
225
			true);
226
	
232
	assumeEquals(
227
	assumeEquals(
233
		"preName2suf\n" + //$NON-NLS-1$
228
		"preName2suf\n" + //$NON-NLS-1$
234
		"preOneNamesuf\n" + //$NON-NLS-1$
229
		"preOneNamesuf\n" + //$NON-NLS-1$
Lines 245-258 Link Here
245
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
240
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
246
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
241
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
247
	JavaCore.setOptions(options);
242
	JavaCore.setOptions(options);
248
243
	
249
	char[][] suggestions = NamingConventions.suggestFieldNames(
244
	String[] suggestions = NamingConventions.getVariableNames(
250
		this.project,
245
			NamingConventions.VK_INSTANCE_FIELD,
251
		"a.b.c".toCharArray(), //$NON-NLS-1$
246
			NamingConventions.BK_SIMPLE_TYPE_NAME,
252
		"OneName".toCharArray(), //$NON-NLS-1$
247
			"OneName", //$NON-NLS-1$
253
		1,
248
			this.project,
254
		0,
249
			1,
255
		new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$
250
			new String[]{"preNamesuf"}, //$NON-NLS-1$
251
			true);
256
252
257
	assumeEquals(
253
	assumeEquals(
258
		"preNamessuf\n" + //$NON-NLS-1$
254
		"preNamessuf\n" + //$NON-NLS-1$
Lines 266-291 Link Here
266
		toString(suggestions));
262
		toString(suggestions));
267
}
263
}
268
public void testSuggestFieldName011() {
264
public void testSuggestFieldName011() {
269
	char[][] suggestions = NamingConventions.suggestFieldNames(
265
	
270
		this.project,
266
	String[] suggestions = NamingConventions.getVariableNames(
271
		"a.b.c".toCharArray(), //$NON-NLS-1$
267
			NamingConventions.VK_INSTANCE_FIELD,
272
		"Factory".toCharArray(), //$NON-NLS-1$
268
			NamingConventions.BK_SIMPLE_TYPE_NAME,
273
		1,
269
			"Factory", //$NON-NLS-1$
274
		0,
270
			this.project,
275
		CharOperation.NO_CHAR_CHAR); //$NON-NLS-1$
271
			1,
272
			new String[]{},
273
			true);
276
274
277
	assumeEquals(
275
	assumeEquals(
278
		"factories", //$NON-NLS-1$
276
		"factories", //$NON-NLS-1$
279
		toString(suggestions));
277
		toString(suggestions));
280
}
278
}
281
public void testSuggestFieldName012() {
279
public void testSuggestFieldName012() {
282
	String[] suggestions = NamingConventions.suggestFieldNames(
280
	String[] suggestions = NamingConventions.getVariableNames(
283
		this.project,
281
			NamingConventions.VK_INSTANCE_FIELD,
284
		"a.b.c", //$NON-NLS-1$
282
			NamingConventions.BK_SIMPLE_TYPE_NAME,
285
		"FooBar", //$NON-NLS-1$
283
			"FooBar", //$NON-NLS-1$
286
		0,
284
			this.project,
287
		0,
285
			0,
288
		new String[]{"bar"}); //$NON-NLS-1$
286
			new String[]{"bar"}, //$NON-NLS-1$
287
			true);
289
288
290
	assumeEquals(
289
	assumeEquals(
291
		"bar2\n" + //$NON-NLS-1$
290
		"bar2\n" + //$NON-NLS-1$
Lines 293-344 Link Here
293
		toString(suggestions));
292
		toString(suggestions));
294
}
293
}
295
public void testSuggestFieldName013() {
294
public void testSuggestFieldName013() {
296
	char[][] suggestions = NamingConventions.suggestFieldNames(
295
	String[] suggestions = NamingConventions.getVariableNames(
297
		this.project,
296
			NamingConventions.VK_INSTANCE_FIELD,
298
		"java.lang".toCharArray(), //$NON-NLS-1$
297
			NamingConventions.BK_SIMPLE_TYPE_NAME,
299
		"Class".toCharArray(), //$NON-NLS-1$
298
			"Class", //$NON-NLS-1$
300
		0,
299
			this.project,
301
		0,
300
			0,
302
		CharOperation.NO_CHAR_CHAR);
301
			new String[]{},
302
			true);
303
303
304
	assumeEquals(
304
	assumeEquals(
305
		"class1",//$NON-NLS-1$
305
		"class1",//$NON-NLS-1$
306
		toString(suggestions));
306
		toString(suggestions));
307
}
307
}
308
public void testSuggestFieldName014() {
308
public void testSuggestFieldName014() {
309
	char[][] suggestions = NamingConventions.suggestFieldNames(
309
	String[] suggestions = NamingConventions.getVariableNames(
310
		this.project,
310
			NamingConventions.VK_INSTANCE_FIELD,
311
		"java.lang".toCharArray(), //$NON-NLS-1$
311
			NamingConventions.BK_SIMPLE_TYPE_NAME,
312
		"Class".toCharArray(), //$NON-NLS-1$
312
			"Class", //$NON-NLS-1$
313
		0,
313
			this.project,
314
		0,
314
			0,
315
		new char[][]{"class1".toCharArray()}); //$NON-NLS-1$
315
			new String[]{"class1"}, //$NON-NLS-1$
316
			true);
316
317
317
	assumeEquals(
318
	assumeEquals(
318
		"class2",//$NON-NLS-1$
319
		"class2",//$NON-NLS-1$
319
		toString(suggestions));
320
		toString(suggestions));
320
}
321
}
321
public void testSuggestFieldName015() {
322
public void testSuggestFieldName015() {
322
	char[][] suggestions = NamingConventions.suggestFieldNames(
323
	String[] suggestions = NamingConventions.getVariableNames(
323
		this.project,
324
			NamingConventions.VK_INSTANCE_FIELD,
324
		"".toCharArray(), //$NON-NLS-1$
325
			NamingConventions.BK_SIMPLE_TYPE_NAME,
325
		"#".toCharArray(), //$NON-NLS-1$
326
			"#", //$NON-NLS-1$
326
		0,
327
			this.project,
327
		0,
328
			0,
328
		CharOperation.NO_CHAR_CHAR);
329
			new String[]{},
330
			true);
329
331
330
	assumeEquals(
332
	assumeEquals(
331
		"name",//$NON-NLS-1$
333
		"name",//$NON-NLS-1$
332
		toString(suggestions));
334
		toString(suggestions));
333
}
335
}
334
public void testSuggestFieldName016() {
336
public void testSuggestFieldName016() {
335
	char[][] suggestions = NamingConventions.suggestFieldNames(
337
	String[] suggestions = NamingConventions.getVariableNames(
336
		this.project,
338
			NamingConventions.VK_INSTANCE_FIELD,
337
		"".toCharArray(), //$NON-NLS-1$
339
			NamingConventions.BK_SIMPLE_TYPE_NAME,
338
		"#".toCharArray(), //$NON-NLS-1$
340
			"#", //$NON-NLS-1$
339
		0,
341
			this.project,
340
		0,
342
			0,
341
		new char[][]{"name".toCharArray()}); //$NON-NLS-1$
343
			new String[]{"name"}, //$NON-NLS-1$
344
			true);
342
345
343
	assumeEquals(
346
	assumeEquals(
344
		"name2",//$NON-NLS-1$
347
		"name2",//$NON-NLS-1$
Lines 348-360 Link Here
348
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
351
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
349
 */
352
 */
350
public void testSuggestFieldName017() {
353
public void testSuggestFieldName017() {
351
	char[][] suggestions = NamingConventions.suggestFieldNames(
354
	String[] suggestions = NamingConventions.getVariableNames(
352
		this.project,
355
			NamingConventions.VK_INSTANCE_FIELD,
353
		"".toCharArray(), //$NON-NLS-1$
356
			NamingConventions.BK_SIMPLE_TYPE_NAME,
354
		"names".toCharArray(), //$NON-NLS-1$
357
			"names", //$NON-NLS-1$
355
		0,
358
			this.project,
356
		0,
359
			0,
357
		new char[][]{});
360
			new String[]{},
361
			true);
358
362
359
	assumeEquals(
363
	assumeEquals(
360
		"names",//$NON-NLS-1$
364
		"names",//$NON-NLS-1$
Lines 364-376 Link Here
364
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
368
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
365
 */
369
 */
366
public void testSuggestFieldName018() {
370
public void testSuggestFieldName018() {
367
	char[][] suggestions = NamingConventions.suggestFieldNames(
371
	String[] suggestions = NamingConventions.getVariableNames(
368
		this.project,
372
			NamingConventions.VK_INSTANCE_FIELD,
369
		"".toCharArray(), //$NON-NLS-1$
373
			NamingConventions.BK_SIMPLE_TYPE_NAME,
370
		"names".toCharArray(), //$NON-NLS-1$
374
			"names", //$NON-NLS-1$
371
		1,
375
			this.project,
372
		0,
376
			1,
373
		new char[][]{});
377
			new String[]{},
378
			true);
374
379
375
	assumeEquals(
380
	assumeEquals(
376
		"names",//$NON-NLS-1$
381
		"names",//$NON-NLS-1$
Lines 380-392 Link Here
380
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
385
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
381
 */
386
 */
382
public void testSuggestFieldName019() {
387
public void testSuggestFieldName019() {
383
	char[][] suggestions = NamingConventions.suggestFieldNames(
388
	String[] suggestions = NamingConventions.getVariableNames(
384
		this.project,
389
			NamingConventions.VK_INSTANCE_FIELD,
385
		"".toCharArray(), //$NON-NLS-1$
390
			NamingConventions.BK_SIMPLE_TYPE_NAME,
386
		"MyClass".toCharArray(), //$NON-NLS-1$
391
			"MyClass", //$NON-NLS-1$
387
		0,
392
			this.project,
388
		0,
393
			0,
389
		new char[][]{});
394
			new String[]{},
395
			true);
390
396
391
	assumeEquals(
397
	assumeEquals(
392
		"class1\n" + //$NON-NLS-1$
398
		"class1\n" + //$NON-NLS-1$
Lines 397-429 Link Here
397
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
403
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356
398
 */
404
 */
399
public void testSuggestFieldName020() {
405
public void testSuggestFieldName020() {
400
	char[][] suggestions = NamingConventions.suggestFieldNames(
406
	String[] suggestions = NamingConventions.getVariableNames(
401
		this.project,
407
			NamingConventions.VK_INSTANCE_FIELD,
402
		"".toCharArray(), //$NON-NLS-1$
408
			NamingConventions.BK_SIMPLE_TYPE_NAME,
403
		"MyClass".toCharArray(), //$NON-NLS-1$
409
			"MyClass", //$NON-NLS-1$
404
		1,
410
			this.project,
405
		0,
411
			1,
406
		new char[][]{});
412
			new String[]{},
413
			true);
407
414
408
	assumeEquals(
415
	assumeEquals(
409
		"classes\n" + //$NON-NLS-1$
416
		"classes\n" + //$NON-NLS-1$
410
		"myClasses", //$NON-NLS-1$
417
		"myClasses", //$NON-NLS-1$
411
		toString(suggestions));
418
		toString(suggestions));
412
}
419
}
413
public void testRemovePrefixAndSuffixForFieldName001() {
420
/*
421
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
422
 */
423
public void testSuggestFieldName021() {
424
	String[] suggestions = NamingConventions.getVariableNames(
425
			NamingConventions.VK_CONSTANT_FIELD,
426
			NamingConventions.BK_SIMPLE_TYPE_NAME,
427
			"MyType", //$NON-NLS-1$
428
			this.project,
429
			0,
430
			new String[]{},
431
			true);
432
433
	assumeEquals(
434
		"TYPE\n" + //$NON-NLS-1$
435
		"MY_TYPE", //$NON-NLS-1$
436
		toString(suggestions));
437
}
438
/*
439
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
440
 */
441
public void testSuggestFieldName022() {
442
	Hashtable options = JavaCore.getOptions();
443
	options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
444
	options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
445
	JavaCore.setOptions(options);
446
	
447
	String[] suggestions = NamingConventions.getVariableNames(
448
			NamingConventions.VK_CONSTANT_FIELD,
449
			NamingConventions.BK_SIMPLE_TYPE_NAME,
450
			"MyType", //$NON-NLS-1$
451
			this.project,
452
			0,
453
			new String[]{},
454
			true);
455
456
	assumeEquals(
457
		"preTYPEsuf\n" + //$NON-NLS-1$
458
		"preMY_TYPEsuf\n" + //$NON-NLS-1$
459
		"preTYPE\n" + //$NON-NLS-1$
460
		"preMY_TYPE\n" + //$NON-NLS-1$
461
		"TYPEsuf\n" + //$NON-NLS-1$
462
		"MY_TYPEsuf\n" + //$NON-NLS-1$
463
		"TYPE\n" + //$NON-NLS-1$
464
		"MY_TYPE", //$NON-NLS-1$
465
		toString(suggestions));
466
}
467
/*
468
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
469
 */
470
public void testSuggestFieldName023() {
471
	String[] suggestions = NamingConventions.getVariableNames(
472
			NamingConventions.VK_INSTANCE_FIELD,
473
			NamingConventions.BK_SIMPLE_NAME,
474
			"oneName", //$NON-NLS-1$
475
			this.project,
476
			0,
477
			new String[]{},
478
			true);
479
480
	assumeEquals(
481
		"oneName", //$NON-NLS-1$
482
		toString(suggestions));
483
}
484
/*
485
 * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111
486
 */
487
public void testSuggestFieldName024() {
414
	Hashtable options = JavaCore.getOptions();
488
	Hashtable options = JavaCore.getOptions();
415
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
489
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
416
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
490
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
417
	JavaCore.setOptions(options);
491
	JavaCore.setOptions(options);
492
	
493
	String[] suggestions = NamingConventions.getVariableNames(
494
			NamingConventions.VK_INSTANCE_FIELD,
495
			NamingConventions.BK_SIMPLE_NAME,
496
			"oneName", //$NON-NLS-1$
497
			this.project,
498
			0,
499
			new String[]{},
500
			true);
418
501
419
	char[] name = NamingConventions.removePrefixAndSuffixForFieldName(
502
	assumeEquals(
420
		this.project,
503
		"preOneNamesuf\n" + //$NON-NLS-1$
421
		"preOneNamesuf".toCharArray(), //$NON-NLS-1$
504
		"preOneName\n" + //$NON-NLS-1$
422
		0);
505
		"oneNamesuf\n" + //$NON-NLS-1$
506
		"oneName", //$NON-NLS-1$
507
		toString(suggestions));
508
}
509
public void testRemovePrefixAndSuffixForFieldName001() {
510
	Hashtable options = JavaCore.getOptions();
511
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$
512
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$
513
	JavaCore.setOptions(options);
423
514
515
	String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_INSTANCE_FIELD, this.project, "preOneNamesuf"); //$NON-NLS-1$
424
	assumeEquals(
516
	assumeEquals(
425
		"oneName", //$NON-NLS-1$
517
		"oneName", //$NON-NLS-1$
426
		new String(name));
518
		name);
427
}
519
}
428
public void testRemovePrefixAndSuffixForFieldName002() {
520
public void testRemovePrefixAndSuffixForFieldName002() {
429
	Hashtable options = JavaCore.getOptions();
521
	Hashtable options = JavaCore.getOptions();
Lines 431-444 Link Here
431
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"uf, suf"); //$NON-NLS-1$
523
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"uf, suf"); //$NON-NLS-1$
432
	JavaCore.setOptions(options);
524
	JavaCore.setOptions(options);
433
525
434
	char[] name = NamingConventions.removePrefixAndSuffixForFieldName(
526
	String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_STATIC_FIELD, this.project, "preOneNamesuf"); //$NON-NLS-1$
435
		this.project,
436
		"preOneNamesuf".toCharArray(), //$NON-NLS-1$
437
		Flags.AccStatic);
438
439
	assumeEquals(
527
	assumeEquals(
440
		"preOneNamesuf", //$NON-NLS-1$
528
		"preOneNamesuf", //$NON-NLS-1$
441
		new String(name));
529
		name);
442
}
530
}
443
public void testRemovePrefixAndSuffixForFieldName003() {
531
public void testRemovePrefixAndSuffixForFieldName003() {
444
	Hashtable options = JavaCore.getOptions();
532
	Hashtable options = JavaCore.getOptions();
Lines 446-459 Link Here
446
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"uf, suf"); //$NON-NLS-1$
534
	options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"uf, suf"); //$NON-NLS-1$
447
	JavaCore.setOptions(options);
535
	JavaCore.setOptions(options);
448
536
449
	char[] name = NamingConventions.removePrefixAndSuffixForFieldName(
537
	String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_INSTANCE_FIELD, this.project, "preOneNamesuf"); //$NON-NLS-1$
450
		this.project,
451
		"preOneNamesuf".toCharArray(), //$NON-NLS-1$
452
		0);
453
454
	assumeEquals(
538
	assumeEquals(
455
		"oneName", //$NON-NLS-1$
539
		"oneName", //$NON-NLS-1$
456
		new String(name));
540
		name);
457
}
541
}
458
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=114086
542
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=114086
459
public void testRemovePrefixAndSuffixForFieldName004() {
543
public void testRemovePrefixAndSuffixForFieldName004() {
Lines 461-474 Link Here
461
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre,"); //$NON-NLS-1$
545
	options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre,"); //$NON-NLS-1$
462
	JavaCore.setOptions(options);
546
	JavaCore.setOptions(options);
463
547
464
	char[] name = NamingConventions.removePrefixAndSuffixForFieldName(
548
	String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_INSTANCE_FIELD, this.project, "preOneName"); //$NON-NLS-1$
465
		this.project,
466
		"preOneName".toCharArray(), //$NON-NLS-1$
467
		0);
468
469
	assumeEquals(
549
	assumeEquals(
470
		"oneName", //$NON-NLS-1$
550
		"oneName", //$NON-NLS-1$
471
		new String(name));
551
		name);
472
}
552
}
473
public void testRemovePrefixAndSuffixForLocalName001() {
553
public void testRemovePrefixAndSuffixForLocalName001() {
474
	Hashtable options = JavaCore.getOptions();
554
	Hashtable options = JavaCore.getOptions();
Lines 476-489 Link Here
476
	options.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES,"uf, suf"); //$NON-NLS-1$
556
	options.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES,"uf, suf"); //$NON-NLS-1$
477
	JavaCore.setOptions(options);
557
	JavaCore.setOptions(options);
478
558
479
	char[] name = NamingConventions.removePrefixAndSuffixForLocalVariableName(
559
	String name = NamingConventions.removeVariablePrefixAndSuffix(NamingConventions.VK_LOCAL, this.project, "preOneNamesuf"); //$NON-NLS-1$
480
		this.project,
481
		"preOneNamesuf".toCharArray() //$NON-NLS-1$
482
		);
483
484
	assumeEquals(
560
	assumeEquals(
485
		"oneName", //$NON-NLS-1$
561
		"oneName", //$NON-NLS-1$
486
		new String(name));
562
		name);
487
}
563
}
488
public void testSuggestGetterName001() {
564
public void testSuggestGetterName001() {
489
	char[] suggestion = NamingConventions.suggestGetterName(
565
	char[] suggestion = NamingConventions.suggestGetterName(
Lines 633-644 Link Here
633
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
709
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
634
		this.project.setOptions(newOptions);
710
		this.project.setOptions(newOptions);
635
711
636
		String[] suggestions = NamingConventions.suggestLocalVariableNames(
712
		String[] suggestions = NamingConventions.getVariableNames(
713
			NamingConventions.VK_LOCAL,
714
			NamingConventions.BK_SIMPLE_TYPE_NAME,
715
			"Enum",
637
			this.project,
716
			this.project,
638
			"",//$NON-NLS-1$
639
			"Enum",//$NON-NLS-1$
640
			0,
717
			0,
641
			new String[]{"o"});
718
			new String[]{"o"}, //$NON-NLS-1$
719
			true);
642
720
643
		assumeEquals(
721
		assumeEquals(
644
			"enum1", //$NON-NLS-1$
722
			"enum1", //$NON-NLS-1$
Lines 659-670 Link Here
659
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
737
		newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
660
		this.project.setOptions(newOptions);
738
		this.project.setOptions(newOptions);
661
739
662
		String[] suggestions = NamingConventions.suggestLocalVariableNames(
740
		String[] suggestions = NamingConventions.getVariableNames(
741
			NamingConventions.VK_LOCAL,
742
			NamingConventions.BK_SIMPLE_TYPE_NAME,
743
			"Enums",
663
			this.project,
744
			this.project,
664
			"",//$NON-NLS-1$
665
			"Enums",//$NON-NLS-1$
666
			0,
745
			0,
667
			new String[]{"o"});
746
			new String[]{"o"}, //$NON-NLS-1$
747
			true);
668
748
669
		assumeEquals(
749
		assumeEquals(
670
			"enums", //$NON-NLS-1$
750
			"enums", //$NON-NLS-1$
(-)model/org/eclipse/jdt/internal/core/InternalNamingConventions.java (-226 / +307 lines)
Lines 12-18 Link Here
12
12
13
import java.util.Map;
13
import java.util.Map;
14
14
15
import org.eclipse.jdt.core.Flags;
16
import org.eclipse.jdt.core.IJavaProject;
15
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.InvalidInputException;
17
import org.eclipse.jdt.core.compiler.InvalidInputException;
Lines 37-263 Link Here
37
				null/*taskPriorities*/,
36
				null/*taskPriorities*/,
38
				true/*taskCaseSensitive*/);
37
				true/*taskCaseSensitive*/);
39
	}
38
	}
40
	public static void suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) {
41
		Map options = javaProject.getOptions(true);
42
		CompilerOptions compilerOptions = new CompilerOptions(options);
43
		AssistOptions assistOptions = new AssistOptions(options);
44
45
		suggestNames(
46
			packageName,
47
			qualifiedTypeName,
48
			dim,
49
			internalPrefix,
50
			assistOptions.argumentPrefixes,
51
			assistOptions.argumentSuffixes,
52
			excludedNames,
53
			getNameScanner(compilerOptions),
54
			requestor);
55
	}
56
	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);
58
59
		Map options = javaProject.getOptions(true);
60
		CompilerOptions compilerOptions = new CompilerOptions(options);
61
		AssistOptions assistOptions = new AssistOptions(options);
62
63
		suggestNames(
64
			packageName,
65
			qualifiedTypeName,
66
			dim,
67
			internalPrefix,
68
			isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes,
69
			isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes,
70
			excludedNames,
71
			getNameScanner(compilerOptions),
72
			requestor);
73
	}
74
	public static void suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) {
75
		Map options = javaProject.getOptions(true);
76
		CompilerOptions compilerOptions = new CompilerOptions(options);
77
		AssistOptions assistOptions = new AssistOptions(options);
78
79
		suggestNames(
80
			packageName,
81
			qualifiedTypeName,
82
			dim,
83
			internalPrefix,
84
			assistOptions.localPrefixes,
85
			assistOptions.localSuffixes,
86
			excludedNames,
87
			getNameScanner(compilerOptions),
88
			requestor);
89
	}
90
91
	private static void suggestNames(
92
		char[] packageName,
93
		char[] qualifiedTypeName,
94
		int dim,
95
		char[] internalPrefix,
96
		char[][] prefixes,
97
		char[][] suffixes,
98
		char[][] excludedNames,
99
		Scanner nameScanner,
100
		INamingRequestor requestor){
101
102
		if(qualifiedTypeName == null || qualifiedTypeName.length == 0)
103
			return;
104
105
		if(internalPrefix == null) {
106
			internalPrefix = CharOperation.NO_CHAR;
107
		} else {
108
			internalPrefix = removePrefix(internalPrefix, prefixes);
109
		}
110
111
		char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.');
112
113
		if(prefixes == null || prefixes.length == 0) {
114
			prefixes = new char[1][0];
115
		} else {
116
			int length = prefixes.length;
117
			System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length);
118
			prefixes[length] = CharOperation.NO_CHAR;
119
		}
120
121
		if(suffixes == null || suffixes.length == 0) {
122
			suffixes = new char[1][0];
123
		} else {
124
			int length = suffixes.length;
125
			System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length);
126
			suffixes[length] = CharOperation.NO_CHAR;
127
		}
128
129
		char[][] tempNames = null;
130
131
		// compute variable name for base type
132
		try{
133
			nameScanner.setSource(typeName);
134
			switch (nameScanner.getNextToken()) {
135
				case TerminalTokens.TokenNameint :
136
				case TerminalTokens.TokenNamebyte :
137
				case TerminalTokens.TokenNameshort :
138
				case TerminalTokens.TokenNamechar :
139
				case TerminalTokens.TokenNamelong :
140
				case TerminalTokens.TokenNamefloat :
141
				case TerminalTokens.TokenNamedouble :
142
				case TerminalTokens.TokenNameboolean :
143
144
					if (internalPrefix != null && internalPrefix.length > 0) return;
145
146
					char[] name = computeBaseTypeNames(typeName[0], excludedNames);
147
					if(name != null) {
148
						tempNames =  new char[][]{name};
149
					}
150
					break;
151
			}
152
		} catch(InvalidInputException e){
153
			// ignore
154
		}
155
156
		// compute variable name for non base type
157
		if(tempNames == null) {
158
			tempNames = computeNames(typeName);
159
		}
160
161
		boolean acceptDefaultName = true;
162
		SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray();
163
164
		next : for (int i = 0; i < tempNames.length; i++) {
165
			char[] tempName = tempNames[i];
166
			if(dim > 0) {
167
				int length = tempName.length;
168
				if (tempName[length-1] == 's'){
169
					if(tempName.length > 1 && tempName[length-2] == 's') {
170
						System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
171
						tempName[length] = 'e';
172
						tempName[length+1] = 's';
173
					}
174
				} else if(tempName[length-1] == 'y') {
175
					System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
176
					tempName[length-1] = 'i';
177
					tempName[length] = 'e';
178
					tempName[length+1] = 's';
179
				} else {
180
					System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
181
					tempName[length] = 's';
182
				}
183
			}
184
185
			char[] unprefixedName = tempName;
186
			unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]);
187
			for (int j = 0; j <= internalPrefix.length; j++) {
188
				if(j == internalPrefix.length ||
189
						CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
190
					tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, j), unprefixedName);
191
					if(j == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
192
					for (int k = 0; k < prefixes.length; k++) {
193
						if(prefixes[k].length > 0
194
							&& ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) {
195
							tempName[0] = ScannerHelper.toUpperCase(tempName[0]);
196
						} else {
197
							tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
198
						}
199
						char[] prefixName = CharOperation.concat(prefixes[k], tempName);
200
						for (int l = 0; l < suffixes.length; l++) {
201
							char[] suffixName = CharOperation.concat(prefixName, suffixes[l]);
202
							suffixName =
203
								excludeNames(
204
									suffixName,
205
									prefixName,
206
									suffixes[l],
207
									excludedNames);
208
							try{
209
								nameScanner.setSource(suffixName);
210
								switch (nameScanner.getNextToken()) {
211
									case TerminalTokens.TokenNameIdentifier :
212
										int token = nameScanner.getNextToken();
213
										if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
214
											if (!foundNames.includes(suffixName)) {
215
												acceptName(suffixName, prefixes[k], suffixes[l],  k == 0, l == 0, internalPrefix.length - j, requestor);
216
												foundNames.add(suffixName);
217
												acceptDefaultName = false;
218
											}
219
										}
220
										break;
221
									default:
222
										suffixName = CharOperation.concat(
223
											prefixName,
224
											String.valueOf(1).toCharArray(),
225
											suffixes[l]
226
										);
227
										suffixName =
228
											excludeNames(
229
												suffixName,
230
												prefixName,
231
												suffixes[l],
232
												excludedNames);
233
										nameScanner.setSource(suffixName);
234
										switch (nameScanner.getNextToken()) {
235
											case TerminalTokens.TokenNameIdentifier :
236
												token = nameScanner.getNextToken();
237
												if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
238
													if (!foundNames.includes(suffixName)) {
239
														acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - j, requestor);
240
														foundNames.add(suffixName);
241
														acceptDefaultName = false;
242
													}
243
												}
244
										}
245
								}
246
							} catch(InvalidInputException e){
247
								// ignore
248
							}
249
						}
250
					}
251
					continue next;
252
				}
253
			}
254
		}
255
		// if no names were found
256
		if(acceptDefaultName) {
257
			char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excludedNames);
258
			requestor.acceptNameWithoutPrefixAndSuffix(name, 0);
259
		}
260
	}
261
39
262
	private static void acceptName(
40
	private static void acceptName(
263
		char[] name,
41
		char[] name,
Lines 278-283 Link Here
278
		}
56
		}
279
	}
57
	}
280
58
59
	private static char[][] computeBaseTypeNames(char[] typeName, boolean isConstantField, char[][] excludedNames){
60
		char[] name = computeBaseTypeNames(typeName[0], excludedNames);
61
		if(name != null) {
62
			return new char[][]{name};
63
		} else {
64
			// compute variable name like from non base type
65
			return  computeNonBaseTypeNames(typeName, isConstantField);
66
		}
67
	}
281
	private static char[] computeBaseTypeNames(char firstName, char[][] excludedNames){
68
	private static char[] computeBaseTypeNames(char firstName, char[][] excludedNames){
282
		char[] name = new char[]{firstName};
69
		char[] name = new char[]{firstName};
283
70
Lines 294-301 Link Here
294
81
295
		return name;
82
		return name;
296
	}
83
	}
297
84
	
298
	private static char[][] computeNames(char[] sourceName){
85
	private static char[][] computeNonBaseTypeNames(char[] sourceName, boolean isConstantField){
299
		char[][] names = new char[5][];
86
		char[][] names = new char[5][];
300
		int nameCount = 0;
87
		int nameCount = 0;
301
		boolean previousIsUpperCase = false;
88
		boolean previousIsUpperCase = false;
Lines 309-315 Link Here
309
					if(nameCount == names.length) {
96
					if(nameCount == names.length) {
310
						System.arraycopy(names, 0, names = new char[nameCount * 2][], 0, nameCount);
97
						System.arraycopy(names, 0, names = new char[nameCount * 2][], 0, nameCount);
311
					}
98
					}
312
					name[0] = ScannerHelper.toLowerCase(name[0]);
99
					if (isConstantField) {
100
						name = convertToConstantName(name);
101
					} else {
102
						name[0] = ScannerHelper.toLowerCase(name[0]);
103
					}
313
					names[nameCount++] = name;
104
					names[nameCount++] = name;
314
				}
105
				}
315
			}
106
			}
Lines 317-327 Link Here
317
			previousIsLetter = isLetter;
108
			previousIsLetter = isLetter;
318
		}
109
		}
319
		if(nameCount == 0){
110
		if(nameCount == 0){
320
			names[nameCount++] = CharOperation.toLowerCase(sourceName);
111
			if (isConstantField) {
112
				names[nameCount++] = convertToConstantName(sourceName);
113
			} else {
114
				names[nameCount++] = CharOperation.toLowerCase(sourceName);
115
			}
321
		}
116
		}
322
		System.arraycopy(names, 0, names = new char[nameCount][], 0, nameCount);
117
		System.arraycopy(names, 0, names = new char[nameCount][], 0, nameCount);
323
		return names;
118
		return names;
324
	}
119
	}
120
	
121
	private static char[] convertToConstantName(char[] name) {
122
		int length = name.length;
123
		char[] constantName = new char[length * 2];
124
		int constantNamePtr = 0;
125
		boolean wasUnderscore = true;
126
		for (int i = 0; i < length; i++) {
127
			if (ScannerHelper.isUpperCase(name[i])) {
128
				if (!wasUnderscore) constantName[constantNamePtr++] = '_';
129
				constantName[constantNamePtr++] = name[i];
130
			} else {
131
				constantName[constantNamePtr++] = ScannerHelper.toUpperCase(name[i]);
132
				wasUnderscore = name[i] == '_';
133
			}
134
		}
135
		System.arraycopy(constantName, 0, constantName = new char[constantNamePtr], 0, constantNamePtr);
136
		return constantName;
137
	}
325
138
326
	private static char[] excludeNames(
139
	private static char[] excludeNames(
327
		char[] suffixName,
140
		char[] suffixName,
Lines 430-433 Link Here
430
					return false;
243
					return false;
431
			return true;
244
			return true;
432
	}
245
	}
246
	
247
	public static final int VK_STATIC_FIELD = 1;
248
	public static final int VK_INSTANCE_FIELD = 2;
249
	public static final int VK_CONSTANT_FIELD = 3;
250
	public static final int VK_PARAMETER = 4;
251
	public static final int VK_LOCAL = 5;
252
	
253
	public static final int BK_SIMPLE_NAME = 1;
254
	public static final int BK_SIMPLE_TYPE_NAME = 2;
255
256
	public static void suggestVariableNames(
257
			int variableKind,
258
			int baseNameKind,
259
			char[] baseName,
260
			IJavaProject javaProject,
261
			int dim,
262
			char[] internalPrefix,
263
			char[][] excluded,
264
			boolean evaluateDefault,
265
			INamingRequestor requestor) {
266
		
267
		if(baseName == null || baseName.length == 0)
268
			return;
269
		
270
		Map options = javaProject.getOptions(true);
271
		CompilerOptions compilerOptions = new CompilerOptions(options);
272
		AssistOptions assistOptions = new AssistOptions(options);
273
		
274
		boolean isConstantField = false;
275
		
276
		char[][] prefixes = null;
277
		char[][] suffixes = null;
278
		switch (variableKind) {
279
			case VK_INSTANCE_FIELD:
280
				prefixes = assistOptions.fieldPrefixes;
281
				suffixes = assistOptions.fieldSuffixes;
282
				break;
283
			case VK_STATIC_FIELD:
284
				prefixes = assistOptions.staticFieldPrefixes;
285
				suffixes = assistOptions.staticFieldSuffixes;
286
				break;
287
			case VK_CONSTANT_FIELD:
288
				isConstantField = true;
289
				prefixes = assistOptions.staticFinalFieldPrefixes;
290
				suffixes = assistOptions.staticFinalFieldSuffixes;
291
				break;
292
			case VK_LOCAL:
293
				prefixes = assistOptions.localPrefixes;
294
				suffixes = assistOptions.localSuffixes;
295
				break;
296
			case VK_PARAMETER:
297
				prefixes = assistOptions.argumentPrefixes;
298
				suffixes = assistOptions.argumentSuffixes;
299
				break;
300
		}
301
		
302
		if(prefixes == null || prefixes.length == 0) {
303
			prefixes = new char[1][0];
304
		} else {
305
			int length = prefixes.length;
306
			System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length);
307
			prefixes[length] = CharOperation.NO_CHAR;
308
		}
309
310
		if(suffixes == null || suffixes.length == 0) {
311
			suffixes = new char[1][0];
312
		} else {
313
			int length = suffixes.length;
314
			System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length);
315
			suffixes[length] = CharOperation.NO_CHAR;
316
		}
317
		
318
		if(internalPrefix == null) {
319
			internalPrefix = CharOperation.NO_CHAR;
320
		} else {
321
			internalPrefix = removePrefix(internalPrefix, prefixes);
322
		}
323
324
		char[][] tempNames = null;
325
		
326
		Scanner nameScanner = getNameScanner(compilerOptions);
327
		if (baseNameKind == BK_SIMPLE_TYPE_NAME) {
328
			boolean isBaseType = false;
329
			
330
			try{
331
				nameScanner.setSource(baseName);
332
				switch (nameScanner.getNextToken()) {
333
					case TerminalTokens.TokenNameint :
334
					case TerminalTokens.TokenNamebyte :
335
					case TerminalTokens.TokenNameshort :
336
					case TerminalTokens.TokenNamechar :
337
					case TerminalTokens.TokenNamelong :
338
					case TerminalTokens.TokenNamefloat :
339
					case TerminalTokens.TokenNamedouble :
340
					case TerminalTokens.TokenNameboolean :
341
						isBaseType = true;
342
						break;
343
				}
344
			} catch(InvalidInputException e){
345
				// ignore
346
			}
347
			if (isBaseType) {
348
				// compute variable name from base type
349
				if (internalPrefix.length > 0) return;
350
	
351
				tempNames = computeBaseTypeNames(baseName, isConstantField, excluded);
352
			} else {
353
				// compute variable name for non base type
354
				tempNames = computeNonBaseTypeNames(baseName, isConstantField);
355
			}
356
		} else {
357
			tempNames = new char[][]{baseName};
358
		}
359
360
		boolean acceptDefaultName = true;
361
		SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray();
362
363
		for (int i = 0; i < tempNames.length; i++) {
364
			char[] tempName = tempNames[i];
365
			
366
			// add English plural form is necessary
367
			if(dim > 0) {
368
				int length = tempName.length;
369
				
370
				if (isConstantField) {
371
					if (tempName[length-1] == 'S'){
372
						if(tempName.length > 1 && tempName[length-2] == 'S') {
373
							System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
374
							tempName[length] = 'E';
375
							tempName[length+1] = 'S';
376
						}
377
					} else if(tempName[length-1] == 'Y') {
378
						System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
379
						tempName[length-1] = 'I';
380
						tempName[length] = 'E';
381
						tempName[length+1] = 'S';
382
					} else {
383
						System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
384
						tempName[length] = 'S';
385
					}
386
				} else {
387
					if (tempName[length-1] == 's'){
388
						if(tempName.length > 1 && tempName[length-2] == 's') {
389
							System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
390
							tempName[length] = 'e';
391
							tempName[length+1] = 's';
392
						}
393
					} else if(tempName[length-1] == 'y') {
394
						System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
395
						tempName[length-1] = 'i';
396
						tempName[length] = 'e';
397
						tempName[length+1] = 's';
398
					} else {
399
						System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
400
						tempName[length] = 's';
401
					}
402
				}
403
			}
404
			
405
			char[] unprefixedName = tempName;
406
			
407
			int matchingIndex = -1;
408
			if (!isConstantField) {
409
				unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]);
410
				
411
				done : for (int j = 0; j <= internalPrefix.length; j++) {
412
					if(j == internalPrefix.length ||
413
							CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
414
						matchingIndex = j;
415
						break done;
416
					}
417
				}
418
			} else {
419
				done : for (int j = 0; j <= internalPrefix.length; j++) {
420
					if(j == internalPrefix.length) {
421
						matchingIndex = j;
422
						break done;
423
					} else if(CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
424
						if (j == 0 || internalPrefix[j - 1] == '_') {
425
							matchingIndex = j;
426
							break done;
427
						}
428
						
429
					}
430
				}
431
			}
432
433
			if(matchingIndex > -1) {
434
				if (!isConstantField) {
435
					tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, matchingIndex), unprefixedName);
436
					if(matchingIndex == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
437
				} else {
438
					if(matchingIndex != 0 && tempName[0] != '_' && internalPrefix[matchingIndex - 1] != '_') {
439
						tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName, '_');
440
					} else {
441
						tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName);
442
					}
443
				}
444
				
445
				for (int k = 0; k < prefixes.length; k++) {
446
					if (!isConstantField) {
447
						if(prefixes[k].length > 0
448
							&& ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) {
449
							tempName[0] = ScannerHelper.toUpperCase(tempName[0]);
450
						} else {
451
							tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
452
						}
453
					}
454
					char[] prefixName = CharOperation.concat(prefixes[k], tempName);
455
					for (int l = 0; l < suffixes.length; l++) {
456
						char[] suffixName = CharOperation.concat(prefixName, suffixes[l]);
457
						suffixName =
458
							excludeNames(
459
								suffixName,
460
								prefixName,
461
								suffixes[l],
462
								excluded);
463
						try{
464
							nameScanner.setSource(suffixName);
465
							switch (nameScanner.getNextToken()) {
466
								case TerminalTokens.TokenNameIdentifier :
467
									int token = nameScanner.getNextToken();
468
									if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
469
										if (!foundNames.includes(suffixName)) {
470
											acceptName(suffixName, prefixes[k], suffixes[l],  k == 0, l == 0, internalPrefix.length - matchingIndex, requestor);
471
											foundNames.add(suffixName);
472
											acceptDefaultName = false;
473
										}
474
									}
475
									break;
476
								default:
477
									suffixName = CharOperation.concat(
478
										prefixName,
479
										String.valueOf(1).toCharArray(),
480
										suffixes[l]
481
									);
482
									suffixName =
483
										excludeNames(
484
											suffixName,
485
											prefixName,
486
											suffixes[l],
487
											excluded);
488
									nameScanner.setSource(suffixName);
489
									switch (nameScanner.getNextToken()) {
490
										case TerminalTokens.TokenNameIdentifier :
491
											token = nameScanner.getNextToken();
492
											if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
493
												if (!foundNames.includes(suffixName)) {
494
													acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor);
495
													foundNames.add(suffixName);
496
													acceptDefaultName = false;
497
												}
498
											}
499
									}
500
							}
501
						} catch(InvalidInputException e){
502
							// ignore
503
						}
504
					}
505
				}
506
			}
507
		}
508
		// if no names were found
509
		if(evaluateDefault && acceptDefaultName) {
510
			char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excluded);
511
			requestor.acceptNameWithoutPrefixAndSuffix(name, 0);
512
		}
513
	}
433
}
514
}
(-)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 1979-1988 Link Here
1979
		defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
1979
		defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
1980
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
1980
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
1981
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
1981
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
1982
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$
1982
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
1983
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
1983
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
1984
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
1984
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1985
		defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1985
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1986
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1987
		defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$
1986
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
1988
		defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
1987
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
1989
		defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
1988
		defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
1990
		defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
(-)model/org/eclipse/jdt/core/JavaCore.java (+26 lines)
Lines 1799-1804 Link Here
1799
	 */
1799
	 */
1800
	public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
1800
	public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
1801
	/**
1801
	/**
1802
	 * Code assist option ID: Define the Prefixes for Static Final Field Name.
1803
	 * <p>When the prefixes is non empty, completion for static final field name will begin with
1804
	 *    one of the proposed prefixes.
1805
	 * <dl>
1806
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"</code></dd>
1807
	 * <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>
1808
	 * <dt>Default:</dt><dd><code>""</code></dd>
1809
	 * </dl>
1810
	 * @since 3.5
1811
	 * @category CodeAssistOptionID
1812
	 */
1813
	public static final String CODEASSIST_STATIC_FINAL_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldPrefixes"; //$NON-NLS-1$
1814
	/**
1802
	 * Code assist option ID: Define the Prefixes for Local Variable Name.
1815
	 * Code assist option ID: Define the Prefixes for Local Variable Name.
1803
	 * <p>When the prefixes is non empty, completion for local variable name will begin with
1816
	 * <p>When the prefixes is non empty, completion for local variable name will begin with
1804
	 *    one of the proposed prefixes.
1817
	 *    one of the proposed prefixes.
Lines 1851-1856 Link Here
1851
	 */
1864
	 */
1852
	public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
1865
	public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
1853
	/**
1866
	/**
1867
	 * Code assist option ID: Define the Suffixes for Static Final Field Name.
1868
	 * <p>When the suffixes is non empty, completion for static final field name will end with
1869
	 *    one of the proposed suffixes.
1870
	 * <dl>
1871
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"</code></dd>
1872
	 * <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>
1873
	 * <dt>Default:</dt><dd><code>""</code></dd>
1874
	 * </dl>
1875
	 * @since 3.5
1876
	 * @category CodeAssistOptionID
1877
	 */
1878
	public static final String CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldSuffixes"; //$NON-NLS-1$
1879
	/**
1854
	 * Code assist option ID: Define the Suffixes for Local Variable Name.
1880
	 * Code assist option ID: Define the Suffixes for Local Variable Name.
1855
	 * <p>When the suffixes is non empty, completion for local variable name will end with
1881
	 * <p>When the suffixes is non empty, completion for local variable name will end with
1856
	 *    one of the proposed suffixes.
1882
	 *    one of the proposed suffixes.
(-)model/org/eclipse/jdt/core/NamingConventions.java (-244 / +434 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-277 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() {
234
		// Not instantiable
235
	}
236
232
237
	private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) {
233
	public static final int VK_STATIC_FIELD = InternalNamingConventions.VK_STATIC_FIELD;
238
		// remove longer prefix
234
	public static final int VK_INSTANCE_FIELD = InternalNamingConventions.VK_INSTANCE_FIELD;
239
		char[] withoutPrefixName = name;
235
	public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_CONSTANT_FIELD;
240
		if (prefixes != null) {
236
	public static final int VK_PARAMETER = InternalNamingConventions.VK_PARAMETER;
241
			int bestLength = 0;
237
	public static final int VK_LOCAL = InternalNamingConventions.VK_LOCAL;
242
			for (int i= 0; i < prefixes.length; i++) {
238
	
243
				char[] prefix = prefixes[i];
239
	public static final int BK_SIMPLE_NAME = InternalNamingConventions.BK_SIMPLE_NAME;
244
				if (CharOperation.prefixEquals(prefix, name)) {
240
	public static final int BK_SIMPLE_TYPE_NAME = InternalNamingConventions.BK_SIMPLE_TYPE_NAME;
245
					int currLen = prefix.length;
246
					boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]);
247
					if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) {
248
						if (bestLength < currLen && name.length != currLen) {
249
							withoutPrefixName = CharOperation.subarray(name, currLen, name.length);
250
							bestLength = currLen;
251
						}
252
					}
253
				}
254
			}
255
		}
256
241
257
		// remove longer suffix
242
	private static String[] convertCharsToString(char[][] c) {
258
		char[] withoutSuffixName = withoutPrefixName;
243
		int length = c == null ? 0 : c.length;
259
		if(suffixes != null) {
244
		String[] s = new String[length];
260
			int bestLength = 0;
245
		for (int i = 0; i < length; i++) {
261
			for (int i = 0; i < suffixes.length; i++) {
246
			s[i] = String.valueOf(c[i]);
262
				char[] suffix = suffixes[i];
247
		}
263
				if(CharOperation.endsWith(withoutPrefixName, suffix)) {
248
		return s;
264
					int currLen = suffix.length;
249
	}
265
					if(bestLength < currLen && withoutPrefixName.length != currLen) {
250
	private static char[][] convertStringToChars(String[] s) {
266
						withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen);
251
		int length = s == null ? 0 : s.length;
267
						bestLength = currLen;
252
		char[][] c = new char[length][];
268
					}
253
		for (int i = 0; i < length; i++) {
269
				}
254
			if(s[i] == null) {
255
				c[i] = CharOperation.NO_CHAR;
256
			} else {
257
				c[i] = s[i].toCharArray();
270
			}
258
			}
271
		}
259
		}
260
		return c;
261
	}
272
262
273
		withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]);
263
	/**
274
		return withoutSuffixName;
264
	 * Suggest names for a variable. The name is computed from a base name
265
	 * and possible prefixes or suffixes are added.
266
	 * <p>
267
	 * The variable can be a local variable, a parameter, an instance field, a static field or a constant field.
268
	 * Each type of variable is specified by a variable kind:
269
	 * <ul>
270
	 * <li>{@link #VK_PARAMETER} for parameter</li>
271
	 * <li>{@link #VK_LOCAL} for local variable</li>
272
	 * <li>{@link #VK_INSTANCE_FIELD} for instance field</li>
273
	 * <li>{@link #VK_STATIC_FIELD} for static field</li>
274
	 * <li>{@link #VK_CONSTANT_FIELD} for constant field</li>
275
	 * </ul>
276
	 * Some other kinds could be added in the future.
277
	 * </p>
278
	 * <p>
279
	 * The base name is used to compute the variable name.
280
	 * Some different kinds of base name are possible and each kind is associated to a different heuristic to compute variable names.
281
	 * The different kinds of base name are:
282
	 * <ul>
283
	 * <li>{@link #BK_SIMPLE_NAME}: If the prefix is <code>pre</code> and the suffix is <code>suf</code> then the proposed name is
284
	 * <code>preSimpleNamesuf</code>.</li>
285
	 * <li>{@link #BK_SIMPLE_TYPE_NAME}: If the type is <code>TypeName</code>, the prefix is <code>pre</code> and the suffix is <code>suf</code>
286
	 * then the proposed names are <code>preTypeNamesuf</code> and <code>preNamesuf</code>.</li>
287
	 * </ul>
288
	 * Some other kinds could be added in the future.
289
	 * </p>
290
	 * <p>
291
	 * Each variable kind is affected by the following JavaCore options:
292
	 * <ul>
293
	 * <li>{@link #VK_PARAMETER}: {@link JavaCore#CODEASSIST_ARGUMENT_PREFIXES} and {@link JavaCore#CODEASSIST_ARGUMENT_SUFFIXES}</li>
294
	 * <li>{@link #VK_LOCAL}: {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}</li>
295
	 * <li>{@link #VK_INSTANCE_FIELD}: {@link JavaCore#CODEASSIST_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_FIELD_SUFFIXES}</li>
296
	 * <li>{@link #VK_STATIC_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES}</li>
297
	 * <li>{@link #VK_CONSTANT_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES}</li>
298
	 * </ul>
299
	 * </p>
300
	 * <p>
301
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
302
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
303
	 * </p>
304
	 *
305
	 * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD},
306
	 * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}.
307
	 * @param baseNameKind specifies what type the base name is: {@link #BK_SIMPLE_NAME} or {@link #BK_SIMPLE_TYPE_NAME}
308
	 * @param baseName name used to compute the suggested names.
309
	 * @param javaProject project which contains the variable.
310
	 * @param dim variable dimension (0 if the field is not an array).
311
	 * @param excluded a list of names which cannot be suggested (already used names).
312
	 *         Can be <code>null</code> if there is no excluded names.
313
	 * @param evaluateDefault if set, the result is guaranteed to contain at least one result. If not, the result can be an empty array. 
314
	 * @return String[] an array of names.
315
	 * @see JavaCore#setOptions(java.util.Hashtable)
316
	 * @see JavaCore#getDefaultOptions()
317
	 */
318
	public static String[] getVariableNames(
319
			int variableKind,
320
			int baseNameKind,
321
			String baseName,
322
			IJavaProject javaProject,
323
			int dim,
324
			String[] excluded,
325
			boolean evaluateDefault) {
326
		
327
		NamingRequestor requestor = new NamingRequestor();
328
		InternalNamingConventions.suggestVariableNames(
329
			variableKind,
330
			baseNameKind,
331
			baseName.toCharArray(),
332
			javaProject,
333
			dim,
334
			null,
335
			convertStringToChars(excluded),
336
			evaluateDefault,
337
			requestor);
338
339
		return convertCharsToString(requestor.getResults());
275
	}
340
	}
276
341
277
	/**
342
	/**
Lines 296-308 Link Here
296
	 * @return char[] the name without prefix and suffix.
361
	 * @return char[] the name without prefix and suffix.
297
	 * @see JavaCore#setOptions(java.util.Hashtable)
362
	 * @see JavaCore#setOptions(java.util.Hashtable)
298
	 * @see JavaCore#getDefaultOptions()
363
	 * @see JavaCore#getDefaultOptions()
364
	 * 
365
	 * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_PARAMETER} as variable kind.
299
	 */
366
	 */
300
	public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) {
367
	public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) {
301
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
368
		return removeVariablePrefixAndSuffix(VK_PARAMETER, javaProject, argumentName);
302
		return	removePrefixAndSuffix(
303
			argumentName,
304
			assistOptions.argumentPrefixes,
305
			assistOptions.argumentSuffixes);
306
	}
369
	}
307
370
308
	/**
371
	/**
Lines 327-337 Link Here
327
	 * @return char[] the name without prefix and suffix.
390
	 * @return char[] the name without prefix and suffix.
328
	 * @see JavaCore#setOptions(java.util.Hashtable)
391
	 * @see JavaCore#setOptions(java.util.Hashtable)
329
	 * @see JavaCore#getDefaultOptions()
392
	 * @see JavaCore#getDefaultOptions()
393
	 * 
394
	 * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_PARAMETER} as variable kind.
330
	 */
395
	 */
331
	public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) {
396
	public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) {
332
		return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray()));
397
		return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray()));
333
	}
398
	}
334
335
	/**
399
	/**
336
	 * Remove prefix and suffix from a field name.
400
	 * Remove prefix and suffix from a field name.
337
	 * <p>
401
	 * <p>
Lines 358-371 Link Here
358
	 * @see Flags
422
	 * @see Flags
359
	 * @see JavaCore#setOptions(java.util.Hashtable)
423
	 * @see JavaCore#setOptions(java.util.Hashtable)
360
	 * @see JavaCore#getDefaultOptions()
424
	 * @see JavaCore#getDefaultOptions()
425
	 * 
426
	 * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead
427
	 * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind.
361
	 */
428
	 */
362
	public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) {
429
	public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) {
363
		boolean isStatic = Flags.isStatic(modifiers);
430
		boolean isStatic = Flags.isStatic(modifiers);
364
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
431
		return removeVariablePrefixAndSuffix(isStatic ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, javaProject, fieldName);
365
		return	removePrefixAndSuffix(
366
			fieldName,
367
			isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes,
368
			isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes);
369
	}
432
	}
370
433
371
	/**
434
	/**
Lines 394-403 Link Here
394
	 * @see Flags
457
	 * @see Flags
395
	 * @see JavaCore#setOptions(java.util.Hashtable)
458
	 * @see JavaCore#setOptions(java.util.Hashtable)
396
	 * @see JavaCore#getDefaultOptions()
459
	 * @see JavaCore#getDefaultOptions()
460
	 * 
461
	 * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead
462
	 * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind.
397
	 */
463
	 */
398
	public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) {
464
	public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) {
399
		return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers));
465
		return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers));
400
	}
466
	}
467
401
	/**
468
	/**
402
	 * Remove prefix and suffix from a local variable name.
469
	 * Remove prefix and suffix from a local variable name.
403
	 * <p>
470
	 * <p>
Lines 420-432 Link Here
420
	 * @return char[] the name without prefix and suffix.
487
	 * @return char[] the name without prefix and suffix.
421
	 * @see JavaCore#setOptions(java.util.Hashtable)
488
	 * @see JavaCore#setOptions(java.util.Hashtable)
422
	 * @see JavaCore#getDefaultOptions()
489
	 * @see JavaCore#getDefaultOptions()
490
	 * 
491
	 * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_LOCAL} as variable kind.
423
	 */
492
	 */
424
	public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) {
493
	public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) {
425
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
494
		return removeVariablePrefixAndSuffix(VK_LOCAL, javaProject, localName);
426
		return	removePrefixAndSuffix(
427
			localName,
428
			assistOptions.localPrefixes,
429
			assistOptions.localSuffixes);
430
	}
495
	}
431
496
432
	/**
497
	/**
Lines 451-461 Link Here
451
	 * @return char[] the name without prefix and suffix.
516
	 * @return char[] the name without prefix and suffix.
452
	 * @see JavaCore#setOptions(java.util.Hashtable)
517
	 * @see JavaCore#setOptions(java.util.Hashtable)
453
	 * @see JavaCore#getDefaultOptions()
518
	 * @see JavaCore#getDefaultOptions()
519
	 * 
520
	 * @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_LOCAL} as variable kind.
454
	 */
521
	 */
455
	public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) {
522
	public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) {
456
		return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray()));
523
		return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray()));
457
	}
524
	}
458
525
526
	private static char[] removeVariablePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) {
527
		// remove longer prefix
528
		char[] withoutPrefixName = name;
529
		if (prefixes != null) {
530
			int bestLength = 0;
531
			for (int i= 0; i < prefixes.length; i++) {
532
				char[] prefix = prefixes[i];
533
				if (CharOperation.prefixEquals(prefix, name)) {
534
					int currLen = prefix.length;
535
					boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]);
536
					if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) {
537
						if (bestLength < currLen && name.length != currLen) {
538
							withoutPrefixName = CharOperation.subarray(name, currLen, name.length);
539
							bestLength = currLen;
540
						}
541
					}
542
				}
543
			}
544
		}
545
546
		// remove longer suffix
547
		char[] withoutSuffixName = withoutPrefixName;
548
		if(suffixes != null) {
549
			int bestLength = 0;
550
			for (int i = 0; i < suffixes.length; i++) {
551
				char[] suffix = suffixes[i];
552
				if(CharOperation.endsWith(withoutPrefixName, suffix)) {
553
					int currLen = suffix.length;
554
					if(bestLength < currLen && withoutPrefixName.length != currLen) {
555
						withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen);
556
						bestLength = currLen;
557
					}
558
				}
559
			}
560
		}
561
562
		withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]);
563
		return withoutSuffixName;
564
	}
565
566
	private static char[] removeVariablePrefixAndSuffix(
567
			int variableKind,
568
			IJavaProject javaProject,
569
			char[] name) {
570
		AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true));
571
		
572
		char[][] prefixes = null;
573
		char[][] suffixes = null;
574
		switch (variableKind) {
575
			case VK_INSTANCE_FIELD:
576
				prefixes = assistOptions.fieldPrefixes;
577
				suffixes = assistOptions.fieldSuffixes;
578
				break;
579
			case VK_STATIC_FIELD:
580
				prefixes = assistOptions.staticFieldPrefixes;
581
				suffixes = assistOptions.staticFieldSuffixes;
582
				break;
583
			case VK_CONSTANT_FIELD:
584
				prefixes = assistOptions.staticFinalFieldPrefixes;
585
				suffixes = assistOptions.staticFinalFieldSuffixes;
586
				break;
587
			case VK_LOCAL:
588
				prefixes = assistOptions.localPrefixes;
589
				suffixes = assistOptions.localSuffixes;
590
				break;
591
			case VK_PARAMETER:
592
				prefixes = assistOptions.argumentPrefixes;
593
				suffixes = assistOptions.argumentSuffixes;
594
				break;
595
		}
596
		
597
		return removeVariablePrefixAndSuffix(name,	prefixes, suffixes);
598
	}
599
600
	/**
601
	 * Remove prefix and suffix from a variable name.
602
	 * 
603
	 * <p>
604
	 * The variable can be a local variable, a parameter, an instance field, a static field or a constant field.
605
	 * Each type of variable is specified by a variable kind:
606
	 * <ul>
607
	 * <li>{@link #VK_PARAMETER}</li>
608
	 * <li>{@link #VK_LOCAL}</li>
609
	 * <li>{@link #VK_INSTANCE_FIELD}</li>
610
	 * <li>{@link #VK_STATIC_FIELD}</li>
611
	 * <li>{@link #VK_CONSTANT_FIELD}</li>
612
	 * </ul>
613
	 * </p>
614
	 * <p>
615
	 * If variable name prefix is <code>pre</code> and variable name suffix is <code>suf</code>
616
	 * then for a variable named <code>preVariablesuf</code> the result of this method is <code>variable</code>.
617
	 * If there is no prefix or suffix defined in JavaCore options the result is the unchanged
618
	 * name <code>preVariablesuf</code>.
619
	 * </p>
620
	 * <p>
621
	 * For each variable kind this method is affected by the following JavaCore options:
622
	 * <ul>
623
	 * <li>{@link #VK_PARAMETER}: {@link JavaCore#CODEASSIST_ARGUMENT_PREFIXES} and {@link JavaCore#CODEASSIST_ARGUMENT_SUFFIXES}</li>
624
	 * <li>{@link #VK_LOCAL}: {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}</li>
625
	 * <li>{@link #VK_INSTANCE_FIELD}: {@link JavaCore#CODEASSIST_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_FIELD_SUFFIXES}</li>
626
	 * <li>{@link #VK_STATIC_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES}</li>
627
	 * <li>{@link #VK_CONSTANT_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES}</li>
628
	 * </ul>
629
	 * </p>
630
	 * <p>
631
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
632
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
633
	 * </p>
634
	 *
635
	 * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD},
636
	 * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}.
637
	 * @param javaProject project which contains the variable.
638
	 * @param name variable name.
639
	 * @return String the name without prefix and suffix.
640
	 * @see JavaCore#setOptions(java.util.Hashtable)
641
	 * @see JavaCore#getDefaultOptions()
642
	 * 
643
	 * @since 3.5
644
	 */
645
	public static String removeVariablePrefixAndSuffix(
646
			int variableKind,
647
			IJavaProject javaProject,
648
			String name) {
649
		return String.valueOf(removeVariablePrefixAndSuffix(variableKind, javaProject, name.toCharArray()));
650
	}
651
652
	private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) {
653
		char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers);
654
		if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) {
655
			name[0] = ScannerHelper.toUpperCase(name[0]);
656
		}
657
		return name;
658
	}
659
459
	/**
660
	/**
460
	 * Suggest names for an argument. The name is computed from argument's type
661
	 * Suggest names for an argument. The name is computed from argument's type
461
	 * and possible prefixes or suffixes are added.
662
	 * and possible prefixes or suffixes are added.
Lines 483-499 Link Here
483
	 * @return char[][] an array of names.
684
	 * @return char[][] an array of names.
484
	 * @see JavaCore#setOptions(java.util.Hashtable)
685
	 * @see JavaCore#setOptions(java.util.Hashtable)
485
	 * @see JavaCore#getDefaultOptions()
686
	 * @see JavaCore#getDefaultOptions()
687
	 * 
688
	 * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind.
486
	 */
689
	 */
487
	public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
690
	public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
488
		NamingRequestor requestor = new NamingRequestor();
691
		NamingRequestor requestor = new NamingRequestor();
489
		InternalNamingConventions.suggestArgumentNames(
692
		InternalNamingConventions.suggestVariableNames(
490
			javaProject,
693
				VK_PARAMETER,
491
			packageName,
694
				BK_SIMPLE_TYPE_NAME,
492
			qualifiedTypeName,
695
				qualifiedTypeName,
493
			dim,
696
				javaProject,
494
			null,
697
				dim,
495
			excludedNames,
698
				null,
496
			requestor);
699
				excludedNames,
700
				true,
701
				requestor);
497
702
498
		return requestor.getResults();
703
		return requestor.getResults();
499
	}
704
	}
Lines 525-530 Link Here
525
	 * @return char[][] an array of names.
730
	 * @return char[][] an array of names.
526
	 * @see JavaCore#setOptions(java.util.Hashtable)
731
	 * @see JavaCore#setOptions(java.util.Hashtable)
527
	 * @see JavaCore#getDefaultOptions()
732
	 * @see JavaCore#getDefaultOptions()
733
	 * 
734
	 * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind.
528
	 */
735
	 */
529
	public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
736
	public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
530
		return convertCharsToString(
737
		return convertCharsToString(
Lines 535-540 Link Here
535
				dim,
742
				dim,
536
				convertStringToChars(excludedNames)));
743
				convertStringToChars(excludedNames)));
537
	}
744
	}
745
538
	/**
746
	/**
539
	 * Suggest names for a field. The name is computed from field's type
747
	 * Suggest names for a field. The name is computed from field's type
540
	 * and possible prefixes or suffixes are added.
748
	 * and possible prefixes or suffixes are added.
Lines 566-583 Link Here
566
	 * @see Flags
774
	 * @see Flags
567
	 * @see JavaCore#setOptions(java.util.Hashtable)
775
	 * @see JavaCore#setOptions(java.util.Hashtable)
568
	 * @see JavaCore#getDefaultOptions()
776
	 * @see JavaCore#getDefaultOptions()
777
	 * 
778
	 * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead 
779
	 * with {@link #VK_INSTANCE_FIELD} or  {@link #VK_STATIC_FIELD} as variable kind.
569
	 */
780
	 */
570
	public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) {
781
	public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) {
571
		NamingRequestor requestor = new NamingRequestor();
782
		NamingRequestor requestor = new NamingRequestor();
572
		InternalNamingConventions.suggestFieldNames(
783
		InternalNamingConventions.suggestVariableNames(
573
			javaProject,
784
				Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD,
574
			packageName,
785
				BK_SIMPLE_TYPE_NAME,
575
			qualifiedTypeName,
786
				qualifiedTypeName,
576
			dim,
787
				javaProject,
577
			modifiers,
788
				dim,
578
			null,
789
				null,
579
			excludedNames,
790
				excludedNames,
580
			requestor);
791
				true,
792
				requestor);
581
793
582
		return requestor.getResults();
794
		return requestor.getResults();
583
	}
795
	}
Lines 613-618 Link Here
613
	 * @see Flags
825
	 * @see Flags
614
	 * @see JavaCore#setOptions(java.util.Hashtable)
826
	 * @see JavaCore#setOptions(java.util.Hashtable)
615
	 * @see JavaCore#getDefaultOptions()
827
	 * @see JavaCore#getDefaultOptions()
828
	 * 
829
	 * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead 
830
	 * with {@link #VK_INSTANCE_FIELD} or  {@link #VK_STATIC_FIELD} as variable kind.
616
	 */
831
	 */
617
	public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) {
832
	public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) {
618
		return convertCharsToString(
833
		return convertCharsToString(
Lines 624-710 Link Here
624
				modifiers,
839
				modifiers,
625
				convertStringToChars(excludedNames)));
840
				convertStringToChars(excludedNames)));
626
	}
841
	}
627
842
	
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
	/**
843
	/**
709
	 * Suggest name for a getter method. The name is computed from field's name
844
	 * Suggest name for a getter method. The name is computed from field's name
710
	 * and possible prefixes or suffixes are removed.
845
	 * and possible prefixes or suffixes are removed.
Lines 756-762 Link Here
756
			);
891
			);
757
		}
892
		}
758
	}
893
	}
759
760
	/**
894
	/**
761
	 * Suggest name for a getter method. The name is computed from field's name
895
	 * Suggest name for a getter method. The name is computed from field's name
762
	 * and possible prefixes or suffixes are removed.
896
	 * and possible prefixes or suffixes are removed.
Lines 797-803 Link Here
797
				isBoolean,
931
				isBoolean,
798
				convertStringToChars(excludedNames)));
932
				convertStringToChars(excludedNames)));
799
	}
933
	}
934
	/**
935
	 * Suggest names for a local variable. The name is computed from variable's type
936
	 * and possible prefixes or suffixes are added.
937
	 * <p>
938
	 * If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code>
939
	 * and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code>
940
	 * and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code>
941
	 * and <code>name</code>.
942
	 * </p>
943
	 * <p>
944
	 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and
945
	 *  {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}.
946
	 * </p>
947
	 * <p>
948
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
949
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
950
	 * </p>
951
	 *
952
	 * @param javaProject project which contains the variable.
953
	 * @param packageName package of the variable's type.
954
	 * @param qualifiedTypeName variable's type.
955
	 * @param dim variable's dimension (0 if the variable is not an array).
956
	 * @param excludedNames a list of names which cannot be suggested (already used names).
957
	 *         Can be <code>null</code> if there is no excluded names.
958
	 * @return char[][] an array of names.
959
	 * @see JavaCore#setOptions(java.util.Hashtable)
960
	 * @see JavaCore#getDefaultOptions()
961
	 * 
962
	 * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind.
963
	 */
964
	public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) {
965
		NamingRequestor requestor = new NamingRequestor();
966
		InternalNamingConventions.suggestVariableNames(
967
				VK_LOCAL,
968
				BK_SIMPLE_TYPE_NAME,
969
				qualifiedTypeName,
970
				javaProject,
971
				dim,
972
				null,
973
				excludedNames,
974
				true,
975
				requestor);
976
977
		return requestor.getResults();
978
	}
979
	/**
980
	 * Suggest names for a local variable. The name is computed from variable's type
981
	 * and possible prefixes or suffixes are added.
982
	 * <p>
983
	 * If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code>
984
	 * and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code>
985
	 * and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code>
986
	 * and <code>name</code>.
987
	 * </p>
988
	 * <p>
989
	 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and
990
	 *  {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}.
991
	 * </p>
992
	 * <p>
993
	 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
994
	 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
995
	 * </p>
996
	 *
997
	 * @param javaProject project which contains the variable.
998
	 * @param packageName package of the variable's type.
999
	 * @param qualifiedTypeName variable's type.
1000
	 * @param dim variable's dimension (0 if the variable is not an array).
1001
	 * @param excludedNames a list of names which cannot be suggested (already used names).
1002
	 *         Can be <code>null</code> if there is no excluded names.
1003
	 * @return char[][] an array of names.
1004
	 * @see JavaCore#setOptions(java.util.Hashtable)
1005
	 * @see JavaCore#getDefaultOptions()
1006
	 * 
1007
	 * @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind.
1008
	 */
1009
	public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) {
1010
		return convertCharsToString(
1011
			suggestLocalVariableNames(
1012
				javaProject,
1013
				packageName.toCharArray(),
1014
				qualifiedTypeName.toCharArray(),
1015
				dim,
1016
				convertStringToChars(excludedNames)));
1017
	}
1018
	private static char[] suggestNewName(char[] name, char[][] excludedNames){
1019
		if(excludedNames == null) {
1020
			return name;
1021
		}
800
1022
1023
		char[] newName = name;
1024
		int count = 2;
1025
		int i = 0;
1026
		while (i < excludedNames.length) {
1027
			if(CharOperation.equals(newName, excludedNames[i], false)) {
1028
				newName = CharOperation.concat(name, String.valueOf(count++).toCharArray());
1029
				i = 0;
1030
			} else {
1031
				i++;
1032
			}
1033
		}
1034
		return newName;
1035
	}
1036
	
801
	/**
1037
	/**
802
	 * Suggest name for a setter method. The name is computed from field's name
1038
	 * Suggest name for a setter method. The name is computed from field's name
803
	 * and possible prefixes or suffixes are removed.
1039
	 * and possible prefixes or suffixes are removed.
Lines 853-859 Link Here
853
			);
1089
			);
854
		}
1090
		}
855
	}
1091
	}
856
857
	/**
1092
	/**
858
	 * Suggest name for a setter method. The name is computed from field's name
1093
	 * Suggest name for a setter method. The name is computed from field's name
859
	 * and possible prefixes or suffixes are removed.
1094
	 * and possible prefixes or suffixes are removed.
Lines 893-945 Link Here
893
				isBoolean,
1128
				isBoolean,
894
				convertStringToChars(excludedNames)));
1129
				convertStringToChars(excludedNames)));
895
	}
1130
	}
896
1131
	
897
	private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) {
1132
	private NamingConventions() {
898
		char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers);
1133
		// Not instantiable
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
	}
932
933
	private static char[][] convertStringToChars(String[] s) {
934
		int length = s == null ? 0 : s.length;
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
	}
1134
	}
945
}
1135
}
(-)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 (-59 / +39 lines)
Lines 262-271 Link Here
262
	private final static int SUPERTYPE = 1;
262
	private final static int SUPERTYPE = 1;
263
	private final static int SUBTYPE = 2;
263
	private final static int SUBTYPE = 2;
264
264
265
	private final static int FIELD = 0;
266
	private final static int LOCAL = 1;
267
	private final static int ARGUMENT = 2;
268
269
	int expectedTypesPtr = -1;
265
	int expectedTypesPtr = -1;
270
	TypeBinding[] expectedTypes = new TypeBinding[1];
266
	TypeBinding[] expectedTypes = new TypeBinding[1];
271
	int expectedTypesFilter;
267
	int expectedTypesFilter;
Lines 1585-1592 Link Here
1585
				}
1581
				}
1586
1582
1587
				this.completionToken = method.selector;
1583
				this.completionToken = method.selector;
1588
1584
				
1589
				findVariableNames(this.completionToken, method.returnType, excludeNames, null, FIELD, method.modifiers);
1585
				int kind =
1586
					 (method.modifiers & ClassFileConstants.AccStatic) == 0 ? 
1587
							InternalNamingConventions.VK_INSTANCE_FIELD :
1588
								(method.modifiers & ClassFileConstants.AccFinal) == 0 ? 
1589
										InternalNamingConventions.VK_STATIC_FIELD :
1590
											InternalNamingConventions.VK_CONSTANT_FIELD;
1591
							
1592
				findVariableNames(this.completionToken, method.returnType, excludeNames, null, kind);
1590
			}
1593
			}
1591
		} else if (astNode instanceof CompletionOnFieldName) {
1594
		} else if (astNode instanceof CompletionOnFieldName) {
1592
			if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) {
1595
			if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) {
Lines 1599-1606 Link Here
1599
				}
1602
				}
1600
1603
1601
				this.completionToken = field.realName;
1604
				this.completionToken = field.realName;
1602
1605
				
1603
				findVariableNames(field.realName, field.type, excludeNames, null, FIELD, field.modifiers);
1606
				int kind =
1607
					 (field.modifiers & ClassFileConstants.AccStatic) == 0 ? 
1608
							InternalNamingConventions.VK_INSTANCE_FIELD :
1609
								(field.modifiers & ClassFileConstants.AccFinal) == 0 ? 
1610
										InternalNamingConventions.VK_STATIC_FIELD :
1611
											InternalNamingConventions.VK_CONSTANT_FIELD;
1612
				
1613
				findVariableNames(field.realName, field.type, excludeNames, null, kind);
1604
			}
1614
			}
1605
		} else if (astNode instanceof CompletionOnLocalName || astNode instanceof CompletionOnArgumentName) {
1615
		} else if (astNode instanceof CompletionOnLocalName || astNode instanceof CompletionOnArgumentName) {
1606
			if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) {
1616
			if (!this.requestor.isIgnored(CompletionProposal.VARIABLE_DECLARATION)) {
Lines 1609-1619 Link Here
1609
				int kind;
1619
				int kind;
1610
				if (variable instanceof CompletionOnLocalName){
1620
				if (variable instanceof CompletionOnLocalName){
1611
					this.completionToken = ((CompletionOnLocalName) variable).realName;
1621
					this.completionToken = ((CompletionOnLocalName) variable).realName;
1612
					kind = LOCAL;
1622
					kind = InternalNamingConventions.VK_LOCAL;
1613
				} else {
1623
				} else {
1614
					CompletionOnArgumentName arg = (CompletionOnArgumentName) variable;
1624
					CompletionOnArgumentName arg = (CompletionOnArgumentName) variable;
1615
					this.completionToken = arg.realName;
1625
					this.completionToken = arg.realName;
1616
					kind = arg.isCatchArgument ? LOCAL : ARGUMENT;
1626
					kind = arg.isCatchArgument ? InternalNamingConventions.VK_LOCAL : InternalNamingConventions.VK_PARAMETER;
1617
				}
1627
				}
1618
1628
1619
				char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, variable);
1629
				char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, variable);
Lines 1631-1637 Link Here
1631
1641
1632
				System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount);
1642
				System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount);
1633
1643
1634
				findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind, variable.modifiers);
1644
				findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind);
1635
			}
1645
			}
1636
		} else if (astNode instanceof CompletionOnKeyword) {
1646
		} else if (astNode instanceof CompletionOnKeyword) {
1637
			if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
1647
			if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
Lines 8898-8905 Link Here
8898
			char[][] discouragedNames,
8908
			char[][] discouragedNames,
8899
			final char[][] forbiddenNames,
8909
			final char[][] forbiddenNames,
8900
			int dim,
8910
			int dim,
8901
			int kind,
8911
			int kind){
8902
			int modifiers){
8903
		findVariableName(
8912
		findVariableName(
8904
				token,
8913
				token,
8905
				qualifiedPackageName,
8914
				qualifiedPackageName,
Lines 8910-8917 Link Here
8910
				forbiddenNames,
8919
				forbiddenNames,
8911
				false,
8920
				false,
8912
				dim,
8921
				dim,
8913
				kind,
8922
				kind);
8914
				modifiers);
8915
	}
8923
	}
8916
	private void findVariableName(
8924
	private void findVariableName(
8917
			char[] token,
8925
			char[] token,
Lines 8923-8930 Link Here
8923
			final char[][] forbiddenNames,
8931
			final char[][] forbiddenNames,
8924
			boolean forCollection,
8932
			boolean forCollection,
8925
			int dim,
8933
			int dim,
8926
			int kind,
8934
			int kind){
8927
			int modifiers){
8928
8935
8929
		if(sourceName == null || sourceName.length == 0)
8936
		if(sourceName == null || sourceName.length == 0)
8930
			return;
8937
			return;
Lines 9004-9042 Link Here
9004
			}
9011
			}
9005
		};
9012
		};
9006
9013
9007
		switch (kind) {
9014
		InternalNamingConventions.suggestVariableNames(
9008
			case FIELD :
9015
				kind,
9009
				InternalNamingConventions.suggestFieldNames(
9016
				InternalNamingConventions.BK_SIMPLE_TYPE_NAME,
9010
					this.javaProject,
9017
				qualifiedSourceName,
9011
					qualifiedPackageName,
9018
				this.javaProject,
9012
					qualifiedSourceName,
9019
				dim,
9013
					dim,
9020
				token,
9014
					modifiers,
9021
				discouragedNames,
9015
					token,
9022
				true,
9016
					discouragedNames,
9023
				namingRequestor);
9017
					namingRequestor);
9018
				break;
9019
			case LOCAL :
9020
				InternalNamingConventions.suggestLocalVariableNames(
9021
					this.javaProject,
9022
					qualifiedPackageName,
9023
					qualifiedSourceName,
9024
					dim,
9025
					token,
9026
					discouragedNames,
9027
					namingRequestor);
9028
				break;
9029
			case ARGUMENT :
9030
				InternalNamingConventions.suggestArgumentNames(
9031
					this.javaProject,
9032
					qualifiedPackageName,
9033
					qualifiedSourceName,
9034
					dim,
9035
					token,
9036
					discouragedNames,
9037
					namingRequestor);
9038
				break;
9039
		}
9040
	}
9024
	}
9041
	
9025
	
9042
	private void findVariableNameForCollection(
9026
	private void findVariableNameForCollection(
Lines 9047-9054 Link Here
9047
			final TypeBinding typeBinding,
9031
			final TypeBinding typeBinding,
9048
			char[][] discouragedNames,
9032
			char[][] discouragedNames,
9049
			final char[][] forbiddenNames,
9033
			final char[][] forbiddenNames,
9050
			int kind,
9034
			int kind){
9051
			int modifiers){
9052
9035
9053
		findVariableName(
9036
		findVariableName(
9054
				token,
9037
				token,
Lines 9060-9070 Link Here
9060
				forbiddenNames,
9043
				forbiddenNames,
9061
				false,
9044
				false,
9062
				1,
9045
				1,
9063
				kind,
9046
				kind);
9064
				modifiers);
9065
	}
9047
	}
9066
9048
9067
	private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind, int modifiers){
9049
	private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind){
9068
		if(type != null &&
9050
		if(type != null &&
9069
			type.resolvedType != null) {
9051
			type.resolvedType != null) {
9070
			TypeBinding tb = type.resolvedType;
9052
			TypeBinding tb = type.resolvedType;
Lines 9080-9087 Link Here
9080
					discouragedNames,
9062
					discouragedNames,
9081
					forbiddenNames,
9063
					forbiddenNames,
9082
					type.dimensions(),
9064
					type.dimensions(),
9083
					kind,
9065
					kind);
9084
					modifiers);
9085
				
9066
				
9086
				if (tb.isParameterizedType() &&
9067
				if (tb.isParameterizedType() &&
9087
						tb.findSuperTypeOriginatingFrom(TypeIds.T_JavaUtilCollection, false) != null) {
9068
						tb.findSuperTypeOriginatingFrom(TypeIds.T_JavaUtilCollection, false) != null) {
Lines 9097-9104 Link Here
9097
							tb,
9078
							tb,
9098
							discouragedNames,
9079
							discouragedNames,
9099
							forbiddenNames,
9080
							forbiddenNames,
9100
							kind,
9081
							kind);
9101
							modifiers);
9102
					}
9082
					}
9103
				}
9083
				}
9104
			}
9084
			}

Return to bug 38111