Lines 12-18
Link Here
|
12 |
|
12 |
|
13 |
import org.eclipse.jdt.core.compiler.CharOperation; |
13 |
import org.eclipse.jdt.core.compiler.CharOperation; |
14 |
|
14 |
|
15 |
import org.eclipse.jdt.internal.codeassist.impl.AssistOptions; |
|
|
16 |
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; |
15 |
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; |
17 |
import org.eclipse.jdt.internal.core.INamingRequestor; |
16 |
import org.eclipse.jdt.internal.core.INamingRequestor; |
18 |
import org.eclipse.jdt.internal.core.InternalNamingConventions; |
17 |
import org.eclipse.jdt.internal.core.InternalNamingConventions; |
Lines 316-361
Link Here
|
316 |
return c; |
315 |
return c; |
317 |
} |
316 |
} |
318 |
|
317 |
|
319 |
private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) { |
|
|
320 |
// remove longer prefix |
321 |
char[] withoutPrefixName = name; |
322 |
if (prefixes != null) { |
323 |
int bestLength = 0; |
324 |
for (int i= 0; i < prefixes.length; i++) { |
325 |
char[] prefix = prefixes[i]; |
326 |
if (CharOperation.prefixEquals(prefix, name)) { |
327 |
int currLen = prefix.length; |
328 |
boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); |
329 |
if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { |
330 |
if (bestLength < currLen && name.length != currLen) { |
331 |
withoutPrefixName = CharOperation.subarray(name, currLen, name.length); |
332 |
bestLength = currLen; |
333 |
} |
334 |
} |
335 |
} |
336 |
} |
337 |
} |
338 |
|
339 |
// remove longer suffix |
340 |
char[] withoutSuffixName = withoutPrefixName; |
341 |
if(suffixes != null) { |
342 |
int bestLength = 0; |
343 |
for (int i = 0; i < suffixes.length; i++) { |
344 |
char[] suffix = suffixes[i]; |
345 |
if(CharOperation.endsWith(withoutPrefixName, suffix)) { |
346 |
int currLen = suffix.length; |
347 |
if(bestLength < currLen && withoutPrefixName.length != currLen) { |
348 |
withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); |
349 |
bestLength = currLen; |
350 |
} |
351 |
} |
352 |
} |
353 |
} |
354 |
|
355 |
withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); |
356 |
return withoutSuffixName; |
357 |
} |
358 |
|
359 |
/** |
318 |
/** |
360 |
* Remove prefix and suffix from an argument name. |
319 |
* Remove prefix and suffix from an argument name. |
361 |
* <p> |
320 |
* <p> |
Lines 382-392
Link Here
|
382 |
* @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_PARAMETER} as variable kind. |
341 |
* @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_PARAMETER} as variable kind. |
383 |
*/ |
342 |
*/ |
384 |
public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) { |
343 |
public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) { |
385 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
344 |
return InternalNamingConventions.removeVariablePrefixAndSuffix(VK_PARAMETER, javaProject, argumentName); |
386 |
return removePrefixAndSuffix( |
|
|
387 |
argumentName, |
388 |
assistOptions.argumentPrefixes, |
389 |
assistOptions.argumentSuffixes); |
390 |
} |
345 |
} |
391 |
|
346 |
|
392 |
/** |
347 |
/** |
Lines 448-459
Link Here
|
448 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
403 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
449 |
*/ |
404 |
*/ |
450 |
public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) { |
405 |
public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) { |
451 |
boolean isStatic = Flags.isStatic(modifiers); |
406 |
return InternalNamingConventions.removeVariablePrefixAndSuffix( |
452 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
407 |
Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, |
453 |
return removePrefixAndSuffix( |
408 |
javaProject, |
454 |
fieldName, |
409 |
fieldName); |
455 |
isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes, |
|
|
456 |
isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes); |
457 |
} |
410 |
} |
458 |
|
411 |
|
459 |
/** |
412 |
/** |
Lines 516-526
Link Here
|
516 |
* @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_LOCAL} as variable kind. |
469 |
* @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_LOCAL} as variable kind. |
517 |
*/ |
470 |
*/ |
518 |
public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) { |
471 |
public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) { |
519 |
AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); |
472 |
return InternalNamingConventions.removeVariablePrefixAndSuffix(VK_LOCAL, javaProject, localName); |
520 |
return removePrefixAndSuffix( |
|
|
521 |
localName, |
522 |
assistOptions.localPrefixes, |
523 |
assistOptions.localSuffixes); |
524 |
} |
473 |
} |
525 |
|
474 |
|
526 |
/** |
475 |
/** |
Lines 590-598
Link Here
|
590 |
IJavaProject javaProject) { |
539 |
IJavaProject javaProject) { |
591 |
return String.valueOf(InternalNamingConventions.getBaseName(variableKind, javaProject, variableName.toCharArray())); |
540 |
return String.valueOf(InternalNamingConventions.getBaseName(variableKind, javaProject, variableName.toCharArray())); |
592 |
} |
541 |
} |
|
|
542 |
|
543 |
private static int getFieldVariableKind(int modifiers) { |
544 |
if (Flags.isStatic(modifiers)) { |
545 |
if (Flags.isFinal(modifiers)) { |
546 |
return VK_STATIC_FINAL_FIELD; |
547 |
} |
548 |
return VK_STATIC_FIELD; |
549 |
} |
550 |
return VK_INSTANCE_FIELD; |
551 |
} |
593 |
|
552 |
|
594 |
private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { |
553 |
private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { |
595 |
char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); |
554 |
char[] name = InternalNamingConventions.getBaseName(getFieldVariableKind(modifiers), project, fieldName); |
596 |
if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { |
555 |
if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { |
597 |
name[0] = ScannerHelper.toUpperCase(name[0]); |
556 |
name[0] = ScannerHelper.toUpperCase(name[0]); |
598 |
} |
557 |
} |
Lines 630-646
Link Here
|
630 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. |
589 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. |
631 |
*/ |
590 |
*/ |
632 |
public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
591 |
public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
633 |
NamingRequestor requestor = new NamingRequestor(); |
592 |
if(qualifiedTypeName == null || qualifiedTypeName.length == 0) |
634 |
InternalNamingConventions.suggestArgumentNames( |
593 |
return CharOperation.NO_CHAR_CHAR; |
635 |
javaProject, |
594 |
|
636 |
packageName, |
595 |
char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); |
637 |
qualifiedTypeName, |
596 |
|
638 |
dim, |
597 |
NamingRequestor requestor = new NamingRequestor(); |
639 |
null, |
598 |
InternalNamingConventions.suggestVariableNames( |
640 |
excludedNames, |
599 |
VK_PARAMETER, |
641 |
requestor); |
600 |
BK_TYPE_NAME, |
642 |
|
601 |
typeName, |
643 |
return requestor.getResults(); |
602 |
javaProject, |
|
|
603 |
dim, |
604 |
null, |
605 |
excludedNames, |
606 |
true, |
607 |
requestor); |
608 |
|
609 |
return requestor.getResults(); |
644 |
} |
610 |
} |
645 |
|
611 |
|
646 |
/** |
612 |
/** |
Lines 719-736
Link Here
|
719 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
685 |
* with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. |
720 |
*/ |
686 |
*/ |
721 |
public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { |
687 |
public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { |
722 |
NamingRequestor requestor = new NamingRequestor(); |
688 |
if(qualifiedTypeName == null || qualifiedTypeName.length == 0) |
723 |
InternalNamingConventions.suggestFieldNames( |
689 |
return CharOperation.NO_CHAR_CHAR; |
724 |
javaProject, |
690 |
|
725 |
packageName, |
691 |
char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); |
726 |
qualifiedTypeName, |
692 |
|
727 |
dim, |
693 |
NamingRequestor requestor = new NamingRequestor(); |
728 |
modifiers, |
694 |
InternalNamingConventions.suggestVariableNames( |
729 |
null, |
695 |
Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, |
730 |
excludedNames, |
696 |
BK_TYPE_NAME, |
731 |
requestor); |
697 |
typeName, |
732 |
|
698 |
javaProject, |
733 |
return requestor.getResults(); |
699 |
dim, |
|
|
700 |
null, |
701 |
excludedNames, |
702 |
true, |
703 |
requestor); |
704 |
|
705 |
return requestor.getResults(); |
734 |
} |
706 |
} |
735 |
|
707 |
|
736 |
/** |
708 |
/** |
Lines 812-818
Link Here
|
812 |
*/ |
784 |
*/ |
813 |
public static char[] suggestGetterName(IJavaProject project, char[] fieldName, int modifiers, boolean isBoolean, char[][] excludedNames) { |
785 |
public static char[] suggestGetterName(IJavaProject project, char[] fieldName, int modifiers, boolean isBoolean, char[][] excludedNames) { |
814 |
if (isBoolean) { |
786 |
if (isBoolean) { |
815 |
char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); |
787 |
char[] name = InternalNamingConventions.getBaseName(getFieldVariableKind(modifiers), project, fieldName); |
816 |
int prefixLen = GETTER_BOOL_NAME.length; |
788 |
int prefixLen = GETTER_BOOL_NAME.length; |
817 |
if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name) |
789 |
if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name) |
818 |
&& name.length > prefixLen && ScannerHelper.isUpperCase(name[prefixLen])) { |
790 |
&& name.length > prefixLen && ScannerHelper.isUpperCase(name[prefixLen])) { |
Lines 901-917
Link Here
|
901 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. |
873 |
* @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. |
902 |
*/ |
874 |
*/ |
903 |
public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
875 |
public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { |
|
|
876 |
if(qualifiedTypeName == null || qualifiedTypeName.length == 0) |
877 |
return CharOperation.NO_CHAR_CHAR; |
878 |
|
879 |
char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); |
880 |
|
904 |
NamingRequestor requestor = new NamingRequestor(); |
881 |
NamingRequestor requestor = new NamingRequestor(); |
905 |
InternalNamingConventions.suggestLocalVariableNames( |
882 |
InternalNamingConventions.suggestVariableNames( |
906 |
javaProject, |
883 |
VK_LOCAL, |
907 |
packageName, |
884 |
BK_TYPE_NAME, |
908 |
qualifiedTypeName, |
885 |
typeName, |
909 |
dim, |
886 |
javaProject, |
910 |
null, |
887 |
dim, |
911 |
excludedNames, |
888 |
null, |
912 |
requestor); |
889 |
excludedNames, |
913 |
|
890 |
true, |
|
|
891 |
requestor); |
892 |
|
914 |
return requestor.getResults(); |
893 |
return requestor.getResults(); |
|
|
894 |
|
915 |
} |
895 |
} |
916 |
/** |
896 |
/** |
917 |
* Suggest names for a local variable. The name is computed from variable's type |
897 |
* Suggest names for a local variable. The name is computed from variable's type |
Lines 1004-1010
Link Here
|
1004 |
public static char[] suggestSetterName(IJavaProject project, char[] fieldName, int modifiers, boolean isBoolean, char[][] excludedNames) { |
984 |
public static char[] suggestSetterName(IJavaProject project, char[] fieldName, int modifiers, boolean isBoolean, char[][] excludedNames) { |
1005 |
|
985 |
|
1006 |
if (isBoolean) { |
986 |
if (isBoolean) { |
1007 |
char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); |
987 |
char[] name = InternalNamingConventions.getBaseName(getFieldVariableKind(modifiers), project, fieldName); |
1008 |
int prefixLen = GETTER_BOOL_NAME.length; |
988 |
int prefixLen = GETTER_BOOL_NAME.length; |
1009 |
if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name) |
989 |
if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name) |
1010 |
&& name.length > prefixLen && ScannerHelper.isUpperCase(name[prefixLen])) { |
990 |
&& name.length > prefixLen && ScannerHelper.isUpperCase(name[prefixLen])) { |