Lines 48-57
Link Here
|
48 |
* @noinstantiate This class is not intended to be instantiated by clients. |
48 |
* @noinstantiate This class is not intended to be instantiated by clients. |
49 |
*/ |
49 |
*/ |
50 |
public final class NamingConventions { |
50 |
public final class NamingConventions { |
51 |
private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$ |
|
|
52 |
private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$ |
53 |
private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$ |
54 |
|
55 |
static class NamingRequestor implements INamingRequestor { |
51 |
static class NamingRequestor implements INamingRequestor { |
56 |
private final static int SIZE = 10; |
52 |
private final static int SIZE = 10; |
57 |
|
53 |
|
Lines 80-85
Link Here
|
80 |
// for acceptNameWithoutPrefixAndSuffix |
76 |
// for acceptNameWithoutPrefixAndSuffix |
81 |
private char[][] otherResults = new char[SIZE][]; |
77 |
private char[][] otherResults = new char[SIZE][]; |
82 |
private int otherResultsCount = 0; |
78 |
private int otherResultsCount = 0; |
|
|
79 |
public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) { |
80 |
int length = this.otherResults.length; |
81 |
if(length == this.otherResultsCount) { |
82 |
System.arraycopy( |
83 |
this.otherResults, |
84 |
0, |
85 |
this.otherResults = new char[length * 2][], |
86 |
0, |
87 |
length); |
88 |
} |
89 |
this.otherResults[this.otherResultsCount++] = name; |
90 |
} |
91 |
|
92 |
public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) { |
93 |
if(isFirstPrefix) { |
94 |
int length = this.firstPrefixResults.length; |
95 |
if(length == this.firstPrefixResultsCount) { |
96 |
System.arraycopy( |
97 |
this.firstPrefixResults, |
98 |
0, |
99 |
this.firstPrefixResults = new char[length * 2][], |
100 |
0, |
101 |
length); |
102 |
} |
103 |
this.firstPrefixResults[this.firstPrefixResultsCount++] = name; |
104 |
} else{ |
105 |
int length = this.prefixResults.length; |
106 |
if(length == this.prefixResultsCount) { |
107 |
System.arraycopy( |
108 |
this.prefixResults, |
109 |
0, |
110 |
this.prefixResults = new char[length * 2][], |
111 |
0, |
112 |
length); |
113 |
} |
114 |
this.prefixResults[this.prefixResultsCount++] = name; |
115 |
} |
116 |
} |
117 |
|
83 |
public void acceptNameWithPrefixAndSuffix(char[] name, boolean isFirstPrefix, boolean isFirstSuffix, int reusedCharacters) { |
118 |
public void acceptNameWithPrefixAndSuffix(char[] name, boolean isFirstPrefix, boolean isFirstSuffix, int reusedCharacters) { |
84 |
if(isFirstPrefix && isFirstSuffix) { |
119 |
if(isFirstPrefix && isFirstSuffix) { |
85 |
int length = this.firstPrefixAndFirstSuffixResults.length; |
120 |
int length = this.firstPrefixAndFirstSuffixResults.length; |
Lines 128-159
Link Here
|
128 |
} |
163 |
} |
129 |
} |
164 |
} |
130 |
|
165 |
|
131 |
public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) { |
|
|
132 |
if(isFirstPrefix) { |
133 |
int length = this.firstPrefixResults.length; |
134 |
if(length == this.firstPrefixResultsCount) { |
135 |
System.arraycopy( |
136 |
this.firstPrefixResults, |
137 |
0, |
138 |
this.firstPrefixResults = new char[length * 2][], |
139 |
0, |
140 |
length); |
141 |
} |
142 |
this.firstPrefixResults[this.firstPrefixResultsCount++] = name; |
143 |
} else{ |
144 |
int length = this.prefixResults.length; |
145 |
if(length == this.prefixResultsCount) { |
146 |
System.arraycopy( |
147 |
this.prefixResults, |
148 |
0, |
149 |
this.prefixResults = new char[length * 2][], |
150 |
0, |
151 |
length); |
152 |
} |
153 |
this.prefixResults[this.prefixResultsCount++] = name; |
154 |
} |
155 |
} |
156 |
|
157 |
public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix, int reusedCharacters) { |
166 |
public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix, int reusedCharacters) { |
158 |
if(isFirstSuffix) { |
167 |
if(isFirstSuffix) { |
159 |
int length = this.firstSuffixResults.length; |
168 |
int length = this.firstSuffixResults.length; |
Lines 179-197
Link Here
|
179 |
this.suffixResults[this.suffixResultsCount++] = name; |
188 |
this.suffixResults[this.suffixResultsCount++] = name; |
180 |
} |
189 |
} |
181 |
} |
190 |
} |
182 |
|
|
|
183 |
public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) { |
184 |
int length = this.otherResults.length; |
185 |
if(length == this.otherResultsCount) { |
186 |
System.arraycopy( |
187 |
this.otherResults, |
188 |
0, |
189 |
this.otherResults = new char[length * 2][], |
190 |
0, |
191 |
length); |
192 |
} |
193 |
this.otherResults[this.otherResultsCount++] = name; |
194 |
} |
195 |
public char[][] getResults(){ |
191 |
public char[][] getResults(){ |
196 |
int count = |
192 |
int count = |
197 |
this.firstPrefixAndFirstSuffixResultsCount |
193 |
this.firstPrefixAndFirstSuffixResultsCount |
Lines 228-277
Link Here
|
228 |
return results; |
224 |
return results; |
229 |
} |
225 |
} |
230 |
} |
226 |
} |
|
|
227 |
private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$ |
228 |
private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$ |
231 |
|
229 |
|
|
|
230 |
private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$ |
232 |
|
231 |
|
233 |
private NamingConventions() { |
|
|
234 |
// Not instantiable |
235 |
} |
236 |
|
232 |
|
237 |
private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) { |
233 |
public static final int VK_STATIC_FIELD = InternalNamingConventions.VK_STATIC_FIELD; |
238 |
// remove longer prefix |
234 |
public static final int VK_INSTANCE_FIELD = InternalNamingConventions.VK_INSTANCE_FIELD; |
239 |
char[] withoutPrefixName = name; |
235 |
public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_CONSTANT_FIELD; |
240 |
if (prefixes != null) { |
236 |
public static final int VK_PARAMETER = InternalNamingConventions.VK_PARAMETER; |
241 |
int bestLength = 0; |
237 |
public static final int VK_LOCAL = InternalNamingConventions.VK_LOCAL; |
242 |
for (int i= 0; i < prefixes.length; i++) { |
238 |
|
243 |
char[] prefix = prefixes[i]; |
239 |
public static final int BK_SIMPLE_NAME = InternalNamingConventions.BK_SIMPLE_NAME; |
244 |
if (CharOperation.prefixEquals(prefix, name)) { |
240 |
public static final int BK_SIMPLE_TYPE_NAME = InternalNamingConventions.BK_SIMPLE_TYPE_NAME; |
245 |
int currLen = prefix.length; |
|
|
246 |
boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); |
247 |
if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { |
248 |
if (bestLength < currLen && name.length != currLen) { |
249 |
withoutPrefixName = CharOperation.subarray(name, currLen, name.length); |
250 |
bestLength = currLen; |
251 |
} |
252 |
} |
253 |
} |
254 |
} |
255 |
} |
256 |
|
241 |
|
257 |
// remove longer suffix |
242 |
private static String[] convertCharsToString(char[][] c) { |
258 |
char[] withoutSuffixName = withoutPrefixName; |
243 |
int length = c == null ? 0 : c.length; |
259 |
if(suffixes != null) { |
244 |
String[] s = new String[length]; |
260 |
int bestLength = 0; |
245 |
for (int i = 0; i < length; i++) { |
261 |
for (int i = 0; i < suffixes.length; i++) { |
246 |
s[i] = String.valueOf(c[i]); |
262 |
char[] suffix = suffixes[i]; |
247 |
} |
263 |
if(CharOperation.endsWith(withoutPrefixName, suffix)) { |
248 |
return s; |
264 |
int currLen = suffix.length; |
249 |
} |
265 |
if(bestLength < currLen && withoutPrefixName.length != currLen) { |
250 |
private static char[][] convertStringToChars(String[] s) { |
266 |
withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); |
251 |
int length = s == null ? 0 : s.length; |
267 |
bestLength = currLen; |
252 |
char[][] c = new char[length][]; |
268 |
} |
253 |
for (int i = 0; i < length; i++) { |
269 |
} |
254 |
if(s[i] == null) { |
|
|
255 |
c[i] = CharOperation.NO_CHAR; |
256 |
} else { |
257 |
c[i] = s[i].toCharArray(); |
270 |
} |
258 |
} |
271 |
} |
259 |
} |
|
|
260 |
return c; |
261 |
} |
272 |
|
262 |
|
273 |
withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); |
263 |
/** |
274 |
return withoutSuffixName; |
264 |
* Suggest names for a variable. The name is computed from a base name |
|
|
265 |
* and possible prefixes or suffixes are added. |
266 |
* <p> |
267 |
* The variable can be a local variable, a parameter, an instance field, a static field or a constant field. |
268 |
* Each type of variable is specified by a variable kind: |
269 |
* <ul> |
270 |
* <li>{@link #VK_PARAMETER} for parameter</li> |
271 |
* <li>{@link #VK_LOCAL} for local variable</li> |
272 |
* <li>{@link #VK_INSTANCE_FIELD} for instance field</li> |
273 |
* <li>{@link #VK_STATIC_FIELD} for static field</li> |
274 |
* <li>{@link #VK_CONSTANT_FIELD} for constant field</li> |
275 |
* </ul> |
276 |
* Some other kinds could be added in the future. |
277 |
* </p> |
278 |
* <p> |
279 |
* The base name is used to compute the variable name. |
280 |
* Some different kinds of base name are possible and each kind is associated to a different heuristic to compute variable names. |
281 |
* The different kinds of base name are: |
282 |
* <ul> |
283 |
* <li>{@link #BK_SIMPLE_NAME}: If the prefix is <code>pre</code> and the suffix is <code>suf</code> then the proposed name is |
284 |
* <code>preSimpleNamesuf</code>.</li> |
285 |
* <li>{@link #BK_SIMPLE_TYPE_NAME}: If the type is <code>TypeName</code>, the prefix is <code>pre</code> and the suffix is <code>suf</code> |
286 |
* then the proposed names are <code>preTypeNamesuf</code> and <code>preNamesuf</code>.</li> |
287 |
* </ul> |
288 |
* Some other kinds could be added in the future. |
289 |
* </p> |
290 |
* <p> |
291 |
* Each variable kind is affected by the following JavaCore options: |
292 |
* <ul> |
293 |
* <li>{@link #VK_PARAMETER}: {@link JavaCore#CODEASSIST_ARGUMENT_PREFIXES} and {@link JavaCore#CODEASSIST_ARGUMENT_SUFFIXES}</li> |
294 |
* <li>{@link #VK_LOCAL}: {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}</li> |
295 |
* <li>{@link #VK_INSTANCE_FIELD}: {@link JavaCore#CODEASSIST_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_FIELD_SUFFIXES}</li> |
296 |
* <li>{@link #VK_STATIC_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES}</li> |
297 |
* <li>{@link #VK_CONSTANT_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES}</li> |
298 |
* </ul> |
299 |
* </p> |
300 |
* <p> |
301 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
302 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
303 |
* </p> |
304 |
* |
305 |
* @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, |
306 |
* {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. |
307 |
* @param baseNameKind specifies what type the base name is: {@link #BK_SIMPLE_NAME} or {@link #BK_SIMPLE_TYPE_NAME} |
308 |
* @param baseName name used to compute the suggested names. |
309 |
* @param javaProject project which contains the variable. |
310 |
* @param dim variable dimension (0 if the field is not an array). |
311 |
* @param excluded a list of names which cannot be suggested (already used names). |
312 |
* Can be <code>null</code> if there is no excluded names. |
313 |
* @param evaluateDefault if set, the result is guaranteed to contain at least one result. If not, the result can be an empty array. |
314 |
* @return String[] an array of names. |
315 |
* @see JavaCore#setOptions(java.util.Hashtable) |
316 |
* @see JavaCore#getDefaultOptions() |
317 |
*/ |
318 |
public static String[] getVariableNames( |
319 |
int variableKind, |
320 |
int baseNameKind, |
321 |
String baseName, |
322 |
IJavaProject javaProject, |
323 |
int dim, |
324 |
String[] excluded, |
325 |
boolean evaluateDefault) { |
326 |
|
327 |
NamingRequestor requestor = new NamingRequestor(); |
328 |
InternalNamingConventions.suggestVariableNames( |
329 |
variableKind, |
330 |
baseNameKind, |
331 |
baseName.toCharArray(), |
332 |
javaProject, |
333 |
dim, |
334 |
null, |
335 |
convertStringToChars(excluded), |
336 |
evaluateDefault, |
337 |
requestor); |
338 |
|
339 |
return convertCharsToString(requestor.getResults()); |
275 |
} |
340 |
} |
276 |
|
341 |
|
277 |
/** |
342 |
/** |
Lines 296-308
Link Here
|
296 |
* @return char[] the name without prefix and suffix. |
361 |
* @return char[] the name without prefix and suffix. |
297 |
* @see JavaCore#setOptions(java.util.Hashtable) |
362 |
* @see JavaCore#setOptions(java.util.Hashtable) |
298 |
* @see JavaCore#getDefaultOptions() |
363 |
* @see JavaCore#getDefaultOptions() |
|
|
364 |
* |
365 |
* @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_PARAMETER} as variable kind. |
299 |
*/ |
366 |
*/ |
300 |
public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) { |
367 |
public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) { |
301 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
368 |
return removeVariablePrefixAndSuffix(VK_PARAMETER, javaProject, argumentName); |
302 |
return removePrefixAndSuffix( |
|
|
303 |
argumentName, |
304 |
assistOptions.argumentPrefixes, |
305 |
assistOptions.argumentSuffixes); |
306 |
} |
369 |
} |
307 |
|
370 |
|
308 |
/** |
371 |
/** |
Lines 327-337
Link Here
|
327 |
* @return char[] the name without prefix and suffix. |
390 |
* @return char[] the name without prefix and suffix. |
328 |
* @see JavaCore#setOptions(java.util.Hashtable) |
391 |
* @see JavaCore#setOptions(java.util.Hashtable) |
329 |
* @see JavaCore#getDefaultOptions() |
392 |
* @see JavaCore#getDefaultOptions() |
|
|
393 |
* |
394 |
* @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_PARAMETER} as variable kind. |
330 |
*/ |
395 |
*/ |
331 |
public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) { |
396 |
public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) { |
332 |
return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray())); |
397 |
return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray())); |
333 |
} |
398 |
} |
334 |
|
|
|
335 |
/** |
399 |
/** |
336 |
* Remove prefix and suffix from a field name. |
400 |
* Remove prefix and suffix from a field name. |
337 |
* <p> |
401 |
* <p> |
Lines 358-371
Link Here
|
358 |
* @see Flags |
422 |
* @see Flags |
359 |
* @see JavaCore#setOptions(java.util.Hashtable) |
423 |
* @see JavaCore#setOptions(java.util.Hashtable) |
360 |
* @see JavaCore#getDefaultOptions() |
424 |
* @see JavaCore#getDefaultOptions() |
|
|
425 |
* |
426 |
* @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead |
427 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
361 |
*/ |
428 |
*/ |
362 |
public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) { |
429 |
public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) { |
363 |
boolean isStatic = Flags.isStatic(modifiers); |
430 |
boolean isStatic = Flags.isStatic(modifiers); |
364 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
431 |
return removeVariablePrefixAndSuffix(isStatic ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, javaProject, fieldName); |
365 |
return removePrefixAndSuffix( |
|
|
366 |
fieldName, |
367 |
isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes, |
368 |
isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes); |
369 |
} |
432 |
} |
370 |
|
433 |
|
371 |
/** |
434 |
/** |
Lines 394-403
Link Here
|
394 |
* @see Flags |
457 |
* @see Flags |
395 |
* @see JavaCore#setOptions(java.util.Hashtable) |
458 |
* @see JavaCore#setOptions(java.util.Hashtable) |
396 |
* @see JavaCore#getDefaultOptions() |
459 |
* @see JavaCore#getDefaultOptions() |
|
|
460 |
* |
461 |
* @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead |
462 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
397 |
*/ |
463 |
*/ |
398 |
public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) { |
464 |
public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) { |
399 |
return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers)); |
465 |
return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers)); |
400 |
} |
466 |
} |
|
|
467 |
|
401 |
/** |
468 |
/** |
402 |
* Remove prefix and suffix from a local variable name. |
469 |
* Remove prefix and suffix from a local variable name. |
403 |
* <p> |
470 |
* <p> |
Lines 420-432
Link Here
|
420 |
* @return char[] the name without prefix and suffix. |
487 |
* @return char[] the name without prefix and suffix. |
421 |
* @see JavaCore#setOptions(java.util.Hashtable) |
488 |
* @see JavaCore#setOptions(java.util.Hashtable) |
422 |
* @see JavaCore#getDefaultOptions() |
489 |
* @see JavaCore#getDefaultOptions() |
|
|
490 |
* |
491 |
* @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_LOCAL} as variable kind. |
423 |
*/ |
492 |
*/ |
424 |
public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) { |
493 |
public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) { |
425 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
494 |
return removeVariablePrefixAndSuffix(VK_LOCAL, javaProject, localName); |
426 |
return removePrefixAndSuffix( |
|
|
427 |
localName, |
428 |
assistOptions.localPrefixes, |
429 |
assistOptions.localSuffixes); |
430 |
} |
495 |
} |
431 |
|
496 |
|
432 |
/** |
497 |
/** |
Lines 451-461
Link Here
|
451 |
* @return char[] the name without prefix and suffix. |
516 |
* @return char[] the name without prefix and suffix. |
452 |
* @see JavaCore#setOptions(java.util.Hashtable) |
517 |
* @see JavaCore#setOptions(java.util.Hashtable) |
453 |
* @see JavaCore#getDefaultOptions() |
518 |
* @see JavaCore#getDefaultOptions() |
|
|
519 |
* |
520 |
* @deprecated Use {@link #removeVariablePrefixAndSuffix(int, IJavaProject, String)} instead with {@link #VK_LOCAL} as variable kind. |
454 |
*/ |
521 |
*/ |
455 |
public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) { |
522 |
public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) { |
456 |
return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray())); |
523 |
return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray())); |
457 |
} |
524 |
} |
458 |
|
525 |
|
|
|
526 |
private static char[] removeVariablePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) { |
527 |
// remove longer prefix |
528 |
char[] withoutPrefixName = name; |
529 |
if (prefixes != null) { |
530 |
int bestLength = 0; |
531 |
for (int i= 0; i < prefixes.length; i++) { |
532 |
char[] prefix = prefixes[i]; |
533 |
if (CharOperation.prefixEquals(prefix, name)) { |
534 |
int currLen = prefix.length; |
535 |
boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); |
536 |
if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { |
537 |
if (bestLength < currLen && name.length != currLen) { |
538 |
withoutPrefixName = CharOperation.subarray(name, currLen, name.length); |
539 |
bestLength = currLen; |
540 |
} |
541 |
} |
542 |
} |
543 |
} |
544 |
} |
545 |
|
546 |
// remove longer suffix |
547 |
char[] withoutSuffixName = withoutPrefixName; |
548 |
if(suffixes != null) { |
549 |
int bestLength = 0; |
550 |
for (int i = 0; i < suffixes.length; i++) { |
551 |
char[] suffix = suffixes[i]; |
552 |
if(CharOperation.endsWith(withoutPrefixName, suffix)) { |
553 |
int currLen = suffix.length; |
554 |
if(bestLength < currLen && withoutPrefixName.length != currLen) { |
555 |
withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); |
556 |
bestLength = currLen; |
557 |
} |
558 |
} |
559 |
} |
560 |
} |
561 |
|
562 |
withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); |
563 |
return withoutSuffixName; |
564 |
} |
565 |
|
566 |
private static char[] removeVariablePrefixAndSuffix( |
567 |
int variableKind, |
568 |
IJavaProject javaProject, |
569 |
char[] name) { |
570 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
571 |
|
572 |
char[][] prefixes = null; |
573 |
char[][] suffixes = null; |
574 |
switch (variableKind) { |
575 |
case VK_INSTANCE_FIELD: |
576 |
prefixes = assistOptions.fieldPrefixes; |
577 |
suffixes = assistOptions.fieldSuffixes; |
578 |
break; |
579 |
case VK_STATIC_FIELD: |
580 |
prefixes = assistOptions.staticFieldPrefixes; |
581 |
suffixes = assistOptions.staticFieldSuffixes; |
582 |
break; |
583 |
case VK_CONSTANT_FIELD: |
584 |
prefixes = assistOptions.staticFinalFieldPrefixes; |
585 |
suffixes = assistOptions.staticFinalFieldSuffixes; |
586 |
break; |
587 |
case VK_LOCAL: |
588 |
prefixes = assistOptions.localPrefixes; |
589 |
suffixes = assistOptions.localSuffixes; |
590 |
break; |
591 |
case VK_PARAMETER: |
592 |
prefixes = assistOptions.argumentPrefixes; |
593 |
suffixes = assistOptions.argumentSuffixes; |
594 |
break; |
595 |
} |
596 |
|
597 |
return removeVariablePrefixAndSuffix(name, prefixes, suffixes); |
598 |
} |
599 |
|
600 |
/** |
601 |
* Remove prefix and suffix from a variable name. |
602 |
* |
603 |
* <p> |
604 |
* The variable can be a local variable, a parameter, an instance field, a static field or a constant field. |
605 |
* Each type of variable is specified by a variable kind: |
606 |
* <ul> |
607 |
* <li>{@link #VK_PARAMETER}</li> |
608 |
* <li>{@link #VK_LOCAL}</li> |
609 |
* <li>{@link #VK_INSTANCE_FIELD}</li> |
610 |
* <li>{@link #VK_STATIC_FIELD}</li> |
611 |
* <li>{@link #VK_CONSTANT_FIELD}</li> |
612 |
* </ul> |
613 |
* </p> |
614 |
* <p> |
615 |
* If variable name prefix is <code>pre</code> and variable name suffix is <code>suf</code> |
616 |
* then for a variable named <code>preVariablesuf</code> the result of this method is <code>variable</code>. |
617 |
* If there is no prefix or suffix defined in JavaCore options the result is the unchanged |
618 |
* name <code>preVariablesuf</code>. |
619 |
* </p> |
620 |
* <p> |
621 |
* For each variable kind this method is affected by the following JavaCore options: |
622 |
* <ul> |
623 |
* <li>{@link #VK_PARAMETER}: {@link JavaCore#CODEASSIST_ARGUMENT_PREFIXES} and {@link JavaCore#CODEASSIST_ARGUMENT_SUFFIXES}</li> |
624 |
* <li>{@link #VK_LOCAL}: {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}</li> |
625 |
* <li>{@link #VK_INSTANCE_FIELD}: {@link JavaCore#CODEASSIST_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_FIELD_SUFFIXES}</li> |
626 |
* <li>{@link #VK_STATIC_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES}</li> |
627 |
* <li>{@link #VK_CONSTANT_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES}</li> |
628 |
* </ul> |
629 |
* </p> |
630 |
* <p> |
631 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
632 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
633 |
* </p> |
634 |
* |
635 |
* @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, |
636 |
* {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. |
637 |
* @param javaProject project which contains the variable. |
638 |
* @param name variable name. |
639 |
* @return String the name without prefix and suffix. |
640 |
* @see JavaCore#setOptions(java.util.Hashtable) |
641 |
* @see JavaCore#getDefaultOptions() |
642 |
* |
643 |
* @since 3.5 |
644 |
*/ |
645 |
public static String removeVariablePrefixAndSuffix( |
646 |
int variableKind, |
647 |
IJavaProject javaProject, |
648 |
String name) { |
649 |
return String.valueOf(removeVariablePrefixAndSuffix(variableKind, javaProject, name.toCharArray())); |
650 |
} |
651 |
|
652 |
private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { |
653 |
char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); |
654 |
if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { |
655 |
name[0] = ScannerHelper.toUpperCase(name[0]); |
656 |
} |
657 |
return name; |
658 |
} |
659 |
|
459 |
/** |
660 |
/** |
460 |
* Suggest names for an argument. The name is computed from argument's type |
661 |
* Suggest names for an argument. The name is computed from argument's type |
461 |
* and possible prefixes or suffixes are added. |
662 |
* and possible prefixes or suffixes are added. |
Lines 483-499
Link Here
|
483 |
* @return char[][] an array of names. |
684 |
* @return char[][] an array of names. |
484 |
* @see JavaCore#setOptions(java.util.Hashtable) |
685 |
* @see JavaCore#setOptions(java.util.Hashtable) |
485 |
* @see JavaCore#getDefaultOptions() |
686 |
* @see JavaCore#getDefaultOptions() |
|
|
687 |
* |
688 |
* @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. |
486 |
*/ |
689 |
*/ |
487 |
public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
690 |
public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
488 |
NamingRequestor requestor = new NamingRequestor(); |
691 |
NamingRequestor requestor = new NamingRequestor(); |
489 |
InternalNamingConventions.suggestArgumentNames( |
692 |
InternalNamingConventions.suggestVariableNames( |
490 |
javaProject, |
693 |
VK_PARAMETER, |
491 |
packageName, |
694 |
BK_SIMPLE_TYPE_NAME, |
492 |
qualifiedTypeName, |
695 |
qualifiedTypeName, |
493 |
dim, |
696 |
javaProject, |
494 |
null, |
697 |
dim, |
495 |
excludedNames, |
698 |
null, |
496 |
requestor); |
699 |
excludedNames, |
|
|
700 |
true, |
701 |
requestor); |
497 |
|
702 |
|
498 |
return requestor.getResults(); |
703 |
return requestor.getResults(); |
499 |
} |
704 |
} |
Lines 525-530
Link Here
|
525 |
* @return char[][] an array of names. |
730 |
* @return char[][] an array of names. |
526 |
* @see JavaCore#setOptions(java.util.Hashtable) |
731 |
* @see JavaCore#setOptions(java.util.Hashtable) |
527 |
* @see JavaCore#getDefaultOptions() |
732 |
* @see JavaCore#getDefaultOptions() |
|
|
733 |
* |
734 |
* @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. |
528 |
*/ |
735 |
*/ |
529 |
public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
736 |
public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
530 |
return convertCharsToString( |
737 |
return convertCharsToString( |
Lines 535-540
Link Here
|
535 |
dim, |
742 |
dim, |
536 |
convertStringToChars(excludedNames))); |
743 |
convertStringToChars(excludedNames))); |
537 |
} |
744 |
} |
|
|
745 |
|
538 |
/** |
746 |
/** |
539 |
* Suggest names for a field. The name is computed from field's type |
747 |
* Suggest names for a field. The name is computed from field's type |
540 |
* and possible prefixes or suffixes are added. |
748 |
* and possible prefixes or suffixes are added. |
Lines 566-583
Link Here
|
566 |
* @see Flags |
774 |
* @see Flags |
567 |
* @see JavaCore#setOptions(java.util.Hashtable) |
775 |
* @see JavaCore#setOptions(java.util.Hashtable) |
568 |
* @see JavaCore#getDefaultOptions() |
776 |
* @see JavaCore#getDefaultOptions() |
|
|
777 |
* |
778 |
* @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead |
779 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
569 |
*/ |
780 |
*/ |
570 |
public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { |
781 |
public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { |
571 |
NamingRequestor requestor = new NamingRequestor(); |
782 |
NamingRequestor requestor = new NamingRequestor(); |
572 |
InternalNamingConventions.suggestFieldNames( |
783 |
InternalNamingConventions.suggestVariableNames( |
573 |
javaProject, |
784 |
Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, |
574 |
packageName, |
785 |
BK_SIMPLE_TYPE_NAME, |
575 |
qualifiedTypeName, |
786 |
qualifiedTypeName, |
576 |
dim, |
787 |
javaProject, |
577 |
modifiers, |
788 |
dim, |
578 |
null, |
789 |
null, |
579 |
excludedNames, |
790 |
excludedNames, |
580 |
requestor); |
791 |
true, |
|
|
792 |
requestor); |
581 |
|
793 |
|
582 |
return requestor.getResults(); |
794 |
return requestor.getResults(); |
583 |
} |
795 |
} |
Lines 613-618
Link Here
|
613 |
* @see Flags |
825 |
* @see Flags |
614 |
* @see JavaCore#setOptions(java.util.Hashtable) |
826 |
* @see JavaCore#setOptions(java.util.Hashtable) |
615 |
* @see JavaCore#getDefaultOptions() |
827 |
* @see JavaCore#getDefaultOptions() |
|
|
828 |
* |
829 |
* @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead |
830 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
616 |
*/ |
831 |
*/ |
617 |
public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) { |
832 |
public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) { |
618 |
return convertCharsToString( |
833 |
return convertCharsToString( |
Lines 624-710
Link Here
|
624 |
modifiers, |
839 |
modifiers, |
625 |
convertStringToChars(excludedNames))); |
840 |
convertStringToChars(excludedNames))); |
626 |
} |
841 |
} |
627 |
|
842 |
|
628 |
/** |
|
|
629 |
* Suggest names for a local variable. The name is computed from variable's type |
630 |
* and possible prefixes or suffixes are added. |
631 |
* <p> |
632 |
* If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code> |
633 |
* and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code> |
634 |
* and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code> |
635 |
* and <code>name</code>. |
636 |
* </p> |
637 |
* <p> |
638 |
* This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and |
639 |
* {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. |
640 |
* </p> |
641 |
* <p> |
642 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
643 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
644 |
* </p> |
645 |
* |
646 |
* @param javaProject project which contains the variable. |
647 |
* @param packageName package of the variable's type. |
648 |
* @param qualifiedTypeName variable's type. |
649 |
* @param dim variable's dimension (0 if the variable is not an array). |
650 |
* @param excludedNames a list of names which cannot be suggested (already used names). |
651 |
* Can be <code>null</code> if there is no excluded names. |
652 |
* @return char[][] an array of names. |
653 |
* @see JavaCore#setOptions(java.util.Hashtable) |
654 |
* @see JavaCore#getDefaultOptions() |
655 |
*/ |
656 |
public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
657 |
NamingRequestor requestor = new NamingRequestor(); |
658 |
InternalNamingConventions.suggestLocalVariableNames( |
659 |
javaProject, |
660 |
packageName, |
661 |
qualifiedTypeName, |
662 |
dim, |
663 |
null, |
664 |
excludedNames, |
665 |
requestor); |
666 |
|
667 |
return requestor.getResults(); |
668 |
} |
669 |
|
670 |
/** |
671 |
* Suggest names for a local variable. The name is computed from variable's type |
672 |
* and possible prefixes or suffixes are added. |
673 |
* <p> |
674 |
* If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code> |
675 |
* and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code> |
676 |
* and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code> |
677 |
* and <code>name</code>. |
678 |
* </p> |
679 |
* <p> |
680 |
* This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and |
681 |
* {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. |
682 |
* </p> |
683 |
* <p> |
684 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
685 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
686 |
* </p> |
687 |
* |
688 |
* @param javaProject project which contains the variable. |
689 |
* @param packageName package of the variable's type. |
690 |
* @param qualifiedTypeName variable's type. |
691 |
* @param dim variable's dimension (0 if the variable is not an array). |
692 |
* @param excludedNames a list of names which cannot be suggested (already used names). |
693 |
* Can be <code>null</code> if there is no excluded names. |
694 |
* @return char[][] an array of names. |
695 |
* @see JavaCore#setOptions(java.util.Hashtable) |
696 |
* @see JavaCore#getDefaultOptions() |
697 |
*/ |
698 |
public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
699 |
return convertCharsToString( |
700 |
suggestLocalVariableNames( |
701 |
javaProject, |
702 |
packageName.toCharArray(), |
703 |
qualifiedTypeName.toCharArray(), |
704 |
dim, |
705 |
convertStringToChars(excludedNames))); |
706 |
} |
707 |
|
708 |
/** |
843 |
/** |
709 |
* Suggest name for a getter method. The name is computed from field's name |
844 |
* Suggest name for a getter method. The name is computed from field's name |
710 |
* and possible prefixes or suffixes are removed. |
845 |
* and possible prefixes or suffixes are removed. |
Lines 756-762
Link Here
|
756 |
); |
891 |
); |
757 |
} |
892 |
} |
758 |
} |
893 |
} |
759 |
|
|
|
760 |
/** |
894 |
/** |
761 |
* Suggest name for a getter method. The name is computed from field's name |
895 |
* Suggest name for a getter method. The name is computed from field's name |
762 |
* and possible prefixes or suffixes are removed. |
896 |
* and possible prefixes or suffixes are removed. |
Lines 797-803
Link Here
|
797 |
isBoolean, |
931 |
isBoolean, |
798 |
convertStringToChars(excludedNames))); |
932 |
convertStringToChars(excludedNames))); |
799 |
} |
933 |
} |
|
|
934 |
/** |
935 |
* Suggest names for a local variable. The name is computed from variable's type |
936 |
* and possible prefixes or suffixes are added. |
937 |
* <p> |
938 |
* If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code> |
939 |
* and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code> |
940 |
* and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code> |
941 |
* and <code>name</code>. |
942 |
* </p> |
943 |
* <p> |
944 |
* This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and |
945 |
* {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. |
946 |
* </p> |
947 |
* <p> |
948 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
949 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
950 |
* </p> |
951 |
* |
952 |
* @param javaProject project which contains the variable. |
953 |
* @param packageName package of the variable's type. |
954 |
* @param qualifiedTypeName variable's type. |
955 |
* @param dim variable's dimension (0 if the variable is not an array). |
956 |
* @param excludedNames a list of names which cannot be suggested (already used names). |
957 |
* Can be <code>null</code> if there is no excluded names. |
958 |
* @return char[][] an array of names. |
959 |
* @see JavaCore#setOptions(java.util.Hashtable) |
960 |
* @see JavaCore#getDefaultOptions() |
961 |
* |
962 |
* @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. |
963 |
*/ |
964 |
public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
965 |
NamingRequestor requestor = new NamingRequestor(); |
966 |
InternalNamingConventions.suggestVariableNames( |
967 |
VK_LOCAL, |
968 |
BK_SIMPLE_TYPE_NAME, |
969 |
qualifiedTypeName, |
970 |
javaProject, |
971 |
dim, |
972 |
null, |
973 |
excludedNames, |
974 |
true, |
975 |
requestor); |
976 |
|
977 |
return requestor.getResults(); |
978 |
} |
979 |
/** |
980 |
* Suggest names for a local variable. The name is computed from variable's type |
981 |
* and possible prefixes or suffixes are added. |
982 |
* <p> |
983 |
* If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code> |
984 |
* and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code> |
985 |
* and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code> |
986 |
* and <code>name</code>. |
987 |
* </p> |
988 |
* <p> |
989 |
* This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and |
990 |
* {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. |
991 |
* </p> |
992 |
* <p> |
993 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
994 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
995 |
* </p> |
996 |
* |
997 |
* @param javaProject project which contains the variable. |
998 |
* @param packageName package of the variable's type. |
999 |
* @param qualifiedTypeName variable's type. |
1000 |
* @param dim variable's dimension (0 if the variable is not an array). |
1001 |
* @param excludedNames a list of names which cannot be suggested (already used names). |
1002 |
* Can be <code>null</code> if there is no excluded names. |
1003 |
* @return char[][] an array of names. |
1004 |
* @see JavaCore#setOptions(java.util.Hashtable) |
1005 |
* @see JavaCore#getDefaultOptions() |
1006 |
* |
1007 |
* @deprecated Use {@link #getVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. |
1008 |
*/ |
1009 |
public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
1010 |
return convertCharsToString( |
1011 |
suggestLocalVariableNames( |
1012 |
javaProject, |
1013 |
packageName.toCharArray(), |
1014 |
qualifiedTypeName.toCharArray(), |
1015 |
dim, |
1016 |
convertStringToChars(excludedNames))); |
1017 |
} |
1018 |
private static char[] suggestNewName(char[] name, char[][] excludedNames){ |
1019 |
if(excludedNames == null) { |
1020 |
return name; |
1021 |
} |
800 |
|
1022 |
|
|
|
1023 |
char[] newName = name; |
1024 |
int count = 2; |
1025 |
int i = 0; |
1026 |
while (i < excludedNames.length) { |
1027 |
if(CharOperation.equals(newName, excludedNames[i], false)) { |
1028 |
newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); |
1029 |
i = 0; |
1030 |
} else { |
1031 |
i++; |
1032 |
} |
1033 |
} |
1034 |
return newName; |
1035 |
} |
1036 |
|
801 |
/** |
1037 |
/** |
802 |
* Suggest name for a setter method. The name is computed from field's name |
1038 |
* Suggest name for a setter method. The name is computed from field's name |
803 |
* and possible prefixes or suffixes are removed. |
1039 |
* and possible prefixes or suffixes are removed. |
Lines 853-859
Link Here
|
853 |
); |
1089 |
); |
854 |
} |
1090 |
} |
855 |
} |
1091 |
} |
856 |
|
|
|
857 |
/** |
1092 |
/** |
858 |
* Suggest name for a setter method. The name is computed from field's name |
1093 |
* Suggest name for a setter method. The name is computed from field's name |
859 |
* and possible prefixes or suffixes are removed. |
1094 |
* and possible prefixes or suffixes are removed. |
Lines 893-945
Link Here
|
893 |
isBoolean, |
1128 |
isBoolean, |
894 |
convertStringToChars(excludedNames))); |
1129 |
convertStringToChars(excludedNames))); |
895 |
} |
1130 |
} |
896 |
|
1131 |
|
897 |
private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { |
1132 |
private NamingConventions() { |
898 |
char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); |
1133 |
// Not instantiable |
899 |
if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { |
|
|
900 |
name[0] = ScannerHelper.toUpperCase(name[0]); |
901 |
} |
902 |
return name; |
903 |
} |
904 |
|
905 |
private static char[] suggestNewName(char[] name, char[][] excludedNames){ |
906 |
if(excludedNames == null) { |
907 |
return name; |
908 |
} |
909 |
|
910 |
char[] newName = name; |
911 |
int count = 2; |
912 |
int i = 0; |
913 |
while (i < excludedNames.length) { |
914 |
if(CharOperation.equals(newName, excludedNames[i], false)) { |
915 |
newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); |
916 |
i = 0; |
917 |
} else { |
918 |
i++; |
919 |
} |
920 |
} |
921 |
return newName; |
922 |
} |
923 |
|
924 |
private static String[] convertCharsToString(char[][] c) { |
925 |
int length = c == null ? 0 : c.length; |
926 |
String[] s = new String[length]; |
927 |
for (int i = 0; i < length; i++) { |
928 |
s[i] = String.valueOf(c[i]); |
929 |
} |
930 |
return s; |
931 |
} |
932 |
|
933 |
private static char[][] convertStringToChars(String[] s) { |
934 |
int length = s == null ? 0 : s.length; |
935 |
char[][] c = new char[length][]; |
936 |
for (int i = 0; i < length; i++) { |
937 |
if(s[i] == null) { |
938 |
c[i] = CharOperation.NO_CHAR; |
939 |
} else { |
940 |
c[i] = s[i].toCharArray(); |
941 |
} |
942 |
} |
943 |
return c; |
944 |
} |
1134 |
} |
945 |
} |
1135 |
} |