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 name 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) { |
|
|
550 |
if(qualifiedTypeName == null || qualifiedTypeName.length == 0) |
551 |
return CharOperation.NO_CHAR_CHAR; |
552 |
|
553 |
char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); |
554 |
|
488 |
NamingRequestor requestor = new NamingRequestor(); |
555 |
NamingRequestor requestor = new NamingRequestor(); |
489 |
InternalNamingConventions.suggestArgumentNames( |
556 |
InternalNamingConventions.suggestVariableNames( |
490 |
javaProject, |
557 |
VK_PARAMETER, |
491 |
packageName, |
558 |
BK_TYPE_NAME, |
492 |
qualifiedTypeName, |
559 |
typeName, |
493 |
dim, |
560 |
javaProject, |
494 |
null, |
561 |
dim, |
495 |
excludedNames, |
562 |
null, |
496 |
requestor); |
563 |
excludedNames, |
|
|
564 |
true, |
565 |
requestor); |
497 |
|
566 |
|
498 |
return requestor.getResults(); |
567 |
return requestor.getResults(); |
499 |
} |
568 |
} |
Lines 525-530
Link Here
|
525 |
* @return char[][] an array of names. |
594 |
* @return char[][] an array of names. |
526 |
* @see JavaCore#setOptions(java.util.Hashtable) |
595 |
* @see JavaCore#setOptions(java.util.Hashtable) |
527 |
* @see JavaCore#getDefaultOptions() |
596 |
* @see JavaCore#getDefaultOptions() |
|
|
597 |
* |
598 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. |
528 |
*/ |
599 |
*/ |
529 |
public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
600 |
public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
530 |
return convertCharsToString( |
601 |
return convertCharsToString( |
Lines 535-540
Link Here
|
535 |
dim, |
606 |
dim, |
536 |
convertStringToChars(excludedNames))); |
607 |
convertStringToChars(excludedNames))); |
537 |
} |
608 |
} |
|
|
609 |
|
538 |
/** |
610 |
/** |
539 |
* Suggest names for a field. The name is computed from field's type |
611 |
* Suggest names for a field. The name is computed from field's type |
540 |
* and possible prefixes or suffixes are added. |
612 |
* and possible prefixes or suffixes are added. |
Lines 566-583
Link Here
|
566 |
* @see Flags |
638 |
* @see Flags |
567 |
* @see JavaCore#setOptions(java.util.Hashtable) |
639 |
* @see JavaCore#setOptions(java.util.Hashtable) |
568 |
* @see JavaCore#getDefaultOptions() |
640 |
* @see JavaCore#getDefaultOptions() |
|
|
641 |
* |
642 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead |
643 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
569 |
*/ |
644 |
*/ |
570 |
public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { |
645 |
public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { |
|
|
646 |
if(qualifiedTypeName == null || qualifiedTypeName.length == 0) |
647 |
return CharOperation.NO_CHAR_CHAR; |
648 |
|
649 |
char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); |
650 |
|
571 |
NamingRequestor requestor = new NamingRequestor(); |
651 |
NamingRequestor requestor = new NamingRequestor(); |
572 |
InternalNamingConventions.suggestFieldNames( |
652 |
InternalNamingConventions.suggestVariableNames( |
573 |
javaProject, |
653 |
Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, |
574 |
packageName, |
654 |
BK_TYPE_NAME, |
575 |
qualifiedTypeName, |
655 |
typeName, |
576 |
dim, |
656 |
javaProject, |
577 |
modifiers, |
657 |
dim, |
578 |
null, |
658 |
null, |
579 |
excludedNames, |
659 |
excludedNames, |
580 |
requestor); |
660 |
true, |
|
|
661 |
requestor); |
581 |
|
662 |
|
582 |
return requestor.getResults(); |
663 |
return requestor.getResults(); |
583 |
} |
664 |
} |
Lines 613-618
Link Here
|
613 |
* @see Flags |
694 |
* @see Flags |
614 |
* @see JavaCore#setOptions(java.util.Hashtable) |
695 |
* @see JavaCore#setOptions(java.util.Hashtable) |
615 |
* @see JavaCore#getDefaultOptions() |
696 |
* @see JavaCore#getDefaultOptions() |
|
|
697 |
* |
698 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead |
699 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
616 |
*/ |
700 |
*/ |
617 |
public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) { |
701 |
public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) { |
618 |
return convertCharsToString( |
702 |
return convertCharsToString( |
Lines 624-710
Link Here
|
624 |
modifiers, |
708 |
modifiers, |
625 |
convertStringToChars(excludedNames))); |
709 |
convertStringToChars(excludedNames))); |
626 |
} |
710 |
} |
627 |
|
711 |
|
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 |
/** |
712 |
/** |
709 |
* Suggest name for a getter method. The name is computed from field's name |
713 |
* Suggest name for a getter method. The name is computed from field's name |
710 |
* and possible prefixes or suffixes are removed. |
714 |
* and possible prefixes or suffixes are removed. |
Lines 756-762
Link Here
|
756 |
); |
760 |
); |
757 |
} |
761 |
} |
758 |
} |
762 |
} |
759 |
|
|
|
760 |
/** |
763 |
/** |
761 |
* Suggest name for a getter method. The name is computed from field's name |
764 |
* Suggest name for a getter method. The name is computed from field's name |
762 |
* and possible prefixes or suffixes are removed. |
765 |
* and possible prefixes or suffixes are removed. |
Lines 797-803
Link Here
|
797 |
isBoolean, |
800 |
isBoolean, |
798 |
convertStringToChars(excludedNames))); |
801 |
convertStringToChars(excludedNames))); |
799 |
} |
802 |
} |
|
|
803 |
/** |
804 |
* Suggest names for a local variable. The name is computed from variable's type |
805 |
* and possible prefixes or suffixes are added. |
806 |
* <p> |
807 |
* If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code> |
808 |
* and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code> |
809 |
* and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code> |
810 |
* and <code>name</code>. |
811 |
* </p> |
812 |
* <p> |
813 |
* This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and |
814 |
* {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. |
815 |
* </p> |
816 |
* <p> |
817 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
818 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
819 |
* </p> |
820 |
* |
821 |
* @param javaProject project which contains the variable. |
822 |
* @param packageName package of the variable's type. |
823 |
* @param qualifiedTypeName variable's type. |
824 |
* @param dim variable's dimension (0 if the variable is not an array). |
825 |
* @param excludedNames a list of names which cannot be suggested (already used names). |
826 |
* Can be <code>null</code> if there is no excluded names. |
827 |
* @return char[][] an array of names. |
828 |
* @see JavaCore#setOptions(java.util.Hashtable) |
829 |
* @see JavaCore#getDefaultOptions() |
830 |
* |
831 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. |
832 |
*/ |
833 |
public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
834 |
if(qualifiedTypeName == null || qualifiedTypeName.length == 0) |
835 |
return CharOperation.NO_CHAR_CHAR; |
836 |
|
837 |
char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); |
838 |
|
839 |
NamingRequestor requestor = new NamingRequestor(); |
840 |
InternalNamingConventions.suggestVariableNames( |
841 |
VK_LOCAL, |
842 |
BK_TYPE_NAME, |
843 |
typeName, |
844 |
javaProject, |
845 |
dim, |
846 |
null, |
847 |
excludedNames, |
848 |
true, |
849 |
requestor); |
800 |
|
850 |
|
|
|
851 |
return requestor.getResults(); |
852 |
} |
853 |
/** |
854 |
* Suggest names for a local variable. The name is computed from variable's type |
855 |
* and possible prefixes or suffixes are added. |
856 |
* <p> |
857 |
* If the type of the local variable is <code>TypeName</code>, the prefix for local variable is <code>pre</code> |
858 |
* and the suffix for local variable is <code>suf</code> then the proposed names are <code>preTypeNamesuf</code> |
859 |
* and <code>preNamesuf</code>. If there is no prefix or suffix the proposals are <code>typeName</code> |
860 |
* and <code>name</code>. |
861 |
* </p> |
862 |
* <p> |
863 |
* This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and |
864 |
* {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. |
865 |
* </p> |
866 |
* <p> |
867 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
868 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
869 |
* </p> |
870 |
* |
871 |
* @param javaProject project which contains the variable. |
872 |
* @param packageName package of the variable's type. |
873 |
* @param qualifiedTypeName variable's type. |
874 |
* @param dim variable's dimension (0 if the variable is not an array). |
875 |
* @param excludedNames a list of names which cannot be suggested (already used names). |
876 |
* Can be <code>null</code> if there is no excluded names. |
877 |
* @return char[][] an array of names. |
878 |
* @see JavaCore#setOptions(java.util.Hashtable) |
879 |
* @see JavaCore#getDefaultOptions() |
880 |
* |
881 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. |
882 |
*/ |
883 |
public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { |
884 |
return convertCharsToString( |
885 |
suggestLocalVariableNames( |
886 |
javaProject, |
887 |
packageName.toCharArray(), |
888 |
qualifiedTypeName.toCharArray(), |
889 |
dim, |
890 |
convertStringToChars(excludedNames))); |
891 |
} |
892 |
private static char[] suggestNewName(char[] name, char[][] excludedNames){ |
893 |
if(excludedNames == null) { |
894 |
return name; |
895 |
} |
896 |
|
897 |
char[] newName = name; |
898 |
int count = 2; |
899 |
int i = 0; |
900 |
while (i < excludedNames.length) { |
901 |
if(CharOperation.equals(newName, excludedNames[i], false)) { |
902 |
newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); |
903 |
i = 0; |
904 |
} else { |
905 |
i++; |
906 |
} |
907 |
} |
908 |
return newName; |
909 |
} |
910 |
|
801 |
/** |
911 |
/** |
802 |
* Suggest name for a setter method. The name is computed from field's name |
912 |
* Suggest name for a setter method. The name is computed from field's name |
803 |
* and possible prefixes or suffixes are removed. |
913 |
* and possible prefixes or suffixes are removed. |
Lines 853-859
Link Here
|
853 |
); |
963 |
); |
854 |
} |
964 |
} |
855 |
} |
965 |
} |
856 |
|
|
|
857 |
/** |
966 |
/** |
858 |
* Suggest name for a setter method. The name is computed from field's name |
967 |
* Suggest name for a setter method. The name is computed from field's name |
859 |
* and possible prefixes or suffixes are removed. |
968 |
* and possible prefixes or suffixes are removed. |
Lines 893-945
Link Here
|
893 |
isBoolean, |
1002 |
isBoolean, |
894 |
convertStringToChars(excludedNames))); |
1003 |
convertStringToChars(excludedNames))); |
895 |
} |
1004 |
} |
|
|
1005 |
|
1006 |
/** |
1007 |
* Suggests names for a variable. The name is computed from a base name and possible prefixes or suffixes are added. |
1008 |
* |
1009 |
* <p> |
1010 |
* The base name is used to compute the variable name. |
1011 |
* Some different kinds of base name are possible and each kind is associated to a different heuristic to compute variable names.<br> |
1012 |
* 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> |
1013 |
* When a prefix and a suffix can be added then all combinations of prefix and suffix are suggested. |
1014 |
* 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 |
1015 |
* <code>prenamesuf</code>, <code>prename</code>, <code>namesuf</code> and <code>name</code>.<br> |
1016 |
* <br> |
1017 |
* The different kinds of base name are: |
1018 |
* <ul> |
1019 |
* <li>{@link #BK_NAME}: the base name is a Java name and the whole base name is considered to compute the variable names. A prefix and a suffix can be added.<br> |
1020 |
* There is an heuristic by variable kind. |
1021 |
* <ul> |
1022 |
* <li>{@link #VK_PARAMETER}, {@link #VK_LOCAL}, {@link #VK_INSTANCE_FIELD} and {@link #VK_STATIC_FIELD}:<br> |
1023 |
* In this case the first character will be converted to lower case and the other characters won't be changed.<br> |
1024 |
* If the base name is <code>SimpleName</code> then the suggested name will be <code>simpleName</code>.<br></li> |
1025 |
* <li>{@link #VK_CONSTANT_FIELD} :<br> |
1026 |
* 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> |
1027 |
* If the base name is <code>SimpleName</code> then the suggested name will be <code>SIMPLE_NAME</code>.</li> |
1028 |
* </ul></li> |
1029 |
* <li>{@link #BK_TYPE_NAME}: the base name is a Java simple type name (e.g. <code>HashMap</code>) and all the words of the base name are considered to compute the variable names. A prefix and a suffix can be added to these names.<br> |
1030 |
* There is an heuristic by variable kind. |
1031 |
* <ul> |
1032 |
* <li>{@link #VK_PARAMETER}, {@link #VK_LOCAL}, {@link #VK_INSTANCE_FIELD} and {@link #VK_STATIC_FIELD}:<br> |
1033 |
* 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> |
1034 |
* If the type is <code>TypeName</code> then the suggested names will be <code>typeName</code> and <code>name</code>.</li> |
1035 |
* <li>{@link #VK_CONSTANT_FIELD} :<br> |
1036 |
* 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> |
1037 |
* If the base name is <code>TypeName</code> then the suggested name will be <code>TYPE_NAME</code> and <code>NAME</code>.</li> |
1038 |
* </ul></li> |
1039 |
* </ul> |
1040 |
* Some other kinds could be added in the future. |
1041 |
* </p> |
1042 |
* <p> |
1043 |
* Each variable kind is affected by the following JavaCore options: |
1044 |
* <ul> |
1045 |
* <li>{@link #VK_PARAMETER}: {@link JavaCore#CODEASSIST_ARGUMENT_PREFIXES} and {@link JavaCore#CODEASSIST_ARGUMENT_SUFFIXES}</li> |
1046 |
* <li>{@link #VK_LOCAL}: {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}</li> |
1047 |
* <li>{@link #VK_INSTANCE_FIELD}: {@link JavaCore#CODEASSIST_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_FIELD_SUFFIXES}</li> |
1048 |
* <li>{@link #VK_STATIC_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES}</li> |
1049 |
* <li>{@link #VK_CONSTANT_FIELD}: {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_PREFIXES} and {@link JavaCore#CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES}</li> |
1050 |
* </ul> |
1051 |
* </p> |
1052 |
* <p> |
1053 |
* For a complete description of these configurable options, see <code>getDefaultOptions</code>. |
1054 |
* For programmaticaly change these options, see <code>JavaCore#setOptions()</code>. |
1055 |
* </p> |
1056 |
* <p> |
1057 |
* Proposed names are sorted by relevance (best proposal first).<br> |
1058 |
* The names are proposed in the following order: |
1059 |
* <ol> |
1060 |
* <li>Names with prefix and suffix. Longest name are proposed first</li> |
1061 |
* <li>Names with prefix. Longest name are proposed first</li> |
1062 |
* <li>Names with suffix. Longest name are proposed first</li> |
1063 |
* <li>Names without prefix and suffix. Longest name are proposed first</li> |
1064 |
* </ol> |
1065 |
* </p> |
1066 |
* |
1067 |
* @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, |
1068 |
* {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. |
1069 |
* @param baseNameKind specifies what type the base name is: {@link #BK_NAME} or {@link #BK_TYPE_NAME} |
1070 |
* @param baseName name used to compute the suggested names. |
1071 |
* @param javaProject project which contains the variable or <code>null</code> to take into account only workspace settings. |
1072 |
* @param dim variable dimension (0 if the field is not an array). |
1073 |
* @param excluded a list of names which cannot be suggested (already used names). |
1074 |
* Can be <code>null</code> if there is no excluded names. |
1075 |
* @param evaluateDefault if set, the result is guaranteed to contain at least one result. If not, the result can be an empty array. |
1076 |
* @return String[] an array of names. |
1077 |
* @see JavaCore#setOptions(java.util.Hashtable) |
1078 |
* @see JavaCore#getDefaultOptions() |
1079 |
* |
1080 |
* @since 3.5 |
1081 |
*/ |
1082 |
public static String[] suggestVariableNames( |
1083 |
int variableKind, |
1084 |
int baseNameKind, |
1085 |
String baseName, |
1086 |
IJavaProject javaProject, |
1087 |
int dim, |
1088 |
String[] excluded, |
1089 |
boolean evaluateDefault) { |
1090 |
|
1091 |
NamingRequestor requestor = new NamingRequestor(); |
1092 |
InternalNamingConventions.suggestVariableNames( |
1093 |
variableKind, |
1094 |
baseNameKind, |
1095 |
baseName.toCharArray(), |
1096 |
javaProject, |
1097 |
dim, |
1098 |
null, |
1099 |
convertStringToChars(excluded), |
1100 |
evaluateDefault, |
1101 |
requestor); |
896 |
|
1102 |
|
897 |
private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { |
1103 |
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 |
} |
1104 |
} |
932 |
|
1105 |
|
933 |
private static char[][] convertStringToChars(String[] s) { |
1106 |
private NamingConventions() { |
934 |
int length = s == null ? 0 : s.length; |
1107 |
// 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 |
} |
1108 |
} |
945 |
} |
1109 |
} |