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, false);
}
} else {
tempNames = computeNonBaseTypeNames(baseName, isConstantField, true);
}
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') {
boolean precededByAVowel = false;
if(tempName.length > 1) {
switch (tempName[length-2]) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
precededByAVowel = true;
break;
}
}
if (precededByAVowel) {
System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
tempName[length] = 'S';
} else {
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') {
boolean precededByAVowel = false;
if(tempName.length > 1) {
switch (tempName[length-2]) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
precededByAVowel = true;
break;
}
}
if (precededByAVowel) {
System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
tempName[length] = 's';
} else {
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;