### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/InternalNamingConventions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/InternalNamingConventions.java,v retrieving revision 1.21 diff -u -r1.21 InternalNamingConventions.java --- model/org/eclipse/jdt/internal/core/InternalNamingConventions.java 27 Jun 2008 16:03:50 -0000 1.21 +++ model/org/eclipse/jdt/internal/core/InternalNamingConventions.java 17 Oct 2008 11:27:18 -0000 @@ -12,8 +12,8 @@ import java.util.Map; -import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.internal.codeassist.impl.AssistOptions; @@ -37,227 +37,6 @@ null/*taskPriorities*/, true/*taskCaseSensitive*/); } - public static void suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) { - Map options = javaProject.getOptions(true); - CompilerOptions compilerOptions = new CompilerOptions(options); - AssistOptions assistOptions = new AssistOptions(options); - - suggestNames( - packageName, - qualifiedTypeName, - dim, - internalPrefix, - assistOptions.argumentPrefixes, - assistOptions.argumentSuffixes, - excludedNames, - getNameScanner(compilerOptions), - requestor); - } - public static void suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) { - boolean isStatic = Flags.isStatic(modifiers); - - Map options = javaProject.getOptions(true); - CompilerOptions compilerOptions = new CompilerOptions(options); - AssistOptions assistOptions = new AssistOptions(options); - - suggestNames( - packageName, - qualifiedTypeName, - dim, - internalPrefix, - isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes, - isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes, - excludedNames, - getNameScanner(compilerOptions), - requestor); - } - public static void suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[] internalPrefix, char[][] excludedNames, INamingRequestor requestor) { - Map options = javaProject.getOptions(true); - CompilerOptions compilerOptions = new CompilerOptions(options); - AssistOptions assistOptions = new AssistOptions(options); - - suggestNames( - packageName, - qualifiedTypeName, - dim, - internalPrefix, - assistOptions.localPrefixes, - assistOptions.localSuffixes, - excludedNames, - getNameScanner(compilerOptions), - requestor); - } - - private static void suggestNames( - char[] packageName, - char[] qualifiedTypeName, - int dim, - char[] internalPrefix, - char[][] prefixes, - char[][] suffixes, - char[][] excludedNames, - Scanner nameScanner, - INamingRequestor requestor){ - - if(qualifiedTypeName == null || qualifiedTypeName.length == 0) - return; - - if(internalPrefix == null) { - internalPrefix = CharOperation.NO_CHAR; - } else { - internalPrefix = removePrefix(internalPrefix, prefixes); - } - - char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); - - if(prefixes == null || prefixes.length == 0) { - prefixes = new char[1][0]; - } else { - int length = prefixes.length; - System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length); - prefixes[length] = CharOperation.NO_CHAR; - } - - if(suffixes == null || suffixes.length == 0) { - suffixes = new char[1][0]; - } else { - int length = suffixes.length; - System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length); - suffixes[length] = CharOperation.NO_CHAR; - } - - char[][] tempNames = null; - - // compute variable name for base type - try{ - nameScanner.setSource(typeName); - switch (nameScanner.getNextToken()) { - case TerminalTokens.TokenNameint : - case TerminalTokens.TokenNamebyte : - case TerminalTokens.TokenNameshort : - case TerminalTokens.TokenNamechar : - case TerminalTokens.TokenNamelong : - case TerminalTokens.TokenNamefloat : - case TerminalTokens.TokenNamedouble : - case TerminalTokens.TokenNameboolean : - - if (internalPrefix != null && internalPrefix.length > 0) return; - - char[] name = computeBaseTypeNames(typeName[0], excludedNames); - if(name != null) { - tempNames = new char[][]{name}; - } - break; - } - } catch(InvalidInputException e){ - // ignore - } - - // compute variable name for non base type - if(tempNames == null) { - tempNames = computeNames(typeName); - } - - boolean acceptDefaultName = true; - SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray(); - - next : for (int i = 0; i < tempNames.length; i++) { - char[] tempName = tempNames[i]; - if(dim > 0) { - int length = tempName.length; - if (tempName[length-1] == 's'){ - if(tempName.length > 1 && tempName[length-2] == 's') { - System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); - tempName[length] = 'e'; - tempName[length+1] = 's'; - } - } else if(tempName[length-1] == 'y') { - System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); - tempName[length-1] = 'i'; - tempName[length] = 'e'; - tempName[length+1] = 's'; - } else { - System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length); - tempName[length] = 's'; - } - } - - char[] unprefixedName = tempName; - unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]); - for (int j = 0; j <= internalPrefix.length; j++) { - if(j == internalPrefix.length || - CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) { - tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, j), unprefixedName); - if(j == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]); - for (int k = 0; k < prefixes.length; k++) { - if(prefixes[k].length > 0 - && ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) { - tempName[0] = ScannerHelper.toUpperCase(tempName[0]); - } else { - tempName[0] = ScannerHelper.toLowerCase(tempName[0]); - } - char[] prefixName = CharOperation.concat(prefixes[k], tempName); - for (int l = 0; l < suffixes.length; l++) { - char[] suffixName = CharOperation.concat(prefixName, suffixes[l]); - suffixName = - excludeNames( - suffixName, - prefixName, - suffixes[l], - excludedNames); - try{ - nameScanner.setSource(suffixName); - switch (nameScanner.getNextToken()) { - case TerminalTokens.TokenNameIdentifier : - int token = nameScanner.getNextToken(); - if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { - if (!foundNames.includes(suffixName)) { - acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - j, requestor); - foundNames.add(suffixName); - acceptDefaultName = false; - } - } - break; - default: - suffixName = CharOperation.concat( - prefixName, - String.valueOf(1).toCharArray(), - suffixes[l] - ); - suffixName = - excludeNames( - suffixName, - prefixName, - suffixes[l], - excludedNames); - nameScanner.setSource(suffixName); - switch (nameScanner.getNextToken()) { - case TerminalTokens.TokenNameIdentifier : - token = nameScanner.getNextToken(); - if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { - if (!foundNames.includes(suffixName)) { - acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - j, requestor); - foundNames.add(suffixName); - acceptDefaultName = false; - } - } - } - } - } catch(InvalidInputException e){ - // ignore - } - } - } - continue next; - } - } - } - // if no names were found - if(acceptDefaultName) { - char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excludedNames); - requestor.acceptNameWithoutPrefixAndSuffix(name, 0); - } - } private static void acceptName( char[] name, @@ -278,6 +57,15 @@ } } + private static char[][] computeBaseTypeNames(char[] typeName, boolean isConstantField, char[][] excludedNames){ + char[] name = computeBaseTypeNames(typeName[0], excludedNames); + if(name != null) { + return new char[][]{name}; + } else { + // compute variable name like from non base type + return computeNonBaseTypeNames(typeName, isConstantField); + } + } private static char[] computeBaseTypeNames(char firstName, char[][] excludedNames){ char[] name = new char[]{firstName}; @@ -294,34 +82,111 @@ return name; } - - private static char[][] computeNames(char[] sourceName){ - char[][] names = new char[5][]; - int nameCount = 0; - boolean previousIsUpperCase = false; - boolean previousIsLetter = true; - for(int i = sourceName.length - 1 ; i >= 0 ; i--){ - boolean isUpperCase = ScannerHelper.isUpperCase(sourceName[i]); - boolean isLetter = ScannerHelper.isLetter(sourceName[i]); - if(isUpperCase && !previousIsUpperCase && previousIsLetter){ - char[] name = CharOperation.subarray(sourceName,i,sourceName.length); - if(name.length > 1){ - if(nameCount == names.length) { - System.arraycopy(names, 0, names = new char[nameCount * 2][], 0, nameCount); - } - name[0] = ScannerHelper.toLowerCase(name[0]); - names[nameCount++] = name; - } + + private static char[][] computeNonBaseTypeNames(char[] sourceName, boolean isConstantField){ + int length = sourceName.length; + + if (length == 0) { + return CharOperation.NO_CHAR_CHAR; + } + + if (length == 1) { + return new char[][]{CharOperation.toLowerCase(sourceName)}; + } + + char[][] nameParts = new char[length][]; + int namePartsPtr = -1; + + int endIndex = length; + char c = sourceName[length - 1]; + + final int IS_LOWER_CASE = 1; + final int IS_UPPER_CASE = 2; + final int IS_UNDERSCORE = 3; + final int IS_OTHER = 4; + + int previousCharKind = + ScannerHelper.isLowerCase(c) ? IS_LOWER_CASE : + ScannerHelper.isUpperCase(c) ? IS_UPPER_CASE : + c == '_' ? IS_UNDERSCORE : IS_OTHER; + + for(int i = length - 1 ; i >= 0 ; i--){ + c = sourceName[i]; + + int charKind = + ScannerHelper.isLowerCase(c) ? IS_LOWER_CASE : + ScannerHelper.isUpperCase(c) ? IS_UPPER_CASE : + c == '_' ? IS_UNDERSCORE : IS_OTHER; + + switch (charKind) { + case IS_LOWER_CASE: + if (previousCharKind == IS_UPPER_CASE) { + nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, i + 1, endIndex); + endIndex = i + 1; + } + previousCharKind = IS_LOWER_CASE; + break; + case IS_UPPER_CASE: + if (previousCharKind == IS_LOWER_CASE) { + nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, i, endIndex); + if (i > 0) { + char pc = sourceName[i - 1]; + previousCharKind = + ScannerHelper.isLowerCase(pc) ? IS_LOWER_CASE : + ScannerHelper.isUpperCase(pc) ? IS_UPPER_CASE : + pc == '_' ? IS_UNDERSCORE : IS_OTHER; + } + endIndex = i; + } else { + previousCharKind = IS_UPPER_CASE; + } + break; + case IS_UNDERSCORE: + switch (previousCharKind) { + case IS_UNDERSCORE: + if (i > 0) { + char pc = sourceName[i - 1]; + previousCharKind = + ScannerHelper.isLowerCase(pc) ? IS_LOWER_CASE : + ScannerHelper.isUpperCase(pc) ? IS_UPPER_CASE : + pc == '_' ? IS_UNDERSCORE : IS_OTHER; + } + endIndex = i; + break; + case IS_LOWER_CASE: + case IS_UPPER_CASE: + nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, i + 1, endIndex); + if (i > 0) { + char pc = sourceName[i - 1]; + previousCharKind = + ScannerHelper.isLowerCase(pc) ? IS_LOWER_CASE : + ScannerHelper.isUpperCase(pc) ? IS_UPPER_CASE : + pc == '_' ? IS_UNDERSCORE : IS_OTHER; + } + endIndex = i; + break; + default: + previousCharKind = IS_UNDERSCORE; + break; + } + break; + default: + previousCharKind = IS_OTHER; + break; } - previousIsUpperCase = isUpperCase; - previousIsLetter = isLetter; } - if(nameCount == 0){ - names[nameCount++] = CharOperation.toLowerCase(sourceName); + if (endIndex > 0) { + nameParts[++namePartsPtr] = CharOperation.subarray(sourceName, 0, endIndex); + } + + if (isConstantField) { + return generateConstantName(nameParts, namePartsPtr); + } else { + return generateNonConstantName(nameParts, namePartsPtr); } - System.arraycopy(names, 0, names = new char[nameCount][], 0, nameCount); - return names; } + + private static char[] excludeNames( char[] suffixName, @@ -344,6 +209,204 @@ } return suffixName; } + + private static char[][] generateNonConstantName(char[][] nameParts, int namePartsPtr) { + char[][] names = new char[namePartsPtr + 1][]; + + char[] namePart = CharOperation.toLowerCase(nameParts[0]); + int namePartLength = namePart.length; + System.arraycopy(namePart, 0, namePart, 0, namePartLength); + + char[] name = namePart; + + names[namePartsPtr] = name; + + for (int i = 1; i <= namePartsPtr; i++) { + namePart = CharOperation.toLowerCase(nameParts[i]); + namePartLength = namePart.length; + name = CharOperation.concat(namePart, name); + name[namePartLength] = ScannerHelper.toUpperCase(name[namePartLength]); + + names[namePartsPtr - i] = name; + } + return names; + } + + private static char[][] generateConstantName(char[][] nameParts, int namePartsPtr) { + char[][] names = new char[namePartsPtr + 1][]; + + char[] namePart = CharOperation.toUpperCase(nameParts[0]); + int namePartLength = namePart.length; + System.arraycopy(namePart, 0, namePart, 0, namePartLength); + + char[] name = namePart; + + names[namePartsPtr] = name; + + for (int i = 1; i <= namePartsPtr; i++) { + namePart = CharOperation.toUpperCase(nameParts[i]); + namePartLength = namePart.length; + if (namePart[namePartLength - 1] != '_') { + name = CharOperation.concat(namePart, name, '_'); + } else { + name = CharOperation.concat(namePart, name); + } + + names[namePartsPtr - i] = name; + } + return names; + } + + public static char[] getBaseName( + int variableKind, + IJavaProject javaProject, + char[] name) { + + AssistOptions assistOptions; + if (javaProject != null) { + assistOptions = new AssistOptions(javaProject.getOptions(true)); + } else { + assistOptions = new AssistOptions(JavaCore.getOptions()); + } + + char[][] prefixes = null; + char[][] suffixes = null; + switch (variableKind) { + case VK_INSTANCE_FIELD: + prefixes = assistOptions.fieldPrefixes; + suffixes = assistOptions.fieldSuffixes; + break; + case VK_STATIC_FIELD: + prefixes = assistOptions.staticFieldPrefixes; + suffixes = assistOptions.staticFieldSuffixes; + break; + case VK_CONSTANT_FIELD: + prefixes = assistOptions.staticFinalFieldPrefixes; + suffixes = assistOptions.staticFinalFieldSuffixes; + break; + case VK_LOCAL: + prefixes = assistOptions.localPrefixes; + suffixes = assistOptions.localSuffixes; + break; + case VK_PARAMETER: + prefixes = assistOptions.argumentPrefixes; + suffixes = assistOptions.argumentSuffixes; + break; + } + + + return getBaseName(name, prefixes, suffixes, variableKind == VK_CONSTANT_FIELD); + } + + private static char[] getBaseName(char[] name, char[][] prefixes, char[][] suffixes, boolean isConstant) { + char[] nameWithoutPrefixAndSiffix = removeVariablePrefixAndSuffix(name, prefixes, suffixes, false); + + char[] baseName; + if (isConstant) { + int length = nameWithoutPrefixAndSiffix.length; + baseName = new char[length]; + int baseNamePtr = -1; + + boolean previousIsUnderscore = false; + for (int i = 0; i < length; i++) { + char c = nameWithoutPrefixAndSiffix[i]; + if (c != '_') { + if (previousIsUnderscore || i == 0) { + baseName[++baseNamePtr] = ScannerHelper.toUpperCase(c); + previousIsUnderscore = false; + } else { + baseName[++baseNamePtr] = ScannerHelper.toLowerCase(c); + } + } else { + previousIsUnderscore = true; + } + } + System.arraycopy(baseName, 0, baseName = new char[baseNamePtr + 1], 0, baseNamePtr + 1); + } else { + baseName = nameWithoutPrefixAndSiffix; + } + + return baseName; + } + + public static char[] removeVariablePrefixAndSuffix( + int variableKind, + IJavaProject javaProject, + char[] name) { + AssistOptions assistOptions; + if (javaProject != null) { + assistOptions = new AssistOptions(javaProject.getOptions(true)); + } else { + assistOptions = new AssistOptions(JavaCore.getOptions()); + } + + char[][] prefixes = null; + char[][] suffixes = null; + switch (variableKind) { + case VK_INSTANCE_FIELD: + prefixes = assistOptions.fieldPrefixes; + suffixes = assistOptions.fieldSuffixes; + break; + case VK_STATIC_FIELD: + prefixes = assistOptions.staticFieldPrefixes; + suffixes = assistOptions.staticFieldSuffixes; + break; + case VK_CONSTANT_FIELD: + prefixes = assistOptions.staticFinalFieldPrefixes; + suffixes = assistOptions.staticFinalFieldSuffixes; + break; + case VK_LOCAL: + prefixes = assistOptions.localPrefixes; + suffixes = assistOptions.localSuffixes; + break; + case VK_PARAMETER: + prefixes = assistOptions.argumentPrefixes; + suffixes = assistOptions.argumentSuffixes; + break; + } + + return InternalNamingConventions.removeVariablePrefixAndSuffix(name, prefixes, suffixes, true); + } + + private static char[] removeVariablePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes, boolean updateFirstCharacter) { + // remove longer prefix + char[] withoutPrefixName = name; + if (prefixes != null) { + int bestLength = 0; + for (int i= 0; i < prefixes.length; i++) { + char[] prefix = prefixes[i]; + if (CharOperation.prefixEquals(prefix, name)) { + int currLen = prefix.length; + boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); + if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { + if (bestLength < currLen && name.length != currLen) { + withoutPrefixName = CharOperation.subarray(name, currLen, name.length); + bestLength = currLen; + } + } + } + } + } + + // remove longer suffix + char[] withoutSuffixName = withoutPrefixName; + if(suffixes != null) { + int bestLength = 0; + for (int i = 0; i < suffixes.length; i++) { + char[] suffix = suffixes[i]; + if(CharOperation.endsWith(withoutPrefixName, suffix)) { + int currLen = suffix.length; + if(bestLength < currLen && withoutPrefixName.length != currLen) { + withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); + bestLength = currLen; + } + } + } + } + + if (updateFirstCharacter) withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); + return withoutSuffixName; + } private static char[] removePrefix(char[] name, char[][] prefixes) { // remove longer prefix @@ -430,4 +493,277 @@ return false; return true; } + + public static final int VK_STATIC_FIELD = 1; + public static final int VK_INSTANCE_FIELD = 2; + public static final int VK_CONSTANT_FIELD = 3; + public static final int VK_PARAMETER = 4; + public static final int VK_LOCAL = 5; + + public static final int BK_SIMPLE_NAME = 1; + public static final int BK_SIMPLE_TYPE_NAME = 2; + + public static void suggestVariableNames( + int variableKind, + int baseNameKind, + char[] baseName, + IJavaProject javaProject, + int dim, + char[] internalPrefix, + char[][] excluded, + boolean evaluateDefault, + INamingRequestor requestor) { + + if(baseName == null || baseName.length == 0) + return; + + Map options; + if (javaProject != null) { + options = javaProject.getOptions(true); + } else { + options = JavaCore.getOptions(); + } + CompilerOptions compilerOptions = new CompilerOptions(options); + AssistOptions assistOptions = new AssistOptions(options); + + boolean isConstantField = false; + + char[][] prefixes = null; + char[][] suffixes = null; + switch (variableKind) { + case VK_INSTANCE_FIELD: + prefixes = assistOptions.fieldPrefixes; + suffixes = assistOptions.fieldSuffixes; + break; + case VK_STATIC_FIELD: + prefixes = assistOptions.staticFieldPrefixes; + suffixes = assistOptions.staticFieldSuffixes; + break; + case VK_CONSTANT_FIELD: + isConstantField = true; + prefixes = assistOptions.staticFinalFieldPrefixes; + suffixes = assistOptions.staticFinalFieldSuffixes; + break; + case VK_LOCAL: + prefixes = assistOptions.localPrefixes; + suffixes = assistOptions.localSuffixes; + break; + case VK_PARAMETER: + prefixes = assistOptions.argumentPrefixes; + suffixes = assistOptions.argumentSuffixes; + break; + } + + if(prefixes == null || prefixes.length == 0) { + prefixes = new char[1][0]; + } else { + int length = prefixes.length; + System.arraycopy(prefixes, 0, prefixes = new char[length+1][], 0, length); + prefixes[length] = CharOperation.NO_CHAR; + } + + if(suffixes == null || suffixes.length == 0) { + suffixes = new char[1][0]; + } else { + int length = suffixes.length; + System.arraycopy(suffixes, 0, suffixes = new char[length+1][], 0, length); + suffixes[length] = CharOperation.NO_CHAR; + } + + if(internalPrefix == null) { + internalPrefix = CharOperation.NO_CHAR; + } else { + internalPrefix = removePrefix(internalPrefix, prefixes); + } + + char[][] tempNames = null; + + Scanner nameScanner = getNameScanner(compilerOptions); + if (baseNameKind == BK_SIMPLE_TYPE_NAME) { + boolean isBaseType = false; + + try{ + nameScanner.setSource(baseName); + switch (nameScanner.getNextToken()) { + case TerminalTokens.TokenNameint : + case TerminalTokens.TokenNamebyte : + case TerminalTokens.TokenNameshort : + case TerminalTokens.TokenNamechar : + case TerminalTokens.TokenNamelong : + case TerminalTokens.TokenNamefloat : + case TerminalTokens.TokenNamedouble : + case TerminalTokens.TokenNameboolean : + isBaseType = true; + break; + } + } catch(InvalidInputException e){ + // ignore + } + if (isBaseType) { + // compute variable name from base type + if (internalPrefix.length > 0) return; + + tempNames = computeBaseTypeNames(baseName, isConstantField, excluded); + } else { + // compute variable name for non base type + tempNames = computeNonBaseTypeNames(baseName, isConstantField); + } + } else { + tempNames = new char[][]{baseName}; + } + + boolean acceptDefaultName = true; + SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray(); + + for (int i = 0; i < tempNames.length; i++) { + char[] tempName = tempNames[i]; + + // add English plural form is necessary + if(dim > 0) { + int length = tempName.length; + + if (isConstantField) { + if (tempName[length-1] == 'S'){ + if(tempName.length > 1 && tempName[length-2] == 'S') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length] = 'E'; + tempName[length+1] = 'S'; + } + } else if(tempName[length-1] == 'Y') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length-1] = 'I'; + tempName[length] = 'E'; + tempName[length+1] = 'S'; + } else { + System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length); + tempName[length] = 'S'; + } + } else { + if (tempName[length-1] == 's'){ + if(tempName.length > 1 && tempName[length-2] == 's') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length] = 'e'; + tempName[length+1] = 's'; + } + } else if(tempName[length-1] == 'y') { + System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length); + tempName[length-1] = 'i'; + tempName[length] = 'e'; + tempName[length+1] = 's'; + } else { + System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length); + tempName[length] = 's'; + } + } + } + + char[] unprefixedName = tempName; + + int matchingIndex = -1; + if (!isConstantField) { + unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]); + + done : for (int j = 0; j <= internalPrefix.length; j++) { + if(j == internalPrefix.length || + CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) { + matchingIndex = j; + break done; + } + } + } else { + done : for (int j = 0; j <= internalPrefix.length; j++) { + if(j == internalPrefix.length) { + matchingIndex = j; + break done; + } else if(CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) { + if (j == 0 || internalPrefix[j - 1] == '_') { + matchingIndex = j; + break done; + } + + } + } + } + + if(matchingIndex > -1) { + if (!isConstantField) { + tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, matchingIndex), unprefixedName); + if(matchingIndex == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]); + } else { + if(matchingIndex != 0 && tempName[0] != '_' && internalPrefix[matchingIndex - 1] != '_') { + tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName, '_'); + } else { + tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName); + } + } + + for (int k = 0; k < prefixes.length; k++) { + if (!isConstantField) { + if(prefixes[k].length > 0 + && ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) { + tempName[0] = ScannerHelper.toUpperCase(tempName[0]); + } else { + tempName[0] = ScannerHelper.toLowerCase(tempName[0]); + } + } + char[] prefixName = CharOperation.concat(prefixes[k], tempName); + for (int l = 0; l < suffixes.length; l++) { + char[] suffixName = CharOperation.concat(prefixName, suffixes[l]); + suffixName = + excludeNames( + suffixName, + prefixName, + suffixes[l], + excluded); + try{ + nameScanner.setSource(suffixName); + switch (nameScanner.getNextToken()) { + case TerminalTokens.TokenNameIdentifier : + int token = nameScanner.getNextToken(); + if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { + if (!foundNames.includes(suffixName)) { + acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor); + foundNames.add(suffixName); + acceptDefaultName = false; + } + } + break; + default: + suffixName = CharOperation.concat( + prefixName, + String.valueOf(1).toCharArray(), + suffixes[l] + ); + suffixName = + excludeNames( + suffixName, + prefixName, + suffixes[l], + excluded); + nameScanner.setSource(suffixName); + switch (nameScanner.getNextToken()) { + case TerminalTokens.TokenNameIdentifier : + token = nameScanner.getNextToken(); + if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) { + if (!foundNames.includes(suffixName)) { + acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor); + foundNames.add(suffixName); + acceptDefaultName = false; + } + } + } + } + } catch(InvalidInputException e){ + // ignore + } + } + } + } + } + // if no names were found + if(evaluateDefault && acceptDefaultName) { + char[] name = excludeNames(DEFAULT_NAME, DEFAULT_NAME, CharOperation.NO_CHAR, excluded); + requestor.acceptNameWithoutPrefixAndSuffix(name, 0); + } + } } Index: model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java,v retrieving revision 1.41 diff -u -r1.41 JavaCorePreferenceInitializer.java --- model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java 8 Oct 2008 11:58:47 -0000 1.41 +++ model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java 17 Oct 2008 11:27:18 -0000 @@ -77,10 +77,12 @@ defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED); defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED); Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.416 diff -u -r1.416 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 13 Oct 2008 13:35:17 -0000 1.416 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 17 Oct 2008 11:27:18 -0000 @@ -1965,10 +1965,12 @@ defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED); defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$ + defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$ defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED); Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.629 diff -u -r1.629 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 10 Oct 2008 17:24:31 -0000 1.629 +++ model/org/eclipse/jdt/core/JavaCore.java 17 Oct 2008 11:27:17 -0000 @@ -1812,6 +1812,19 @@ */ public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$ /** + * Code assist option ID: Define the Prefixes for Static Final Field Name. + *

