mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
2004-08-25 Chris Wiebe
add namespace validation to CConventions * index/org/eclipse/cdt/internal/core/messages.properties * src/org/eclipse/cdt/core/CConventions.java
This commit is contained in:
parent
3083b4d98c
commit
c399a92017
3 changed files with 86 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-08-25 Chris Wiebe
|
||||
|
||||
add namespace validation to CConventions
|
||||
* index/org/eclipse/cdt/internal/core/messages.properties
|
||||
* src/org/eclipse/cdt/core/CConventions.java
|
||||
|
||||
2004-08-25 Alain Magloire
|
||||
|
||||
Fix for PR 72078
|
||||
|
|
|
@ -21,14 +21,23 @@ indexNotificationJob=Updating C/C++ Indexer clients
|
|||
|
||||
convention.illegalIdentifier= Illegal identifier
|
||||
convention.invalid= Invalid identifier
|
||||
convention.scope.leadingUnderscore= Scope starts with underscore
|
||||
convention.scope.lowercaseName= Scope starts with lower case
|
||||
convention.scope.nullName= Scope name is null
|
||||
convention.scope.emptyName= Scope name is empty
|
||||
convention.scope.dotName= Scope name starts or ends with a .
|
||||
convention.scope.nameWithBlanks= Scop name has blanks
|
||||
convention.scope.nameWithBlanks= Scope name has blanks
|
||||
|
||||
convention.class.nullName= Class name is null
|
||||
convention.class.nameWithBlanks= Class name has blanks
|
||||
convention.class.dollarName= Class name has $
|
||||
convention.class.leadingUnderscore= Class name starts with underscore
|
||||
convention.class.lowercaseName= Class name starts with lower case
|
||||
convention.class.invalidName= Class name is invalid
|
||||
|
||||
convention.namespace.nullName= Namespace is null
|
||||
convention.namespace.nameWithBlanks= Namespace has blanks
|
||||
convention.namespace.dollarName= Namespace has $
|
||||
convention.namespace.leadingUnderscore= Namespace starts with underscore
|
||||
convention.namespace.lowercaseName= Namespace starts with lower case
|
||||
convention.namespace.invalidName= Namespace is invalid
|
||||
|
|
|
@ -114,7 +114,10 @@ public class CConventions {
|
|||
if (CharOperation.contains('$', scannedID)) {
|
||||
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.dollarName"), null); //$NON-NLS-1$
|
||||
}
|
||||
if ((scannedID.length > 0 && Character.isLowerCase(scannedID[0]))) {
|
||||
if (scannedID.length > 0 && scannedID[0] == '_') {
|
||||
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.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.class.lowercaseName"), null); //$NON-NLS-1$
|
||||
}
|
||||
return CModelStatus.VERIFIED_OK;
|
||||
|
@ -122,6 +125,69 @@ public class CConventions {
|
|||
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.invalidName", name), null); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the given CPP namespace name, either simple or qualified. For
|
||||
* example, <code>"A::B::C"</code>, or <code>"C"</code>.
|
||||
* <p>
|
||||
*
|
||||
* @param name the name of a namespace
|
||||
* @return a status object with code <code>IStatus.OK</code> if
|
||||
* the given name is valid as a CPP class 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 validateNamespaceName(String name) {
|
||||
if (name == null) {
|
||||
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.namespace.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.namespace.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.namespace.dollarName"), null); //$NON-NLS-1$
|
||||
}
|
||||
if (scannedID.length > 0 && scannedID[0] == '_') {
|
||||
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.namespace.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.namespace.lowercaseName"), null); //$NON-NLS-1$
|
||||
// }
|
||||
return CModelStatus.VERIFIED_OK;
|
||||
} else {
|
||||
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.invalidName", name), null); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the given scope name.
|
||||
* <p>
|
||||
|
@ -154,6 +220,9 @@ public class CConventions {
|
|||
if (scannedID == null) {
|
||||
return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.illegalIdentifier", typeName), null); //$NON-NLS-1$
|
||||
}
|
||||
if (firstToken && scannedID.length > 0 && scannedID[0] == '_') {
|
||||
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.leadingUnderscore"), null); //$NON-NLS-1$
|
||||
}
|
||||
if (firstToken && scannedID.length > 0 && Character.isLowerCase(scannedID[0])) {
|
||||
return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.lowercaseName"), null); //$NON-NLS-1$
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue