1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

fix for 124971 by Janees Elamkulam <janees.ek@in.ibm.com>

This commit is contained in:
Chris Recoskie 2006-07-27 11:48:26 +00:00
parent 92753b5ecf
commit 1fa5b46efe
2 changed files with 68 additions and 0 deletions

View file

@ -455,4 +455,65 @@ public class CConventions {
return val;
}
/**
* Validate the given CPP enum name, either simple or qualified. For
* example, <code>"A::B::C"</code>, or <code>"C"</code>.
* <p>
*
* @param name the name of a enum
* @return a status object with code <code>IStatus.OK</code> if
* the given name is valid as a CPP enum name,
* a status with code <code>IStatus.WARNING</code>
* indicating why the given name is discouraged,
* otherwise a status object indicating what is wrong with
* the name
*/
public static IStatus validateEnumName(String name) {
if (name == null) {
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.enum.nullName"), null); //$NON-NLS-1$
}
String trimmed = name.trim();
if ((!name.equals(trimmed)) || (name.indexOf(" ") != -1) ){ //$NON-NLS-1$
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.enum.nameWithBlanks"), null); //$NON-NLS-1$
}
int index = name.lastIndexOf(scopeResolutionOperator);
char[] scannedID;
if (index == -1) {
// simple name
IStatus status = validateIdentifier(name);
if (!status.isOK()){
return status;
}
scannedID = name.toCharArray();
} else {
// qualified name
String pkg = name.substring(0, index).trim();
IStatus status = validateScopeName(pkg);
if (!status.isOK()) {
return status;
}
String type = name.substring(index + scopeResolutionOperator.length()).trim();
status = validateIdentifier(type);
if (!status.isOK()){
return status;
}
scannedID = type.toCharArray();
}
if (scannedID != null) {
if (CharOperation.contains('$', scannedID)) {
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.enum.dollarName"), null); //$NON-NLS-1$
}
if (scannedID.length > 0 && scannedID[0] == '_') {
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.enum.leadingUnderscore"), null); //$NON-NLS-1$
}
if (scannedID.length > 0 && Character.isLowerCase(scannedID[0])) {
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.enum.lowercaseName"), null); //$NON-NLS-1$
}
return CModelStatus.VERIFIED_OK;
}
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.enum.invalidName"), null); //$NON-NLS-1$
}
}

View file

@ -48,3 +48,10 @@ convention.filename.possiblyInvalid=File name contains non-standard or illegal c
convention.filename.nameWithBlanks=File name contains spaces
convention.headerFilename.filetype=File extension does not correspond to known header file types
convention.sourceFilename.filetype=File extension does not correspond to known source file types
convention.enum.nullName= Enum name is null
convention.enum.nameWithBlanks= Enum name has blanks
convention.enum.dollarName= Enum name has $
convention.enum.leadingUnderscore= Enum name starts with underscore
convention.enum.lowercaseName= Enum name starts with lower case
convention.enum.invalidName= Enum name is invalid