1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core;
13 import net.sourceforge.phpdt.core.compiler.CharOperation;
14 import net.sourceforge.phpdt.internal.codeassist.impl.AssistOptions;
15 import net.sourceforge.phpdt.internal.core.INamingRequestor;
16 import net.sourceforge.phpdt.internal.core.InternalNamingConventions;
19 * Provides methods for computing Java-specific names.
21 * The behavior of the methods is dependent of several JavaCore options.
23 * The possible options are :
25 * <li>CODEASSIST_FIELD_PREFIXES : Define the Prefixes for Field Name.</li>
26 * <li>CODEASSIST_STATIC_FIELD_PREFIXES : Define the Prefixes for Static Field
28 * <li>CODEASSIST_LOCAL_PREFIXES : Define the Prefixes for Local Variable Name.</li>
29 * <li>CODEASSIST_ARGUMENT_PREFIXES : Define the Prefixes for Argument Name.</li>
30 * <li>CODEASSIST_FIELD_SUFFIXES : Define the Suffixes for Field Name.</li>
31 * <li>CODEASSIST_STATIC_FIELD_SUFFIXES : Define the Suffixes for Static Field
33 * <li>CODEASSIST_LOCAL_SUFFIXES : Define the Suffixes for Local Variable Name.</li>
34 * <li>CODEASSIST_ARGUMENT_SUFFIXES : Define the Suffixes for Argument Name.</li>
38 * For a complete description of the configurable options, see
39 * <code>getDefaultOptions</code>. For programmaticaly change these options,
40 * see <code>JavaCore#setOptions()</code>.
43 * This class provides static methods and constants only; it is not intended to
44 * be instantiated or subclassed by clients.
47 * @see JavaCore#setOptions(java.util.Hashtable)
48 * @see JavaCore#getDefaultOptions()
51 public final class NamingConventions {
52 private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$
54 private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$
56 private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$
58 private static class NamingRequestor implements INamingRequestor {
59 private final static int SIZE = 10;
61 // for acceptNameWithPrefixAndSuffix
62 private char[][] firstPrefixAndFirstSuffixResults = new char[SIZE][];
64 private int firstPrefixAndFirstSuffixResultsCount = 0;
66 private char[][] firstPrefixAndSuffixResults = new char[SIZE][];
68 private int firstPrefixAndSuffixResultsCount = 0;
70 private char[][] prefixAndFirstSuffixResults = new char[SIZE][];
72 private int prefixAndFirstSuffixResultsCount = 0;
74 private char[][] prefixAndSuffixResults = new char[SIZE][];
76 private int prefixAndSuffixResultsCount = 0;
78 // for acceptNameWithPrefix
79 private char[][] firstPrefixResults = new char[SIZE][];
81 private int firstPrefixResultsCount = 0;
83 private char[][] prefixResults = new char[SIZE][];
85 private int prefixResultsCount = 0;
87 // for acceptNameWithSuffix
88 private char[][] firstSuffixResults = new char[SIZE][];
90 private int firstSuffixResultsCount = 0;
92 private char[][] suffixResults = new char[SIZE][];
94 private int suffixResultsCount = 0;
96 // for acceptNameWithoutPrefixAndSuffix
97 private char[][] otherResults = new char[SIZE][];
99 private int otherResultsCount = 0;
101 public void acceptNameWithPrefixAndSuffix(char[] name,
102 boolean isFirstPrefix, boolean isFirstSuffix) {
103 if (isFirstPrefix && isFirstSuffix) {
104 int length = this.firstPrefixAndFirstSuffixResults.length;
105 if (length == this.firstPrefixAndFirstSuffixResultsCount) {
108 this.firstPrefixAndFirstSuffixResults,
110 this.firstPrefixAndFirstSuffixResults = new char[length * 2][],
113 this.firstPrefixAndFirstSuffixResults[this.firstPrefixAndFirstSuffixResultsCount++] = name;
114 } else if (isFirstPrefix) {
115 int length = this.firstPrefixAndSuffixResults.length;
116 if (length == this.firstPrefixAndSuffixResultsCount) {
119 this.firstPrefixAndSuffixResults,
121 this.firstPrefixAndSuffixResults = new char[length * 2][],
124 this.firstPrefixAndSuffixResults[this.firstPrefixAndSuffixResultsCount++] = name;
125 } else if (isFirstSuffix) {
126 int length = this.prefixAndFirstSuffixResults.length;
127 if (length == this.prefixAndFirstSuffixResultsCount) {
130 this.prefixAndFirstSuffixResults,
132 this.prefixAndFirstSuffixResults = new char[length * 2][],
135 this.prefixAndFirstSuffixResults[this.prefixAndFirstSuffixResultsCount++] = name;
137 int length = this.prefixAndSuffixResults.length;
138 if (length == this.prefixAndSuffixResultsCount) {
141 this.prefixAndSuffixResults,
143 this.prefixAndSuffixResults = new char[length * 2][],
146 this.prefixAndSuffixResults[this.prefixAndSuffixResultsCount++] = name;
150 public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix) {
152 int length = this.firstPrefixResults.length;
153 if (length == this.firstPrefixResultsCount) {
154 System.arraycopy(this.firstPrefixResults, 0,
155 this.firstPrefixResults = new char[length * 2][],
158 this.firstPrefixResults[this.firstPrefixResultsCount++] = name;
160 int length = this.prefixResults.length;
161 if (length == this.prefixResultsCount) {
162 System.arraycopy(this.prefixResults, 0,
163 this.prefixResults = new char[length * 2][], 0,
166 this.prefixResults[this.prefixResultsCount++] = name;
170 public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix) {
172 int length = this.firstSuffixResults.length;
173 if (length == this.firstSuffixResultsCount) {
174 System.arraycopy(this.firstSuffixResults, 0,
175 this.firstSuffixResults = new char[length * 2][],
178 this.firstSuffixResults[this.firstSuffixResultsCount++] = name;
180 int length = this.suffixResults.length;
181 if (length == this.suffixResultsCount) {
182 System.arraycopy(this.suffixResults, 0,
183 this.suffixResults = new char[length * 2][], 0,
186 this.suffixResults[this.suffixResultsCount++] = name;
190 public void acceptNameWithoutPrefixAndSuffix(char[] name) {
191 int length = this.otherResults.length;
192 if (length == this.otherResultsCount) {
193 System.arraycopy(this.otherResults, 0,
194 this.otherResults = new char[length * 2][], 0, length);
196 this.otherResults[this.otherResultsCount++] = name;
199 public char[][] getResults() {
200 int count = this.firstPrefixAndFirstSuffixResultsCount
201 + this.firstPrefixAndSuffixResultsCount
202 + this.prefixAndFirstSuffixResultsCount
203 + this.prefixAndSuffixResultsCount
204 + this.firstPrefixResultsCount + this.prefixResultsCount
205 + this.firstSuffixResultsCount + this.suffixResultsCount
206 + this.otherResultsCount;
208 char[][] results = new char[count][];
211 System.arraycopy(this.firstPrefixAndFirstSuffixResults, 0, results,
212 index, this.firstPrefixAndFirstSuffixResultsCount);
213 index += this.firstPrefixAndFirstSuffixResultsCount;
214 System.arraycopy(this.firstPrefixAndSuffixResults, 0, results,
215 index, this.firstPrefixAndSuffixResultsCount);
216 index += this.firstPrefixAndSuffixResultsCount;
217 System.arraycopy(this.prefixAndFirstSuffixResults, 0, results,
218 index, this.prefixAndFirstSuffixResultsCount);
219 index += this.prefixAndFirstSuffixResultsCount;
220 System.arraycopy(this.prefixAndSuffixResults, 0, results, index,
221 this.prefixAndSuffixResultsCount);
222 index += this.prefixAndSuffixResultsCount;
223 System.arraycopy(this.firstPrefixResults, 0, results, index,
224 this.firstPrefixResultsCount);
225 index += this.firstPrefixResultsCount;
226 System.arraycopy(this.prefixResults, 0, results, index,
227 this.prefixResultsCount);
228 index += this.prefixResultsCount;
229 System.arraycopy(this.firstSuffixResults, 0, results, index,
230 this.firstSuffixResultsCount);
231 index += this.firstSuffixResultsCount;
232 System.arraycopy(this.suffixResults, 0, results, index,
233 this.suffixResultsCount);
234 index += this.suffixResultsCount;
235 System.arraycopy(this.otherResults, 0, results, index,
236 this.otherResultsCount);
242 private NamingConventions() {
246 private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes,
248 // remove longer prefix
249 char[] withoutPrefixName = name;
250 if (prefixes != null) {
252 for (int i = 0; i < prefixes.length; i++) {
253 char[] prefix = prefixes[i];
254 if (CharOperation.prefixEquals(prefix, name)) {
255 int currLen = prefix.length;
256 boolean lastCharIsLetter = Character
257 .isLetter(prefix[currLen - 1]);
258 if (!lastCharIsLetter
259 || (lastCharIsLetter && name.length > currLen && Character
260 .isUpperCase(name[currLen]))) {
261 if (bestLength < currLen && name.length != currLen) {
262 withoutPrefixName = CharOperation.subarray(name,
263 currLen, name.length);
264 bestLength = currLen;
271 // remove longer suffix
272 char[] withoutSuffixName = withoutPrefixName;
273 if (suffixes != null) {
275 for (int i = 0; i < suffixes.length; i++) {
276 char[] suffix = suffixes[i];
277 if (CharOperation.endsWith(withoutPrefixName, suffix)) {
278 int currLen = suffix.length;
279 if (bestLength < currLen
280 && withoutPrefixName.length != currLen) {
281 withoutSuffixName = CharOperation.subarray(
282 withoutPrefixName, 0, withoutPrefixName.length
284 bestLength = currLen;
290 withoutSuffixName[0] = Character.toLowerCase(withoutSuffixName[0]);
291 return withoutSuffixName;
295 * Remove prefix and suffix from an argument name.
297 * If argument name prefix is <code>pre</code> and argument name suffix is
298 * <code>suf</code> then for an argument named <code>preArgsuf</code>
299 * the result of this method is <code>arg</code>. If there is no prefix
300 * or suffix defined in JavaCore options the result is the unchanged name
301 * <code>preArgsuf</code>.
304 * This method is affected by the following JavaCore options :
305 * CODEASSIST_ARGUMENT_PREFIXES and CODEASSIST_ARGUMENT_SUFFIXES.
308 * For a complete description of these configurable options, see
309 * <code>getDefaultOptions</code>. For programmaticaly change these
310 * options, see <code>JavaCore#setOptions()</code>.
314 * project which contains the argument.
315 * @param argumentName
317 * @return char[] the name without prefix and suffix.
318 * @see JavaCore#setOptions(java.util.Hashtable)
319 * @see JavaCore#getDefaultOptions()
321 public static char[] removePrefixAndSuffixForArgumentName(
322 IJavaProject javaProject, char[] argumentName) {
323 AssistOptions assistOptions = new AssistOptions(javaProject
325 return removePrefixAndSuffix(argumentName,
326 assistOptions.argumentPrefixes, assistOptions.argumentSuffixes);
330 * Remove prefix and suffix from an argument name.
332 * If argument name prefix is <code>pre</code> and argument name suffix is
333 * <code>suf</code> then for an argument named <code>preArgsuf</code>
334 * the result of this method is <code>arg</code>. If there is no prefix
335 * or suffix defined in JavaCore options the result is the unchanged name
336 * <code>preArgsuf</code>.
339 * This method is affected by the following JavaCore options :
340 * CODEASSIST_ARGUMENT_PREFIXES and CODEASSIST_ARGUMENT_SUFFIXES.
343 * For a complete description of these configurable options, see
344 * <code>getDefaultOptions</code>. For programmaticaly change these
345 * options, see <code>JavaCore#setOptions()</code>.
349 * project which contains the argument.
350 * @param argumentName
352 * @return char[] the name without prefix and suffix.
353 * @see JavaCore#setOptions(java.util.Hashtable)
354 * @see JavaCore#getDefaultOptions()
356 public static String removePrefixAndSuffixForArgumentName(
357 IJavaProject javaProject, String argumentName) {
358 return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject,
359 argumentName.toCharArray()));
363 * Remove prefix and suffix from a field name.
365 * If field name prefix is <code>pre</code> and field name suffix is
366 * <code>suf</code> then for a field named <code>preFieldsuf</code> the
367 * result of this method is <code>field</code>. If there is no prefix or
368 * suffix defined in JavaCore options the result is the unchanged name
369 * <code>preFieldsuf</code>.
372 * This method is affected by the following JavaCore options :
373 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES for instance field
374 * and CODEASSIST_STATIC_FIELD_PREFIXES, CODEASSIST_STATIC_FIELD_SUFFIXES
378 * For a complete description of these configurable options, see
379 * <code>getDefaultOptions</code>. For programmaticaly change these
380 * options, see <code>JavaCore#setOptions()</code>.
384 * project which contains the field.
388 * field's modifiers as defined by the class <code>Flags</code>.
389 * @return char[] the name without prefix and suffix.
391 * @see JavaCore#setOptions(java.util.Hashtable)
392 * @see JavaCore#getDefaultOptions()
394 public static char[] removePrefixAndSuffixForFieldName(
395 IJavaProject javaProject, char[] fieldName, int modifiers) {
396 boolean isStatic = Flags.isStatic(modifiers);
397 AssistOptions assistOptions = new AssistOptions(javaProject
399 return removePrefixAndSuffix(fieldName,
400 isStatic ? assistOptions.staticFieldPrefixes
401 : assistOptions.fieldPrefixes,
402 isStatic ? assistOptions.staticFieldSuffixes
403 : assistOptions.fieldSuffixes);
407 * Remove prefix and suffix from a field name.
409 * If field name prefix is <code>pre</code> and field name suffix is
410 * <code>suf</code> then for a field named <code>preFieldsuf</code> the
411 * result of this method is <code>field</code>. If there is no prefix or
412 * suffix defined in JavaCore options the result is the unchanged name
413 * <code>preFieldsuf</code>.
416 * This method is affected by the following JavaCore options :
417 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES for instance field
418 * and CODEASSIST_STATIC_FIELD_PREFIXES, CODEASSIST_STATIC_FIELD_SUFFIXES
422 * For a complete description of these configurable options, see
423 * <code>getDefaultOptions</code>. For programmaticaly change these
424 * options, see <code>JavaCore#setOptions()</code>.
428 * project which contains the field.
432 * field's modifiers as defined by the class <code>Flags</code>.
433 * @return char[] the name without prefix and suffix.
435 * @see JavaCore#setOptions(java.util.Hashtable)
436 * @see JavaCore#getDefaultOptions()
438 public static String removePrefixAndSuffixForFieldName(
439 IJavaProject javaProject, String fieldName, int modifiers) {
440 return String.valueOf(removePrefixAndSuffixForFieldName(javaProject,
441 fieldName.toCharArray(), modifiers));
445 * Remove prefix and suffix from a local variable name.
447 * If local variable name prefix is <code>pre</code> and local variable
448 * name suffix is <code>suf</code> then for a local variable named
449 * <code>preLocalsuf</code> the result of this method is
450 * <code>local</code>. If there is no prefix or suffix defined in
451 * JavaCore options the result is the unchanged name
452 * <code>preLocalsuf</code>.
455 * This method is affected by the following JavaCore options :
456 * CODEASSIST_LOCAL_PREFIXES and CODEASSIST_LOCAL_SUFFIXES.
459 * For a complete description of these configurable options, see
460 * <code>getDefaultOptions</code>. For programmaticaly change these
461 * options, see <code>JavaCore#setOptions()</code>.
465 * project which contains the variable.
468 * @return char[] the name without prefix and suffix.
469 * @see JavaCore#setOptions(java.util.Hashtable)
470 * @see JavaCore#getDefaultOptions()
472 public static char[] removePrefixAndSuffixForLocalVariableName(
473 IJavaProject javaProject, char[] localName) {
474 AssistOptions assistOptions = new AssistOptions(javaProject
476 return removePrefixAndSuffix(localName, assistOptions.argumentPrefixes,
477 assistOptions.argumentSuffixes);
481 * Remove prefix and suffix from a local variable name.
483 * If local variable name prefix is <code>pre</code> and local variable
484 * name suffix is <code>suf</code> then for a local variable named
485 * <code>preLocalsuf</code> the result of this method is
486 * <code>local</code>. If there is no prefix or suffix defined in
487 * JavaCore options the result is the unchanged name
488 * <code>preLocalsuf</code>.
491 * This method is affected by the following JavaCore options :
492 * CODEASSIST_LOCAL_PREFIXES and CODEASSIST_LOCAL_SUFFIXES.
495 * For a complete description of these configurable options, see
496 * <code>getDefaultOptions</code>. For programmaticaly change these
497 * options, see <code>JavaCore#setOptions()</code>.
501 * project which contains the variable.
504 * @return char[] the name without prefix and suffix.
505 * @see JavaCore#setOptions(java.util.Hashtable)
506 * @see JavaCore#getDefaultOptions()
508 public static String removePrefixAndSuffixForLocalVariableName(
509 IJavaProject javaProject, String localName) {
510 return String.valueOf(removePrefixAndSuffixForLocalVariableName(
511 javaProject, localName.toCharArray()));
515 * Suggest names for an argument. The name is computed from argument's type
516 * and possible prefixes or suffixes are added.
518 * If the type of the argument is <code>TypeName</code>, the prefix for
519 * argument is <code>pre</code> and the suffix for argument is
520 * <code>suf</code> then the proposed names are
521 * <code>preTypeNamesuf</code> and <code>preNamesuf</code>. If there is
522 * no prefix or suffix the proposals are <code>typeName</code> and
526 * This method is affected by the following JavaCore options :
527 * CODEASSIST_ARGUMENT_PREFIXES and CODEASSIST_ARGUMENT_SUFFIXES.
530 * For a complete description of these configurable options, see
531 * <code>getDefaultOptions</code>. For programmaticaly change these
532 * options, see <code>JavaCore#setOptions()</code>.
536 * project which contains the argument.
538 * package of the argument's type.
539 * @param qualifiedTypeName
542 * argument's dimension (0 if the argument is not an array).
543 * @param excludedNames
544 * a list of names which cannot be suggested (already used
545 * names). Can be <code>null</code> if there is no excluded
547 * @return char[][] an array of names.
548 * @see JavaCore#setOptions(java.util.Hashtable)
549 * @see JavaCore#getDefaultOptions()
551 public static char[][] suggestArgumentNames(IJavaProject javaProject,
552 char[] packageName, char[] qualifiedTypeName, int dim,
553 char[][] excludedNames) {
554 NamingRequestor requestor = new NamingRequestor();
555 InternalNamingConventions.suggestArgumentNames(javaProject,
556 packageName, qualifiedTypeName, dim, excludedNames, requestor);
558 return requestor.getResults();
562 * Suggest names for an argument. The name is computed from argument's type
563 * and possible prefixes or suffixes are added.
565 * If the type of the argument is <code>TypeName</code>, the prefix for
566 * argument is <code>pre</code> and the suffix for argument is
567 * <code>suf</code> then the proposed names are
568 * <code>preTypeNamesuf</code> and <code>preNamesuf</code>. If there is
569 * no prefix or suffix the proposals are <code>typeName</code> and
573 * This method is affected by the following JavaCore options :
574 * CODEASSIST_ARGUMENT_PREFIXES and CODEASSIST_ARGUMENT_SUFFIXES.
577 * For a complete description of these configurable options, see
578 * <code>getDefaultOptions</code>. For programmaticaly change these
579 * options, see <code>JavaCore#setOptions()</code>.
583 * project which contains the argument.
585 * package of the argument's type.
586 * @param qualifiedTypeName
589 * argument's dimension (0 if the argument is not an array).
590 * @param excludedNames
591 * a list of names which cannot be suggested (already used
592 * names). Can be <code>null</code> if there is no excluded
594 * @return char[][] an array of names.
595 * @see JavaCore#setOptions(java.util.Hashtable)
596 * @see JavaCore#getDefaultOptions()
598 public static String[] suggestArgumentNames(IJavaProject javaProject,
599 String packageName, String qualifiedTypeName, int dim,
600 String[] excludedNames) {
601 return convertCharsToString(suggestArgumentNames(javaProject,
602 packageName.toCharArray(), qualifiedTypeName.toCharArray(),
603 dim, convertStringToChars(excludedNames)));
607 * Suggest names for a field. The name is computed from field's type and
608 * possible prefixes or suffixes are added.
610 * If the type of the field is <code>TypeName</code>, the prefix for
611 * field is <code>pre</code> and the suffix for field is <code>suf</code>
612 * then the proposed names are <code>preTypeNamesuf</code> and
613 * <code>preNamesuf</code>. If there is no prefix or suffix the proposals
614 * are <code>typeName</code> and <code>name</code>.
617 * This method is affected by the following JavaCore options :
618 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES and for instance
619 * field and CODEASSIST_STATIC_FIELD_PREFIXES,
620 * CODEASSIST_STATIC_FIELD_SUFFIXES for static field.
623 * For a complete description of these configurable options, see
624 * <code>getDefaultOptions</code>. For programmaticaly change these
625 * options, see <code>JavaCore#setOptions()</code>.
629 * project which contains the field.
631 * package of the field's type.
632 * @param qualifiedTypeName
635 * field's dimension (0 if the field is not an array).
637 * field's modifiers as defined by the class <code>Flags</code>.
638 * @param excludedNames
639 * a list of names which cannot be suggested (already used
640 * names). Can be <code>null</code> if there is no excluded
642 * @return char[][] an array of names.
644 * @see JavaCore#setOptions(java.util.Hashtable)
645 * @see JavaCore#getDefaultOptions()
647 public static char[][] suggestFieldNames(IJavaProject javaProject,
648 char[] packageName, char[] qualifiedTypeName, int dim,
649 int modifiers, char[][] excludedNames) {
650 NamingRequestor requestor = new NamingRequestor();
651 InternalNamingConventions.suggestFieldNames(javaProject, packageName,
652 qualifiedTypeName, dim, modifiers, excludedNames, requestor);
654 return requestor.getResults();
658 * Suggest names for a field. The name is computed from field's type and
659 * possible prefixes or suffixes are added.
661 * If the type of the field is <code>TypeName</code>, the prefix for
662 * field is <code>pre</code> and the suffix for field is <code>suf</code>
663 * then the proposed names are <code>preTypeNamesuf</code> and
664 * <code>preNamesuf</code>. If there is no prefix or suffix the proposals
665 * are <code>typeName</code> and <code>name</code>.
668 * This method is affected by the following JavaCore options :
669 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES and for instance
670 * field and CODEASSIST_STATIC_FIELD_PREFIXES,
671 * CODEASSIST_STATIC_FIELD_SUFFIXES for static field.
674 * For a complete description of these configurable options, see
675 * <code>getDefaultOptions</code>. For programmaticaly change these
676 * options, see <code>JavaCore#setOptions()</code>.
680 * project which contains the field.
682 * package of the field's type.
683 * @param qualifiedTypeName
686 * field's dimension (0 if the field is not an array).
688 * field's modifiers as defined by the class <code>Flags</code>.
689 * @param excludedNames
690 * a list of names which cannot be suggested (already used
691 * names). Can be <code>null</code> if there is no excluded
693 * @return char[][] an array of names.
695 * @see JavaCore#setOptions(java.util.Hashtable)
696 * @see JavaCore#getDefaultOptions()
698 public static String[] suggestFieldNames(IJavaProject javaProject,
699 String packageName, String qualifiedTypeName, int dim,
700 int modifiers, String[] excludedNames) {
701 return convertCharsToString(suggestFieldNames(javaProject, packageName
702 .toCharArray(), qualifiedTypeName.toCharArray(), dim,
703 modifiers, convertStringToChars(excludedNames)));
707 * Suggest names for a local variable. The name is computed from variable's
708 * type and possible prefixes or suffixes are added.
710 * If the type of the local variable is <code>TypeName</code>, the prefix
711 * for local variable is <code>pre</code> and the suffix for local
712 * variable is <code>suf</code> then the proposed names are
713 * <code>preTypeNamesuf</code> and <code>preNamesuf</code>. If there is
714 * no prefix or suffix the proposals are <code>typeName</code> and
718 * This method is affected by the following JavaCore options :
719 * CODEASSIST_LOCAL_PREFIXES and CODEASSIST_LOCAL_SUFFIXES.
722 * For a complete description of these configurable options, see
723 * <code>getDefaultOptions</code>. For programmaticaly change these
724 * options, see <code>JavaCore#setOptions()</code>.
728 * project which contains the variable.
730 * package of the variable's type.
731 * @param qualifiedTypeName
734 * variable's dimension (0 if the variable is not an array).
735 * @param excludedNames
736 * a list of names which cannot be suggested (already used
737 * names). Can be <code>null</code> if there is no excluded
739 * @return char[][] an array of names.
740 * @see JavaCore#setOptions(java.util.Hashtable)
741 * @see JavaCore#getDefaultOptions()
743 public static char[][] suggestLocalVariableNames(IJavaProject javaProject,
744 char[] packageName, char[] qualifiedTypeName, int dim,
745 char[][] excludedNames) {
746 NamingRequestor requestor = new NamingRequestor();
747 InternalNamingConventions.suggestLocalVariableNames(javaProject,
748 packageName, qualifiedTypeName, dim, excludedNames, requestor);
750 return requestor.getResults();
754 * Suggest names for a local variable. The name is computed from variable's
755 * type and possible prefixes or suffixes are added.
757 * If the type of the local variable is <code>TypeName</code>, the prefix
758 * for local variable is <code>pre</code> and the suffix for local
759 * variable is <code>suf</code> then the proposed names are
760 * <code>preTypeNamesuf</code> and <code>preNamesuf</code>. If there is
761 * no prefix or suffix the proposals are <code>typeName</code> and
765 * This method is affected by the following JavaCore options :
766 * CODEASSIST_LOCAL_PREFIXES and CODEASSIST_LOCAL_SUFFIXES.
769 * For a complete description of these configurable options, see
770 * <code>getDefaultOptions</code>. For programmaticaly change these
771 * options, see <code>JavaCore#setOptions()</code>.
775 * project which contains the variable.
777 * package of the variable's type.
778 * @param qualifiedTypeName
781 * variable's dimension (0 if the variable is not an array).
782 * @param excludedNames
783 * a list of names which cannot be suggested (already used
784 * names). Can be <code>null</code> if there is no excluded
786 * @return char[][] an array of names.
787 * @see JavaCore#setOptions(java.util.Hashtable)
788 * @see JavaCore#getDefaultOptions()
790 public static String[] suggestLocalVariableNames(IJavaProject javaProject,
791 String packageName, String qualifiedTypeName, int dim,
792 String[] excludedNames) {
793 return convertCharsToString(suggestLocalVariableNames(javaProject,
794 packageName.toCharArray(), qualifiedTypeName.toCharArray(),
795 dim, convertStringToChars(excludedNames)));
799 * Suggest name for a getter method. The name is computed from field's name
800 * and possible prefixes or suffixes are removed.
802 * If the field name is <code>preFieldNamesuf</code> and the prefix for
803 * field is <code>pre</code> and the suffix for field is <code>suf</code>
804 * then the prosposed name is <code>isFieldName</code> for boolean field
805 * or <code>getFieldName</code> for others. If there is no prefix and
806 * suffix the proposal is <code>isPreFieldNamesuf</code> for boolean field
807 * or <code>getPreFieldNamesuf</code> for others.
810 * This method is affected by the following JavaCore options :
811 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES for instance field
812 * and CODEASSIST_STATIC_FIELD_PREFIXES, CODEASSIST_STATIC_FIELD_SUFFIXES
816 * For a complete description of these configurable options, see
817 * <code>getDefaultOptions</code>. For programmaticaly change these
818 * options, see <code>JavaCore#setOptions()</code>.
822 * project which contains the field.
826 * field's modifiers as defined by the class <code>Flags</code>.
828 * <code>true</code> if the field's type is boolean
829 * @param excludedNames
830 * a list of names which cannot be suggested (already used
831 * names). Can be <code>null</code> if there is no excluded
833 * @return char[] a name.
835 * @see JavaCore#setOptions(java.util.Hashtable)
836 * @see JavaCore#getDefaultOptions()
838 public static char[] suggestGetterName(IJavaProject project,
839 char[] fieldName, int modifiers, boolean isBoolean,
840 char[][] excludedNames) {
842 char[] name = removePrefixAndSuffixForFieldName(project, fieldName,
844 int prefixLen = GETTER_BOOL_NAME.length;
845 if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name)
846 && name.length > prefixLen
847 && Character.isUpperCase(name[prefixLen])) {
848 return suggestNewName(name, excludedNames);
850 return suggestNewName(CharOperation.concat(GETTER_BOOL_NAME,
851 suggestAccessorName(project, fieldName, modifiers)),
855 return suggestNewName(CharOperation.concat(GETTER_NAME,
856 suggestAccessorName(project, fieldName, modifiers)),
862 * Suggest name for a getter method. The name is computed from field's name
863 * and possible prefixes or suffixes are removed.
865 * If the field name is <code>preFieldNamesuf</code> and the prefix for
866 * field is <code>pre</code> and the suffix for field is <code>suf</code>
867 * then the prosposed name is <code>isFieldName</code> for boolean field
868 * or <code>getFieldName</code> for others. If there is no prefix and
869 * suffix the proposal is <code>isPreFieldNamesuf</code> for boolean field
870 * or <code>getPreFieldNamesuf</code> for others.
873 * This method is affected by the following JavaCore options :
874 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES for instance field
875 * and CODEASSIST_STATIC_FIELD_PREFIXES, CODEASSIST_STATIC_FIELD_SUFFIXES
879 * For a complete description of these configurable options, see
880 * <code>getDefaultOptions</code>. For programmaticaly change these
881 * options, see <code>JavaCore#setOptions()</code>.
885 * project which contains the field.
889 * field's modifiers as defined by the class <code>Flags</code>.
891 * <code>true</code> if the field's type is boolean
892 * @param excludedNames
893 * a list of names which cannot be suggested (already used
894 * names). Can be <code>null</code> if there is no excluded
896 * @return char[] a name.
898 * @see JavaCore#setOptions(java.util.Hashtable)
899 * @see JavaCore#getDefaultOptions()
901 public static String suggestGetterName(IJavaProject project,
902 String fieldName, int modifiers, boolean isBoolean,
903 String[] excludedNames) {
904 return String.valueOf(suggestGetterName(project, fieldName
905 .toCharArray(), modifiers, isBoolean,
906 convertStringToChars(excludedNames)));
910 * Suggest name for a setter method. The name is computed from field's name
911 * and possible prefixes or suffixes are removed.
913 * If the field name is <code>preFieldNamesuf</code> and the prefix for
914 * field is <code>pre</code> and the suffix for field is <code>suf</code>
915 * then the proposed name is <code>setFieldName</code>. If there is no
916 * prefix and suffix the proposal is <code>setPreFieldNamesuf</code>.
919 * This method is affected by the following JavaCore options :
920 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES for instance field
921 * and CODEASSIST_STATIC_FIELD_PREFIXES, CODEASSIST_STATIC_FIELD_SUFFIXES
925 * For a complete description of these configurable options, see
926 * <code>getDefaultOptions</code>. For programmaticaly change these
927 * options, see <code>JavaCore#setOptions()</code>.
931 * project which contains the field.
935 * field's modifiers as defined by the class <code>Flags</code>.
937 * <code>true</code> if the field's type is boolean
938 * @param excludedNames
939 * a list of names which cannot be suggested (already used
940 * names). Can be <code>null</code> if there is no excluded
942 * @return char[] a name.
944 * @see JavaCore#setOptions(java.util.Hashtable)
945 * @see JavaCore#getDefaultOptions()
947 public static char[] suggestSetterName(IJavaProject project,
948 char[] fieldName, int modifiers, boolean isBoolean,
949 char[][] excludedNames) {
952 char[] name = removePrefixAndSuffixForFieldName(project, fieldName,
954 int prefixLen = GETTER_BOOL_NAME.length;
955 if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name)
956 && name.length > prefixLen
957 && Character.isUpperCase(name[prefixLen])) {
958 name = CharOperation.subarray(name, prefixLen, name.length);
959 return suggestNewName(CharOperation.concat(SETTER_NAME,
960 suggestAccessorName(project, name, modifiers)),
963 return suggestNewName(CharOperation.concat(SETTER_NAME,
964 suggestAccessorName(project, fieldName, modifiers)),
968 return suggestNewName(CharOperation.concat(SETTER_NAME,
969 suggestAccessorName(project, fieldName, modifiers)),
975 * Suggest name for a setter method. The name is computed from field's name
976 * and possible prefixes or suffixes are removed.
978 * If the field name is <code>preFieldNamesuf</code> and the prefix for
979 * field is <code>pre</code> and the suffix for field is <code>suf</code>
980 * then the proposed name is <code>setFieldName</code>. If there is no
981 * prefix and suffix the proposal is <code>setPreFieldNamesuf</code>.
984 * This method is affected by the following JavaCore options :
985 * CODEASSIST_FIELD_PREFIXES, CODEASSIST_FIELD_SUFFIXES for instance field
986 * and CODEASSIST_STATIC_FIELD_PREFIXES, CODEASSIST_STATIC_FIELD_SUFFIXES
990 * For a complete description of these configurable options, see
991 * <code>getDefaultOptions</code>. For programmaticaly change these
992 * options, see <code>JavaCore#setOptions()</code>.
996 * project which contains the field.
1000 * field's modifiers as defined by the class <code>Flags</code>.
1002 * <code>true</code> if the field's type is boolean
1003 * @param excludedNames
1004 * a list of names which cannot be suggested (already used
1005 * names). Can be <code>null</code> if there is no excluded
1007 * @return char[] a name.
1009 * @see JavaCore#setOptions(java.util.Hashtable)
1010 * @see JavaCore#getDefaultOptions()
1012 public static String suggestSetterName(IJavaProject project,
1013 String fieldName, int modifiers, boolean isBoolean,
1014 String[] excludedNames) {
1015 return String.valueOf(suggestSetterName(project, fieldName
1016 .toCharArray(), modifiers, isBoolean,
1017 convertStringToChars(excludedNames)));
1020 private static char[] suggestAccessorName(IJavaProject project,
1021 char[] fieldName, int modifiers) {
1022 char[] name = removePrefixAndSuffixForFieldName(project, fieldName,
1024 if (name.length > 0 && Character.isLowerCase(name[0])) {
1025 name[0] = Character.toUpperCase(name[0]);
1030 private static char[] suggestNewName(char[] name, char[][] excludedNames) {
1031 if (excludedNames == null) {
1035 char[] newName = name;
1038 while (i < excludedNames.length) {
1039 if (CharOperation.equals(newName, excludedNames[i], false)) {
1040 newName = CharOperation.concat(name, String.valueOf(count++)
1050 private static String[] convertCharsToString(char[][] c) {
1051 int length = c == null ? 0 : c.length;
1052 String[] s = new String[length];
1053 for (int i = 0; i < length; i++) {
1054 s[i] = String.valueOf(c[i]);
1059 private static char[][] convertStringToChars(String[] s) {
1060 int length = s == null ? 0 : s.length;
1061 char[][] c = new char[length][];
1062 for (int i = 0; i < length; i++) {
1064 c[i] = CharOperation.NO_CHAR;
1066 c[i] = s[i].toCharArray();