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

Collapse All | Expand All

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

Return to bug 38111