When the prefixes is non empty, completion for static final field name will begin with + * one of the proposed prefixes. + *

+ *
Option id:
"org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"
+ *
Possible values:
{ "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card
+ *
Default:
""
+ *
+ * @since 3.5 + * @category CodeAssistOptionID + */ + public static final String CODEASSIST_STATIC_FINAL_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldPrefixes"; //$NON-NLS-1$ + /** * Code assist option ID: Define the Prefixes for Local Variable Name. *

When the prefixes is non empty, completion for local variable name will begin with * one of the proposed prefixes. @@ -1864,6 +1877,19 @@ */ public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$ /** + * Code assist option ID: Define the Suffixes for Static Final Field Name. + *

When the suffixes is non empty, completion for static final field name will end with + * one of the proposed suffixes. + *

+ *
Option id:
"org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"
+ *
Possible values:
{ "<suffix>[,<suffix>]*" }< where <suffix> is a String without any wild-card
+ *
Default:
""
+ *
+ * @since 3.5 + * @category CodeAssistOptionID + */ + public static final String CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFinalFieldSuffixes"; //$NON-NLS-1$ + /** * Code assist option ID: Define the Suffixes for Local Variable Name. *

When the suffixes is non empty, completion for local variable name will end with * one of the proposed suffixes. Index: model/org/eclipse/jdt/core/NamingConventions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/NamingConventions.java,v retrieving revision 1.37 diff -u -r1.37 NamingConventions.java --- model/org/eclipse/jdt/core/NamingConventions.java 27 Jun 2008 16:04:00 -0000 1.37 +++ model/org/eclipse/jdt/core/NamingConventions.java 17 Oct 2008 11:27:18 -0000 @@ -11,7 +11,6 @@ package org.eclipse.jdt.core; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.codeassist.impl.AssistOptions; import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; import org.eclipse.jdt.internal.core.INamingRequestor; import org.eclipse.jdt.internal.core.InternalNamingConventions; @@ -48,10 +47,6 @@ * @noinstantiate This class is not intended to be instantiated by clients. */ public final class NamingConventions { - private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$ - private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$ - private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$ - static class NamingRequestor implements INamingRequestor { private final static int SIZE = 10; @@ -80,6 +75,45 @@ // for acceptNameWithoutPrefixAndSuffix private char[][] otherResults = new char[SIZE][]; private int otherResultsCount = 0; + public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) { + int length = this.otherResults.length; + if(length == this.otherResultsCount) { + System.arraycopy( + this.otherResults, + 0, + this.otherResults = new char[length * 2][], + 0, + length); + } + this.otherResults[this.otherResultsCount++] = name; + } + + public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) { + if(isFirstPrefix) { + int length = this.firstPrefixResults.length; + if(length == this.firstPrefixResultsCount) { + System.arraycopy( + this.firstPrefixResults, + 0, + this.firstPrefixResults = new char[length * 2][], + 0, + length); + } + this.firstPrefixResults[this.firstPrefixResultsCount++] = name; + } else{ + int length = this.prefixResults.length; + if(length == this.prefixResultsCount) { + System.arraycopy( + this.prefixResults, + 0, + this.prefixResults = new char[length * 2][], + 0, + length); + } + this.prefixResults[this.prefixResultsCount++] = name; + } + } + public void acceptNameWithPrefixAndSuffix(char[] name, boolean isFirstPrefix, boolean isFirstSuffix, int reusedCharacters) { if(isFirstPrefix && isFirstSuffix) { int length = this.firstPrefixAndFirstSuffixResults.length; @@ -128,32 +162,6 @@ } } - public void acceptNameWithPrefix(char[] name, boolean isFirstPrefix, int reusedCharacters) { - if(isFirstPrefix) { - int length = this.firstPrefixResults.length; - if(length == this.firstPrefixResultsCount) { - System.arraycopy( - this.firstPrefixResults, - 0, - this.firstPrefixResults = new char[length * 2][], - 0, - length); - } - this.firstPrefixResults[this.firstPrefixResultsCount++] = name; - } else{ - int length = this.prefixResults.length; - if(length == this.prefixResultsCount) { - System.arraycopy( - this.prefixResults, - 0, - this.prefixResults = new char[length * 2][], - 0, - length); - } - this.prefixResults[this.prefixResultsCount++] = name; - } - } - public void acceptNameWithSuffix(char[] name, boolean isFirstSuffix, int reusedCharacters) { if(isFirstSuffix) { int length = this.firstSuffixResults.length; @@ -179,19 +187,6 @@ this.suffixResults[this.suffixResultsCount++] = name; } } - - public void acceptNameWithoutPrefixAndSuffix(char[] name, int reusedCharacters) { - int length = this.otherResults.length; - if(length == this.otherResultsCount) { - System.arraycopy( - this.otherResults, - 0, - this.otherResults = new char[length * 2][], - 0, - length); - } - this.otherResults[this.otherResultsCount++] = name; - } public char[][] getResults(){ int count = this.firstPrefixAndFirstSuffixResultsCount @@ -228,50 +223,82 @@ return results; } } + private static final char[] GETTER_BOOL_NAME = "is".toCharArray(); //$NON-NLS-1$ + private static final char[] GETTER_NAME = "get".toCharArray(); //$NON-NLS-1$ + private static final char[] SETTER_NAME = "set".toCharArray(); //$NON-NLS-1$ - private NamingConventions() { - // Not instantiable - } - private static char[] removePrefixAndSuffix(char[] name, char[][] prefixes, char[][] suffixes) { - // remove longer prefix - char[] withoutPrefixName = name; - if (prefixes != null) { - int bestLength = 0; - for (int i= 0; i < prefixes.length; i++) { - char[] prefix = prefixes[i]; - if (CharOperation.prefixEquals(prefix, name)) { - int currLen = prefix.length; - boolean lastCharIsLetter = ScannerHelper.isLetter(prefix[currLen - 1]); - if(!lastCharIsLetter || (lastCharIsLetter && name.length > currLen && ScannerHelper.isUpperCase(name[currLen]))) { - if (bestLength < currLen && name.length != currLen) { - withoutPrefixName = CharOperation.subarray(name, currLen, name.length); - bestLength = currLen; - } - } - } - } - } + /** + * Variable kind which represents a static field. + * + * @since 3.5 + */ + public static final int VK_STATIC_FIELD = InternalNamingConventions.VK_STATIC_FIELD; + /** + * Variable kind which represents an instance field. + * + * @since 3.5 + */ + public static final int VK_INSTANCE_FIELD = InternalNamingConventions.VK_INSTANCE_FIELD; + /** + * Variable kind which represents a constant field (static final). + * + * @since 3.5 + */ + public static final int VK_CONSTANT_FIELD = InternalNamingConventions.VK_CONSTANT_FIELD; + /** + * Variable kind which represents an argument. + * + * @since 3.5 + */ + public static final int VK_PARAMETER = InternalNamingConventions.VK_PARAMETER; + /** + * Variable kind which represents a local variable. + * + * @since 3.5 + */ + public static final int VK_LOCAL = InternalNamingConventions.VK_LOCAL; + + /** + * The base name associated to this base name kind is a simple name. + * When this base name is used the whole name is considered. + * + * @see #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean) + * + * @since 3.5 + */ + public static final int BK_NAME = InternalNamingConventions.BK_SIMPLE_NAME; + + /** + * The base name associated to this base name kind is a simple type name. + * When this base name is used to all the words of the name are considered. + * + * @see #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean) + * + * @since 3.5 + */ + public static final int BK_TYPE_NAME = InternalNamingConventions.BK_SIMPLE_TYPE_NAME; - // remove longer suffix - char[] withoutSuffixName = withoutPrefixName; - if(suffixes != null) { - int bestLength = 0; - for (int i = 0; i < suffixes.length; i++) { - char[] suffix = suffixes[i]; - if(CharOperation.endsWith(withoutPrefixName, suffix)) { - int currLen = suffix.length; - if(bestLength < currLen && withoutPrefixName.length != currLen) { - withoutSuffixName = CharOperation.subarray(withoutPrefixName, 0, withoutPrefixName.length - currLen); - bestLength = currLen; - } - } + private static String[] convertCharsToString(char[][] c) { + int length = c == null ? 0 : c.length; + String[] s = new String[length]; + for (int i = 0; i < length; i++) { + s[i] = String.valueOf(c[i]); + } + return s; + } + private static char[][] convertStringToChars(String[] s) { + int length = s == null ? 0 : s.length; + char[][] c = new char[length][]; + for (int i = 0; i < length; i++) { + if(s[i] == null) { + c[i] = CharOperation.NO_CHAR; + } else { + c[i] = s[i].toCharArray(); } } - - withoutSuffixName[0] = ScannerHelper.toLowerCase(withoutSuffixName[0]); - return withoutSuffixName; + return c; } /** @@ -296,13 +323,11 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_PARAMETER} as variable kind. */ public static char[] removePrefixAndSuffixForArgumentName(IJavaProject javaProject, char[] argumentName) { - AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); - return removePrefixAndSuffix( - argumentName, - assistOptions.argumentPrefixes, - assistOptions.argumentSuffixes); + return InternalNamingConventions.removeVariablePrefixAndSuffix(VK_PARAMETER, javaProject, argumentName); } /** @@ -327,11 +352,12 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_PARAMETER} as variable kind. */ public static String removePrefixAndSuffixForArgumentName(IJavaProject javaProject, String argumentName) { return String.valueOf(removePrefixAndSuffixForArgumentName(javaProject, argumentName.toCharArray())); } - /** * Remove prefix and suffix from a field name. *

@@ -358,14 +384,13 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static char[] removePrefixAndSuffixForFieldName(IJavaProject javaProject, char[] fieldName, int modifiers) { boolean isStatic = Flags.isStatic(modifiers); - AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); - return removePrefixAndSuffix( - fieldName, - isStatic ? assistOptions.staticFieldPrefixes : assistOptions.fieldPrefixes, - isStatic ? assistOptions.staticFieldSuffixes : assistOptions.fieldSuffixes); + return InternalNamingConventions.removeVariablePrefixAndSuffix(isStatic ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, javaProject, fieldName); } /** @@ -394,10 +419,14 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static String removePrefixAndSuffixForFieldName(IJavaProject javaProject, String fieldName, int modifiers) { return String.valueOf(removePrefixAndSuffixForFieldName(javaProject, fieldName.toCharArray(), modifiers)); } + /** * Remove prefix and suffix from a local variable name. *

@@ -420,13 +449,11 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_LOCAL} as variable kind. */ public static char[] removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, char[] localName) { - AssistOptions assistOptions = new AssistOptions(javaProject.getOptions(true)); - return removePrefixAndSuffix( - localName, - assistOptions.localPrefixes, - assistOptions.localSuffixes); + return InternalNamingConventions.removeVariablePrefixAndSuffix(VK_LOCAL, javaProject, localName); } /** @@ -451,10 +478,43 @@ * @return char[] the name without prefix and suffix. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #getBaseName(int, String, IJavaProject)} instead with {@link #VK_LOCAL} as variable kind. */ public static String removePrefixAndSuffixForLocalVariableName(IJavaProject javaProject, String localName) { return String.valueOf(removePrefixAndSuffixForLocalVariableName(javaProject, localName.toCharArray())); } + + /** + * Returns a base name which could be used to generate this variable name with {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)}. + *

+ * e.g.
+ * If the variable is a {@link #VK_LOCAL} and the variable name is variableName then the base name will be VariableName.
+ * If the variable is a {@link #VK_CONSTANT_FIELD} and the variable name is VARIABLE_NAME then the base name will be VariableName.
+ *

+ * + * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, + * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. + * @param variableName a variable name + * @param javaProject project which contains the variable or null to take into account only workspace settings. + * + * @see #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean) + * @since 3.5 + */ + public static String getBaseName( + int variableKind, + String variableName, + IJavaProject javaProject) { + return String.valueOf(InternalNamingConventions.getBaseName(variableKind, javaProject, variableName.toCharArray())); + } + + private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { + char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); + if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { + name[0] = ScannerHelper.toUpperCase(name[0]); + } + return name; + } /** * Suggest names for an argument. The name is computed from argument's type @@ -483,17 +543,26 @@ * @return char[][] an array of names. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. */ public static char[][] suggestArgumentNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { + if(qualifiedTypeName == null || qualifiedTypeName.length == 0) + return CharOperation.NO_CHAR_CHAR; + + char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); + NamingRequestor requestor = new NamingRequestor(); - InternalNamingConventions.suggestArgumentNames( - javaProject, - packageName, - qualifiedTypeName, - dim, - null, - excludedNames, - requestor); + InternalNamingConventions.suggestVariableNames( + VK_PARAMETER, + BK_TYPE_NAME, + typeName, + javaProject, + dim, + null, + excludedNames, + true, + requestor); return requestor.getResults(); } @@ -525,6 +594,8 @@ * @return char[][] an array of names. * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_PARAMETER} as variable kind. */ public static String[] suggestArgumentNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { return convertCharsToString( @@ -535,6 +606,7 @@ dim, convertStringToChars(excludedNames))); } + /** * Suggest names for a field. The name is computed from field's type * and possible prefixes or suffixes are added. @@ -566,18 +638,27 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static char[][] suggestFieldNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, int modifiers, char[][] excludedNames) { + if(qualifiedTypeName == null || qualifiedTypeName.length == 0) + return CharOperation.NO_CHAR_CHAR; + + char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); + NamingRequestor requestor = new NamingRequestor(); - InternalNamingConventions.suggestFieldNames( - javaProject, - packageName, - qualifiedTypeName, - dim, - modifiers, - null, - excludedNames, - requestor); + InternalNamingConventions.suggestVariableNames( + Flags.isStatic(modifiers) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD, + BK_TYPE_NAME, + typeName, + javaProject, + dim, + null, + excludedNames, + true, + requestor); return requestor.getResults(); } @@ -613,6 +694,9 @@ * @see Flags * @see JavaCore#setOptions(java.util.Hashtable) * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead + * with {@link #VK_INSTANCE_FIELD} or {@link #VK_STATIC_FIELD} as variable kind. */ public static String[] suggestFieldNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, int modifiers, String[] excludedNames) { return convertCharsToString( @@ -624,87 +708,7 @@ modifiers, convertStringToChars(excludedNames))); } - - /** - * Suggest names for a local variable. The name is computed from variable's type - * and possible prefixes or suffixes are added. - *

- * If the type of the local variable is TypeName, the prefix for local variable is pre - * and the suffix for local variable is suf then the proposed names are preTypeNamesuf - * and preNamesuf. If there is no prefix or suffix the proposals are typeName - * and name. - *

- *

- * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and - * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. - *

- *

- * For a complete description of these configurable options, see getDefaultOptions. - * For programmaticaly change these options, see JavaCore#setOptions(). - *

- * - * @param javaProject project which contains the variable. - * @param packageName package of the variable's type. - * @param qualifiedTypeName variable's type. - * @param dim variable's dimension (0 if the variable is not an array). - * @param excludedNames a list of names which cannot be suggested (already used names). - * Can be null if there is no excluded names. - * @return char[][] an array of names. - * @see JavaCore#setOptions(java.util.Hashtable) - * @see JavaCore#getDefaultOptions() - */ - public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { - NamingRequestor requestor = new NamingRequestor(); - InternalNamingConventions.suggestLocalVariableNames( - javaProject, - packageName, - qualifiedTypeName, - dim, - null, - excludedNames, - requestor); - - return requestor.getResults(); - } - - /** - * Suggest names for a local variable. The name is computed from variable's type - * and possible prefixes or suffixes are added. - *

- * If the type of the local variable is TypeName, the prefix for local variable is pre - * and the suffix for local variable is suf then the proposed names are preTypeNamesuf - * and preNamesuf. If there is no prefix or suffix the proposals are typeName - * and name. - *

- *

- * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and - * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. - *

- *

- * For a complete description of these configurable options, see getDefaultOptions. - * For programmaticaly change these options, see JavaCore#setOptions(). - *

- * - * @param javaProject project which contains the variable. - * @param packageName package of the variable's type. - * @param qualifiedTypeName variable's type. - * @param dim variable's dimension (0 if the variable is not an array). - * @param excludedNames a list of names which cannot be suggested (already used names). - * Can be null if there is no excluded names. - * @return char[][] an array of names. - * @see JavaCore#setOptions(java.util.Hashtable) - * @see JavaCore#getDefaultOptions() - */ - public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { - return convertCharsToString( - suggestLocalVariableNames( - javaProject, - packageName.toCharArray(), - qualifiedTypeName.toCharArray(), - dim, - convertStringToChars(excludedNames))); - } - + /** * Suggest name for a getter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -756,7 +760,6 @@ ); } } - /** * Suggest name for a getter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -797,7 +800,114 @@ isBoolean, convertStringToChars(excludedNames))); } + /** + * Suggest names for a local variable. The name is computed from variable's type + * and possible prefixes or suffixes are added. + *

+ * If the type of the local variable is TypeName, the prefix for local variable is pre + * and the suffix for local variable is suf then the proposed names are preTypeNamesuf + * and preNamesuf. If there is no prefix or suffix the proposals are typeName + * and name. + *

+ *

+ * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and + * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. + *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ * + * @param javaProject project which contains the variable. + * @param packageName package of the variable's type. + * @param qualifiedTypeName variable's type. + * @param dim variable's dimension (0 if the variable is not an array). + * @param excludedNames a list of names which cannot be suggested (already used names). + * Can be null if there is no excluded names. + * @return char[][] an array of names. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. + */ + public static char[][] suggestLocalVariableNames(IJavaProject javaProject, char[] packageName, char[] qualifiedTypeName, int dim, char[][] excludedNames) { + if(qualifiedTypeName == null || qualifiedTypeName.length == 0) + return CharOperation.NO_CHAR_CHAR; + + char[] typeName = CharOperation.lastSegment(qualifiedTypeName, '.'); + + NamingRequestor requestor = new NamingRequestor(); + InternalNamingConventions.suggestVariableNames( + VK_LOCAL, + BK_TYPE_NAME, + typeName, + javaProject, + dim, + null, + excludedNames, + true, + requestor); + return requestor.getResults(); + } + /** + * Suggest names for a local variable. The name is computed from variable's type + * and possible prefixes or suffixes are added. + *

+ * If the type of the local variable is TypeName, the prefix for local variable is pre + * and the suffix for local variable is suf then the proposed names are preTypeNamesuf + * and preNamesuf. If there is no prefix or suffix the proposals are typeName + * and name. + *

+ *

+ * This method is affected by the following JavaCore options : {@link JavaCore#CODEASSIST_LOCAL_PREFIXES} and + * {@link JavaCore#CODEASSIST_LOCAL_SUFFIXES}. + *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ * + * @param javaProject project which contains the variable. + * @param packageName package of the variable's type. + * @param qualifiedTypeName variable's type. + * @param dim variable's dimension (0 if the variable is not an array). + * @param excludedNames a list of names which cannot be suggested (already used names). + * Can be null if there is no excluded names. + * @return char[][] an array of names. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + * + * @deprecated Use {@link #suggestVariableNames(int, int, String, IJavaProject, int, String[], boolean)} instead with {@link #VK_LOCAL} as variable kind. + */ + public static String[] suggestLocalVariableNames(IJavaProject javaProject, String packageName, String qualifiedTypeName, int dim, String[] excludedNames) { + return convertCharsToString( + suggestLocalVariableNames( + javaProject, + packageName.toCharArray(), + qualifiedTypeName.toCharArray(), + dim, + convertStringToChars(excludedNames))); + } + private static char[] suggestNewName(char[] name, char[][] excludedNames){ + if(excludedNames == null) { + return name; + } + + char[] newName = name; + int count = 2; + int i = 0; + while (i < excludedNames.length) { + if(CharOperation.equals(newName, excludedNames[i], false)) { + newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); + i = 0; + } else { + i++; + } + } + return newName; + } + /** * Suggest name for a setter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -853,7 +963,6 @@ ); } } - /** * Suggest name for a setter method. The name is computed from field's name * and possible prefixes or suffixes are removed. @@ -893,53 +1002,108 @@ isBoolean, convertStringToChars(excludedNames))); } + + /** + * Suggests names for a variable. The name is computed from a base name and possible prefixes or suffixes are added. + * + *

+ * The base name is used to compute the variable name. + * Some different kinds of base name are possible and each kind is associated to a different heuristic to compute variable names.
+ * The heuristic depends also of the kind of the variable. Each kind of variable is identified by a constant starting with VK_.
+ * When a prefix and a suffix can be added then all combinations of prefix and suffix are suggested. + * If the name is name, the prefix is pre and the suffix is suf then the suggested names will be + * prenamesuf, prename, namesuf and name.
+ *
+ * The different kinds of base name are: + *

+ * Some other kinds could be added in the future. + *

+ *

+ * Each variable kind is affected by the following JavaCore options: + *

+ *

+ *

+ * For a complete description of these configurable options, see getDefaultOptions. + * For programmaticaly change these options, see JavaCore#setOptions(). + *

+ *

+ * Proposed names are sorted by relevance (best proposal first).
+ * The names are proposed in the following order: + *

    + *
  1. Names with prefix and suffix. Longest name are proposed first
  2. + *
  3. Names with prefix. Longest name are proposed first
  4. + *
  5. Names with suffix. Longest name are proposed first
  6. + *
  7. Names without prefix and suffix. Longest name are proposed first
  8. + *
+ *

+ * + * @param variableKind specifies what type the variable is: {@link #VK_LOCAL}, {@link #VK_PARAMETER}, {@link #VK_STATIC_FIELD}, + * {@link #VK_INSTANCE_FIELD} or {@link #VK_CONSTANT_FIELD}. + * @param baseNameKind specifies what type the base name is: {@link #BK_NAME} or {@link #BK_TYPE_NAME} + * @param baseName name used to compute the suggested names. + * @param javaProject project which contains the variable or null to take into account only workspace settings. + * @param dim variable dimension (0 if the field is not an array). + * @param excluded a list of names which cannot be suggested (already used names). + * Can be null if there is no excluded names. + * @param evaluateDefault if set, the result is guaranteed to contain at least one result. If not, the result can be an empty array. + * @return String[] an array of names. + * @see JavaCore#setOptions(java.util.Hashtable) + * @see JavaCore#getDefaultOptions() + * + * @since 3.5 + */ + public static String[] suggestVariableNames( + int variableKind, + int baseNameKind, + String baseName, + IJavaProject javaProject, + int dim, + String[] excluded, + boolean evaluateDefault) { + + NamingRequestor requestor = new NamingRequestor(); + InternalNamingConventions.suggestVariableNames( + variableKind, + baseNameKind, + baseName.toCharArray(), + javaProject, + dim, + null, + convertStringToChars(excluded), + evaluateDefault, + requestor); - private static char[] suggestAccessorName(IJavaProject project, char[] fieldName, int modifiers) { - char[] name = removePrefixAndSuffixForFieldName(project, fieldName, modifiers); - if (name.length > 0 && ScannerHelper.isLowerCase(name[0])) { - name[0] = ScannerHelper.toUpperCase(name[0]); - } - return name; - } - - private static char[] suggestNewName(char[] name, char[][] excludedNames){ - if(excludedNames == null) { - return name; - } - - char[] newName = name; - int count = 2; - int i = 0; - while (i < excludedNames.length) { - if(CharOperation.equals(newName, excludedNames[i], false)) { - newName = CharOperation.concat(name, String.valueOf(count++).toCharArray()); - i = 0; - } else { - i++; - } - } - return newName; - } - - private static String[] convertCharsToString(char[][] c) { - int length = c == null ? 0 : c.length; - String[] s = new String[length]; - for (int i = 0; i < length; i++) { - s[i] = String.valueOf(c[i]); - } - return s; + return convertCharsToString(requestor.getResults()); } - - private static char[][] convertStringToChars(String[] s) { - int length = s == null ? 0 : s.length; - char[][] c = new char[length][]; - for (int i = 0; i < length; i++) { - if(s[i] == null) { - c[i] = CharOperation.NO_CHAR; - } else { - c[i] = s[i].toCharArray(); - } - } - return c; + + private NamingConventions() { + // Not instantiable } } Index: compiler/org/eclipse/jdt/core/compiler/CharOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CharOperation.java,v retrieving revision 1.85 diff -u -r1.85 CharOperation.java --- compiler/org/eclipse/jdt/core/compiler/CharOperation.java 27 Jun 2008 16:04:14 -0000 1.85 +++ compiler/org/eclipse/jdt/core/compiler/CharOperation.java 17 Oct 2008 11:27:16 -0000 @@ -3582,6 +3582,54 @@ } /** + * Answers the result of a char[] conversion to uppercase. Answers null if the given chars array is null. + *
+ * NOTE: If no conversion was necessary, then answers back the argument one. + *
+ *
+ * For example: + *
    + *
  1. + *    chars = { 'A' , 'B' }
    + *    result => { 'A' , 'B' }
    + * 
    + *
  2. + *
  3. + *    array = { 'a', 'B' }
    + *    result => { 'A' , 'B' }
    + * 
    + *
  4. + *
+ * + * @param chars the chars to convert + * @return the result of a char[] conversion to uppercase + * + * @since 3.5 + */ +final static public char[] toUpperCase(char[] chars) { + if (chars == null) + return null; + int length = chars.length; + char[] upperChars = null; + for (int i = 0; i < length; i++) { + char c = chars[i]; + char lc = ScannerHelper.toUpperCase(c); + if ((c != lc) || (upperChars != null)) { + if (upperChars == null) { + System.arraycopy( + chars, + 0, + upperChars = new char[length], + 0, + i); + } + upperChars[i] = lc; + } + } + return upperChars == null ? chars : upperChars; +} + +/** * Answers a new array removing leading and trailing spaces (' '). Answers the given array if there is no * space characters to remove. *
Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java,v retrieving revision 1.28 diff -u -r1.28 AssistOptions.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java 27 Jun 2008 16:04:06 -0000 1.28 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistOptions.java 17 Oct 2008 11:27:16 -0000 @@ -28,6 +28,8 @@ "org.eclipse.jdt.core.codeComplete.fieldPrefixes"; //$NON-NLS-1$ public static final String OPTION_StaticFieldPrefixes = "org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"; //$NON-NLS-1$ + public static final String OPTION_StaticFinalFieldPrefixes = + "org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes"; //$NON-NLS-1$ public static final String OPTION_LocalPrefixes = "org.eclipse.jdt.core.codeComplete.localPrefixes"; //$NON-NLS-1$ public static final String OPTION_ArgumentPrefixes = @@ -36,6 +38,8 @@ "org.eclipse.jdt.core.codeComplete.fieldSuffixes"; //$NON-NLS-1$ public static final String OPTION_StaticFieldSuffixes = "org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"; //$NON-NLS-1$ + public static final String OPTION_StaticFinalFieldSuffixes = + "org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes"; //$NON-NLS-1$ public static final String OPTION_LocalSuffixes = "org.eclipse.jdt.core.codeComplete.localSuffixes"; //$NON-NLS-1$ public static final String OPTION_ArgumentSuffixes = @@ -61,10 +65,12 @@ public boolean suggestStaticImport = true; public char[][] fieldPrefixes = null; public char[][] staticFieldPrefixes = null; + public char[][] staticFinalFieldPrefixes = null; public char[][] localPrefixes = null; public char[][] argumentPrefixes = null; public char[][] fieldSuffixes = null; public char[][] staticFieldSuffixes = null; + public char[][] staticFinalFieldSuffixes = null; public char[][] localSuffixes = null; public char[][] argumentSuffixes = null; @@ -121,6 +127,16 @@ } } } + if ((optionValue = optionsMap.get(OPTION_StaticFinalFieldPrefixes)) != null) { + if (optionValue instanceof String) { + String stringValue = (String) optionValue; + if (stringValue.length() > 0){ + this.staticFinalFieldPrefixes = splitAndTrimOn(',', stringValue.toCharArray()); + } else { + this.staticFinalFieldPrefixes = null; + } + } + } if ((optionValue = optionsMap.get(OPTION_LocalPrefixes)) != null) { if (optionValue instanceof String) { String stringValue = (String) optionValue; @@ -161,6 +177,16 @@ } } } + if ((optionValue = optionsMap.get(OPTION_StaticFinalFieldSuffixes)) != null) { + if (optionValue instanceof String) { + String stringValue = (String) optionValue; + if (stringValue.length() > 0){ + this.staticFinalFieldSuffixes = splitAndTrimOn(',', stringValue.toCharArray()); + } else { + this.staticFinalFieldSuffixes = null; + } + } + } if ((optionValue = optionsMap.get(OPTION_LocalSuffixes)) != null) { if (optionValue instanceof String) { String stringValue = (String) optionValue; Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v retrieving revision 1.379 diff -u -r1.379 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 13 Oct 2008 20:06:01 -0000 1.379 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 17 Oct 2008 11:27:16 -0000 @@ -342,10 +342,6 @@ private final static int SUPERTYPE = 1; private final static int SUBTYPE = 2; - private final static int FIELD = 0; - private final static int LOCAL = 1; - private final static int ARGUMENT = 2; - int expectedTypesPtr = -1; TypeBinding[] expectedTypes = new TypeBinding[1]; int expectedTypesFilter; @@ -1559,7 +1555,15 @@ this.completionToken = field.realName; - findVariableNames(field.realName, field.type, excludeNames, null, FIELD, field.modifiers); + + int kind = + (field.modifiers & ClassFileConstants.AccStatic) == 0 ? + InternalNamingConventions.VK_INSTANCE_FIELD : + (field.modifiers & ClassFileConstants.AccFinal) == 0 ? + InternalNamingConventions.VK_STATIC_FIELD : + InternalNamingConventions.VK_CONSTANT_FIELD; + + findVariableNames(field.realName, field.type, excludeNames, null, kind); } } @@ -1826,11 +1830,11 @@ int kind; if (variable instanceof CompletionOnLocalName){ this.completionToken = ((CompletionOnLocalName) variable).realName; - kind = LOCAL; + kind = InternalNamingConventions.VK_LOCAL; } else { CompletionOnArgumentName arg = (CompletionOnArgumentName) variable; this.completionToken = arg.realName; - kind = arg.isCatchArgument ? LOCAL : ARGUMENT; + kind = arg.isCatchArgument ? InternalNamingConventions.VK_LOCAL : InternalNamingConventions.VK_PARAMETER; } char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, variable); @@ -1848,7 +1852,7 @@ System.arraycopy(discouragedNames, 0, discouragedNames = new char[localCount][], 0, localCount); - findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind, variable.modifiers); + findVariableNames(this.completionToken, variable.type, discouragedNames, forbiddenNames, kind); } } @@ -2166,7 +2170,15 @@ this.completionToken = method.selector; - findVariableNames(this.completionToken, method.returnType, excludeNames, null, FIELD, method.modifiers); + + int kind = + (method.modifiers & ClassFileConstants.AccStatic) == 0 ? + InternalNamingConventions.VK_INSTANCE_FIELD : + (method.modifiers & ClassFileConstants.AccFinal) == 0 ? + InternalNamingConventions.VK_STATIC_FIELD : + InternalNamingConventions.VK_CONSTANT_FIELD; + + findVariableNames(this.completionToken, method.returnType, excludeNames, null, kind); } } @@ -9674,8 +9686,7 @@ final char[][] forbiddenNames, boolean forCollection, int dim, - int kind, - int modifiers){ + int kind){ if(sourceName == null || sourceName.length == 0) return; @@ -9755,39 +9766,16 @@ } }; - switch (kind) { - case FIELD : - InternalNamingConventions.suggestFieldNames( - this.javaProject, - qualifiedPackageName, - qualifiedSourceName, - dim, - modifiers, - token, - discouragedNames, - namingRequestor); - break; - case LOCAL : - InternalNamingConventions.suggestLocalVariableNames( - this.javaProject, - qualifiedPackageName, - qualifiedSourceName, - dim, - token, - discouragedNames, - namingRequestor); - break; - case ARGUMENT : - InternalNamingConventions.suggestArgumentNames( - this.javaProject, - qualifiedPackageName, - qualifiedSourceName, - dim, - token, - discouragedNames, - namingRequestor); - break; - } + InternalNamingConventions.suggestVariableNames( + kind, + InternalNamingConventions.BK_SIMPLE_TYPE_NAME, + qualifiedSourceName, + this.javaProject, + dim, + token, + discouragedNames, + true, + namingRequestor); } // Helper method for private void findVariableNames(char[] name, TypeReference type ) @@ -9800,8 +9788,7 @@ char[][] discouragedNames, final char[][] forbiddenNames, int dim, - int kind, - int modifiers){ + int kind){ findVariableName( token, qualifiedPackageName, @@ -9812,8 +9799,7 @@ forbiddenNames, false, dim, - kind, - modifiers); + kind); } private void findVariableNameForCollection( char[] token, @@ -9823,8 +9809,7 @@ final TypeBinding typeBinding, char[][] discouragedNames, final char[][] forbiddenNames, - int kind, - int modifiers){ + int kind){ findVariableName( token, @@ -9836,10 +9821,9 @@ forbiddenNames, false, 1, - kind, - modifiers); + kind); } - private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind, int modifiers){ + private void findVariableNames(char[] name, TypeReference type , char[][] discouragedNames, char[][] forbiddenNames, int kind){ if(type != null && type.resolvedType != null) { TypeBinding tb = type.resolvedType; @@ -9855,8 +9839,7 @@ discouragedNames, forbiddenNames, type.dimensions(), - kind, - modifiers); + kind); if (tb.isParameterizedType() && tb.findSuperTypeOriginatingFrom(TypeIds.T_JavaUtilCollection, false) != null) { @@ -9872,8 +9855,7 @@ tb, discouragedNames, forbiddenNames, - kind, - modifiers); + kind); } } } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v retrieving revision 1.189 diff -u -r1.189 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 10 Oct 2008 07:29:03 -0000 1.189 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 17 Oct 2008 11:27:24 -0000 @@ -5134,8 +5134,123 @@ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( - "nameRequestor[VARIABLE_DECLARATION]{nameRequestor, null, Ltest.TypeNameRequestor;, nameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + - "nameTypeNameRequestor[VARIABLE_DECLARATION]{nameTypeNameRequestor, null, Ltest.TypeNameRequestor;, nameTypeNameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + "nameTypeNameRequestor[VARIABLE_DECLARATION]{nameTypeNameRequestor, null, Ltest.TypeNameRequestor;, nameTypeNameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + + "nameRequestor[VARIABLE_DECLARATION]{nameRequestor, null, Ltest.TypeNameRequestor;, nameRequestor, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NAME_LESS_NEW_CHARACTERS + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName3() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor \n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor "; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + + "REQUESTOR[VARIABLE_DECLARATION]{REQUESTOR, null, Ltest.TypeNameRequestor;, REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + + "TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName4() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor nam\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor nam"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "NAM_REQUESTOR[VARIABLE_DECLARATION]{NAM_REQUESTOR, null, Ltest.TypeNameRequestor;, NAM_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + + "NAM_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{NAM_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAM_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED) + "}\n" + + "NAME_REQUESTOR[VARIABLE_DECLARATION]{NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_NAME_LESS_NEW_CHARACTERS+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName5() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor ZZ\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor ZZ"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "ZZ_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_REQUESTOR[VARIABLE_DECLARATION]{ZZ_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName6() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor ZZN\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor ZZN"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "ZZN_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZN_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZN_REQUESTOR[VARIABLE_DECLARATION]{ZZN_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZN_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZN_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZN_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", + requestor.getResults()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 +public void testCompletionFieldName7() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TypeNameRequestor.java", + "package test;"+ + "public class TypeNameRequestor {\n" + + " public static final TypeNameRequestor ZZ_N\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "final TypeNameRequestor ZZ_N"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "ZZ_N_REQUESTOR[VARIABLE_DECLARATION]{ZZ_N_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_N_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_N_TYPE_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_N_TYPE_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_N_TYPE_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}\n" + + "ZZ_NAME_REQUESTOR[VARIABLE_DECLARATION]{ZZ_NAME_REQUESTOR, null, Ltest.TypeNameRequestor;, ZZ_NAME_REQUESTOR, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_NAME_LESS_NEW_CHARACTERS + R_NON_RESTRICTED) + "}", requestor.getResults()); } @@ -13880,7 +13995,9 @@ assertEquals( "element:class1 completion:class1 relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + - "element:myClass completion:myClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED), + "element:fooMyClass completion:fooMyClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + + "element:myClass completion:myClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + + "element:testFooMyClass completion:testFooMyClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED), requestor.getResults()); } public void testCompletionVariableName10() throws JavaModelException { @@ -14270,10 +14387,10 @@ cu.codeComplete(cursorLocation, requestor); assertEquals( - "element:bar_MyClass completion:bar_MyClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + + "element:barMyClass completion:barMyClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + "element:class1 completion:class1 relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + "element:myClass completion:myClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"\n" + - "element:test_Bar_MyClass completion:test_Bar_MyClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED), + "element:testBarMyClass completion:testBarMyClass relevance:"+(R_DEFAULT + R_INTERESTING + R_CASE+ R_NON_RESTRICTED), requestor.getResults()); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=150228 Index: src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java,v retrieving revision 1.22 diff -u -r1.22 NamingConventionTests.java --- src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java 27 Jun 2008 16:02:40 -0000 1.22 +++ src/org/eclipse/jdt/core/tests/model/NamingConventionTests.java 17 Oct 2008 11:27:24 -0000 @@ -41,7 +41,7 @@ super.setUp(); this.project = createJavaProject("P", new String[]{"src"}, "bin"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ this.oldOptions = JavaCore.getOptions(); - this.abortOnFailure = false; // some tests have failing one time on macos boxes => do not abort on failures +// this.abortOnFailure = false; // some tests have failing one time on macos boxes => do not abort on failures } /** * Cleanup after the previous test. @@ -53,45 +53,96 @@ super.tearDown(); } -private String toString(char[][] suggestions) { - if(suggestions == null) { - return ""; //$NON-NLS-1$ - } - - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < suggestions.length; i++) { - if(i != 0) { - buffer.append('\n'); - } - buffer.append(suggestions[i]); - } - return buffer.toString(); +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testGetBaseName001() { + String baseName = NamingConventions.getBaseName( + NamingConventions.VK_INSTANCE_FIELD, + "OneName", //$NON-NLS-1$ + this.project); + + assertEquals( + "OneName", //$NON-NLS-1$ + baseName); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testGetBaseName002() { + String baseName = NamingConventions.getBaseName( + NamingConventions.VK_CONSTANT_FIELD, + "ONE_NAME", //$NON-NLS-1$ + this.project); + + assertEquals( + "OneName", //$NON-NLS-1$ + baseName); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testGetBaseName003() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ + options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ + JavaCore.setOptions(options); + + String baseName = NamingConventions.getBaseName( + NamingConventions.VK_INSTANCE_FIELD, + "preOneNamesuf", //$NON-NLS-1$ + this.project); + + assertEquals( + "OneName", //$NON-NLS-1$ + baseName); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testGetBaseName004() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ + options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ + JavaCore.setOptions(options); + + String baseName = NamingConventions.getBaseName( + NamingConventions.VK_CONSTANT_FIELD, + "preONE_NAMEsuf", //$NON-NLS-1$ + this.project); + + assertEquals( + "OneName", //$NON-NLS-1$ + baseName); } public void testSuggestFieldName001() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + assumeEquals( - "name\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName002() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneClass".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); - + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneClass", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + assumeEquals( - "class1\n" + //$NON-NLS-1$ - "oneClass", //$NON-NLS-1$ + "oneClass\n" + //$NON-NLS-1$ + "class1", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName003() { @@ -99,19 +150,20 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( - "fName\n" + //$NON-NLS-1$ "fOneName\n" + //$NON-NLS-1$ - "name\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "fName\n" + //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName004() { @@ -119,19 +171,20 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"_"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( - "_name\n" + //$NON-NLS-1$ "_oneName\n" + //$NON-NLS-1$ - "name\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "_name\n" + //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName005() { @@ -139,20 +192,21 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"f"); //$NON-NLS-1$ options.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,"fg"); //$NON-NLS-1$ JavaCore.setOptions(options); - - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - Flags.AccStatic, - CharOperation.NO_CHAR_CHAR); + + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_STATIC_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( - "fgName\n" + //$NON-NLS-1$ "fgOneName\n" + //$NON-NLS-1$ - "name\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "fgName\n" + //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName006() { @@ -161,23 +215,24 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( - "preNamesuf\n" + //$NON-NLS-1$ "preOneNamesuf\n" + //$NON-NLS-1$ - "preName\n" + //$NON-NLS-1$ + "preNamesuf\n" + //$NON-NLS-1$ "preOneName\n" + //$NON-NLS-1$ - "namesuf\n" + //$NON-NLS-1$ + "preName\n" + //$NON-NLS-1$ "oneNamesuf\n" + //$NON-NLS-1$ - "name\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "namesuf\n" + //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName007() { @@ -186,13 +241,14 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "int".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "int", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "preIsuf\n" + //$NON-NLS-1$ @@ -202,17 +258,18 @@ toString(suggestions)); } public void testSuggestFieldName008() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"name".toCharArray()}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{"name"}, //$NON-NLS-1$ + true); assumeEquals( - "name2\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name2", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName009() { @@ -221,23 +278,24 @@ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$ - + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{"preNamesuf"}, //$NON-NLS-1$ + true); + assumeEquals( - "preName2suf\n" + //$NON-NLS-1$ "preOneNamesuf\n" + //$NON-NLS-1$ - "preName\n" + //$NON-NLS-1$ + "preName2suf\n" + //$NON-NLS-1$ "preOneName\n" + //$NON-NLS-1$ - "namesuf\n" + //$NON-NLS-1$ + "preName\n" + //$NON-NLS-1$ "oneNamesuf\n" + //$NON-NLS-1$ - "name\n" + //$NON-NLS-1$ - "oneName", //$NON-NLS-1$ + "namesuf\n" + //$NON-NLS-1$ + "oneName\n" + //$NON-NLS-1$ + "name", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName010() { @@ -245,100 +303,108 @@ options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ JavaCore.setOptions(options); - - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "OneName".toCharArray(), //$NON-NLS-1$ - 1, - 0, - new char[][]{"preNamesuf".toCharArray()}); //$NON-NLS-1$ + + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "OneName", //$NON-NLS-1$ + this.project, + 1, + new String[]{"preNamesuf"}, //$NON-NLS-1$ + true); assumeEquals( - "preNamessuf\n" + //$NON-NLS-1$ "preOneNamessuf\n" + //$NON-NLS-1$ - "preNames\n" + //$NON-NLS-1$ + "preNamessuf\n" + //$NON-NLS-1$ "preOneNames\n" + //$NON-NLS-1$ - "namessuf\n" + //$NON-NLS-1$ + "preNames\n" + //$NON-NLS-1$ "oneNamessuf\n" + //$NON-NLS-1$ - "names\n" + //$NON-NLS-1$ - "oneNames", //$NON-NLS-1$ + "namessuf\n" + //$NON-NLS-1$ + "oneNames\n" + //$NON-NLS-1$ + "names", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName011() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c".toCharArray(), //$NON-NLS-1$ - "Factory".toCharArray(), //$NON-NLS-1$ - 1, - 0, - CharOperation.NO_CHAR_CHAR); //$NON-NLS-1$ + + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "Factory", //$NON-NLS-1$ + this.project, + 1, + new String[]{}, + true); assumeEquals( "factories", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName012() { - String[] suggestions = NamingConventions.suggestFieldNames( - this.project, - "a.b.c", //$NON-NLS-1$ - "FooBar", //$NON-NLS-1$ - 0, - 0, - new String[]{"bar"}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "FooBar", //$NON-NLS-1$ + this.project, + 0, + new String[]{"bar"}, //$NON-NLS-1$ + true); assumeEquals( - "bar2\n" + //$NON-NLS-1$ - "fooBar", //$NON-NLS-1$ + "fooBar\n" + //$NON-NLS-1$ + "bar2", //$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName013() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "java.lang".toCharArray(), //$NON-NLS-1$ - "Class".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "Class", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "class1",//$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName014() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "java.lang".toCharArray(), //$NON-NLS-1$ - "Class".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"class1".toCharArray()}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "Class", //$NON-NLS-1$ + this.project, + 0, + new String[]{"class1"}, //$NON-NLS-1$ + true); assumeEquals( "class2",//$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName015() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "#".toCharArray(), //$NON-NLS-1$ - 0, - 0, - CharOperation.NO_CHAR_CHAR); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "#", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "name",//$NON-NLS-1$ toString(suggestions)); } public void testSuggestFieldName016() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "#".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{"name".toCharArray()}); //$NON-NLS-1$ + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "#", //$NON-NLS-1$ + this.project, + 0, + new String[]{"name"}, //$NON-NLS-1$ + true); assumeEquals( "name2",//$NON-NLS-1$ @@ -348,13 +414,14 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName017() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "names".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "names", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( "names",//$NON-NLS-1$ @@ -364,13 +431,14 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName018() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "names".toCharArray(), //$NON-NLS-1$ - 1, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "names", //$NON-NLS-1$ + this.project, + 1, + new String[]{}, + true); assumeEquals( "names",//$NON-NLS-1$ @@ -380,36 +448,385 @@ * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName019() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "MyClass".toCharArray(), //$NON-NLS-1$ - 0, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyClass", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( - "class1\n" + //$NON-NLS-1$ - "myClass", //$NON-NLS-1$ + "myClass\n" + //$NON-NLS-1$ + "class1", //$NON-NLS-1$ toString(suggestions)); } /* * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=35356 */ public void testSuggestFieldName020() { - char[][] suggestions = NamingConventions.suggestFieldNames( - this.project, - "".toCharArray(), //$NON-NLS-1$ - "MyClass".toCharArray(), //$NON-NLS-1$ - 1, - 0, - new char[][]{}); + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyClass", //$NON-NLS-1$ + this.project, + 1, + new String[]{}, + true); + + assumeEquals( + "myClasses\n" + //$NON-NLS-1$ + "classes", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName021() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "MY_TYPE\n" + //$NON-NLS-1$ + "TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName022() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ + options.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ + JavaCore.setOptions(options); + + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "preMY_TYPEsuf\n" + //$NON-NLS-1$ + "preTYPEsuf\n" + //$NON-NLS-1$ + "preMY_TYPE\n" + //$NON-NLS-1$ + "preTYPE\n" + //$NON-NLS-1$ + "MY_TYPEsuf\n" + //$NON-NLS-1$ + "TYPEsuf\n" + //$NON-NLS-1$ + "MY_TYPE\n" + //$NON-NLS-1$ + "TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName023() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_NAME, + "oneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "oneName", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName024() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ + options.put(JavaCore.CODEASSIST_FIELD_SUFFIXES,"suf"); //$NON-NLS-1$ + JavaCore.setOptions(options); + + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_NAME, + "oneName", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "preOneNamesuf\n" + //$NON-NLS-1$ + "preOneName\n" + //$NON-NLS-1$ + "oneNamesuf\n" + //$NON-NLS-1$ + "oneName", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName025() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_TYPE_NAME, + "My_Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "MY_TYPE\n" + //$NON-NLS-1$ + "TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName026() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_TYPE_NAME, + "_MyType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "MY_TYPE\n" + //$NON-NLS-1$ + "TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName027() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyType_", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "MY_TYPE\n" + //$NON-NLS-1$ + "TYPE", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName028() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_CONSTANT_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyTyp_e", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "MY_TYP_E\n" + //$NON-NLS-1$ + "TYP_E\n" + //$NON-NLS-1$ + "E", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName029() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "My1Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "my1Type\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName030() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "M1yType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "m1yType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName031() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "MY1Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "my1Type\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName032() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "M1YType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "m1yType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName033() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "My_First_Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "myFirstType\n" + //$NON-NLS-1$ + "firstType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName034() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "MY_FIRST_Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "myFirstType\n" + //$NON-NLS-1$ + "firstType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName035() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "my_first_Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "myFirstType\n" + //$NON-NLS-1$ + "firstType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName036() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "MyFirst_9_Type", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "myFirst_9Type\n" + //$NON-NLS-1$ + "first_9Type\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName037() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "AType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); + + assumeEquals( + "aType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ + toString(suggestions)); +} +/* + * bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38111 + */ +public void testSuggestFieldName038() { + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_INSTANCE_FIELD, + NamingConventions.BK_TYPE_NAME, + "aType", //$NON-NLS-1$ + this.project, + 0, + new String[]{}, + true); assumeEquals( - "classes\n" + //$NON-NLS-1$ - "myClasses", //$NON-NLS-1$ + "aType\n" + //$NON-NLS-1$ + "type", //$NON-NLS-1$ toString(suggestions)); } +/** @deprecated */ public void testRemovePrefixAndSuffixForFieldName001() { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre"); //$NON-NLS-1$ @@ -425,6 +842,7 @@ "oneName", //$NON-NLS-1$ new String(name)); } +/** @deprecated */ public void testRemovePrefixAndSuffixForFieldName002() { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pr, pre"); //$NON-NLS-1$ @@ -440,6 +858,7 @@ "preOneNamesuf", //$NON-NLS-1$ new String(name)); } +/** @deprecated */ public void testRemovePrefixAndSuffixForFieldName003() { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pr, pre"); //$NON-NLS-1$ @@ -456,6 +875,7 @@ new String(name)); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=114086 +/** @deprecated */ public void testRemovePrefixAndSuffixForFieldName004() { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.CODEASSIST_FIELD_PREFIXES,"pre,"); //$NON-NLS-1$ @@ -470,6 +890,7 @@ "oneName", //$NON-NLS-1$ new String(name)); } +/** @deprecated */ public void testRemovePrefixAndSuffixForLocalName001() { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.CODEASSIST_LOCAL_PREFIXES,"pr, pre"); //$NON-NLS-1$ @@ -633,12 +1054,14 @@ newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); this.project.setOptions(newOptions); - String[] suggestions = NamingConventions.suggestLocalVariableNames( + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_LOCAL, + NamingConventions.BK_TYPE_NAME, + "Enum", this.project, - "",//$NON-NLS-1$ - "Enum",//$NON-NLS-1$ 0, - new String[]{"o"}); + new String[]{"o"}, //$NON-NLS-1$ + true); assumeEquals( "enum1", //$NON-NLS-1$ @@ -659,12 +1082,14 @@ newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); this.project.setOptions(newOptions); - String[] suggestions = NamingConventions.suggestLocalVariableNames( + String[] suggestions = NamingConventions.suggestVariableNames( + NamingConventions.VK_LOCAL, + NamingConventions.BK_TYPE_NAME, + "Enums", this.project, - "",//$NON-NLS-1$ - "Enums",//$NON-NLS-1$ 0, - new String[]{"o"}); + new String[]{"o"}, //$NON-NLS-1$ + true); assumeEquals( "enums", //$NON-NLS-1$