mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 327846 - Method names conflicting with Java keywords should have underscore prepended, not appended. Expand list of Java keywords. General cleanup. r=bsmedberg. xulrunner only
Original committer: pedemont%us.ibm.com Original revision: 1.40 Original date: 2006/03/30 22:31:56
This commit is contained in:
parent
644d9a41cb
commit
d065efbcb1
@ -855,7 +855,8 @@ SetupParams(JNIEnv *env, const jobject aParam, PRUint8 aType, PRBool aIsOut,
|
||||
{
|
||||
LOG(("long (void*)\n"));
|
||||
if (!aIsOut && !aIsArrayElement) { // 'in'
|
||||
aVariant.val.p = (void*) env->CallLongMethod(aParam, longValueMID);
|
||||
aVariant.val.p =
|
||||
NS_REINTERPRET_CAST(void*, env->CallLongMethod(aParam, longValueMID));
|
||||
} else { // 'inout' & 'array'
|
||||
jlong value;
|
||||
if (aParam) {
|
||||
@ -871,7 +872,8 @@ SetupParams(JNIEnv *env, const jobject aParam, PRUint8 aType, PRBool aIsOut,
|
||||
}
|
||||
aVariant.SetPtrIsData();
|
||||
} else { // 'array'
|
||||
NS_STATIC_CAST(void**, aVariant.val.p)[aIndex] = (void*) value;
|
||||
NS_STATIC_CAST(void**, aVariant.val.p)[aIndex] =
|
||||
NS_REINTERPRET_CAST(void*, value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1284,6 +1286,53 @@ FinalizeParams(JNIEnv *env, const nsXPTParamInfo &aParamInfo, PRUint8 aType,
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
QueryAttributeInfo(nsIInterfaceInfo* aIInfo, const char* aMethodName,
|
||||
PRBool aCapitalizedAttr, PRUint16* aMethodIndex,
|
||||
const nsXPTMethodInfo** aMethodInfo)
|
||||
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// An 'attribute' will start with either "get" or "set". But first,
|
||||
// we check the length, in order to skip over method names that match exactly
|
||||
// "get" or "set".
|
||||
if (strlen(aMethodName) > 3) {
|
||||
if (strncmp("get", aMethodName, 3) == 0) {
|
||||
char* getterName = strdup(aMethodName + 3);
|
||||
if (!aCapitalizedAttr) {
|
||||
getterName[0] = tolower(getterName[0]);
|
||||
}
|
||||
rv = aIInfo->GetMethodInfoForName(getterName, aMethodIndex, aMethodInfo);
|
||||
free(getterName);
|
||||
} else if (strncmp("set", aMethodName, 3) == 0) {
|
||||
char* setterName = strdup(aMethodName + 3);
|
||||
if (!aCapitalizedAttr) {
|
||||
setterName[0] = tolower(setterName[0]);
|
||||
}
|
||||
rv = aIInfo->GetMethodInfoForName(setterName, aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// If this succeeded, GetMethodInfoForName will have returned the
|
||||
// method info for the 'getter'. We want the 'setter', so increase
|
||||
// method index by one ('setter' immediately follows the 'getter'),
|
||||
// and get its method info.
|
||||
(*aMethodIndex)++;
|
||||
rv = aIInfo->GetMethodInfo(*aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Double check that this methodInfo matches the given method.
|
||||
if (!(*aMethodInfo)->IsSetter() ||
|
||||
strcmp(setterName, (*aMethodInfo)->name) != 0) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(setterName);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an interface info struct and a method name, returns the method info
|
||||
* and index, if that method exists.
|
||||
@ -1296,84 +1345,39 @@ nsresult
|
||||
QueryMethodInfo(nsIInterfaceInfo* aIInfo, const char* aMethodName,
|
||||
PRUint16* aMethodIndex, const nsXPTMethodInfo** aMethodInfo)
|
||||
{
|
||||
// Skip over any leading underscores, since these are methods that conflicted
|
||||
// with existing Java keywords
|
||||
const char* methodName = aMethodName;
|
||||
if (methodName[0] == '_') {
|
||||
methodName++;
|
||||
}
|
||||
|
||||
// The common case is that the method name is lower case, so we check
|
||||
// that first.
|
||||
nsresult rv;
|
||||
rv = aIInfo->GetMethodInfoForName(aMethodName, aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
// If there is no method called <aMethodName>, then maybe it is an
|
||||
// 'attribute'. An 'attribute' will start with "get" or "set". But first,
|
||||
// we check the length, in order to skip over method names that match exactly
|
||||
// "get" or "set".
|
||||
if (strlen(aMethodName) > 3) {
|
||||
if (strncmp("get", aMethodName, 3) == 0) {
|
||||
char* getterName = strdup(aMethodName + 3);
|
||||
getterName[0] = tolower(getterName[0]);
|
||||
rv = aIInfo->GetMethodInfoForName(getterName, aMethodIndex, aMethodInfo);
|
||||
free(getterName);
|
||||
} else if (strncmp("set", aMethodName, 3) == 0) {
|
||||
char* setterName = strdup(aMethodName + 3);
|
||||
setterName[0] = tolower(setterName[0]);
|
||||
rv = aIInfo->GetMethodInfoForName(setterName, aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// If this succeeded, GetMethodInfoForName will have returned the
|
||||
// method info for the 'getter'. We want the 'setter', so increase
|
||||
// method index by one ('setter' immediately follows the 'getter'),
|
||||
// and get its method info.
|
||||
(*aMethodIndex)++;
|
||||
rv = aIInfo->GetMethodInfo(*aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Double check that this methodInfo matches the given method.
|
||||
if (!(*aMethodInfo)->IsSetter() ||
|
||||
strcmp(setterName, (*aMethodInfo)->name) != 0) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(setterName);
|
||||
}
|
||||
}
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
// If we get here, then maybe the method name is capitalized.
|
||||
char* methodName = strdup(aMethodName);
|
||||
methodName[0] = toupper(methodName[0]);
|
||||
rv = aIInfo->GetMethodInfoForName(methodName, aMethodIndex, aMethodInfo);
|
||||
free(methodName);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
// If there is no method called <aMethodName>, then maybe it is an
|
||||
// 'attribute'.
|
||||
if (strlen(aMethodName) > 3) {
|
||||
if (strncmp("get", aMethodName, 3) == 0) {
|
||||
char* getterName = strdup(aMethodName + 3);
|
||||
rv = aIInfo->GetMethodInfoForName(getterName, aMethodIndex, aMethodInfo);
|
||||
free(getterName);
|
||||
} else if (strncmp("set", aMethodName, 3) == 0) {
|
||||
char* setterName = strdup(aMethodName + 3);
|
||||
rv = aIInfo->GetMethodInfoForName(setterName, aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// If this succeeded, GetMethodInfoForName will have returned the
|
||||
// method info for the 'getter'. We want the 'setter', so increase
|
||||
// method index by one ('setter' immediately follows the 'getter'),
|
||||
// and get its method info.
|
||||
(*aMethodIndex)++;
|
||||
rv = aIInfo->GetMethodInfo(*aMethodIndex, aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Double check that this methodInfo matches the given method.
|
||||
if (!(*aMethodInfo)->IsSetter() ||
|
||||
strcmp(setterName, (*aMethodInfo)->name) != 0) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(setterName);
|
||||
}
|
||||
}
|
||||
rv = QueryAttributeInfo(aIInfo, methodName, PR_FALSE, aMethodIndex,
|
||||
aMethodInfo);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
// If we get here, then maybe the method name is capitalized.
|
||||
char* name = strdup(methodName);
|
||||
name[0] = toupper(name[0]);
|
||||
rv = aIInfo->GetMethodInfoForName(name, aMethodIndex, aMethodInfo);
|
||||
free(name);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
// If there is no method called <aMethodName>, then maybe it is an
|
||||
// 'attribute'.
|
||||
rv = QueryAttributeInfo(aIInfo, methodName, PR_TRUE, aMethodIndex,
|
||||
aMethodInfo);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -95,6 +95,34 @@ JavaToXPTCStubMap* gJavaToXPTCStubMap = nsnull;
|
||||
PRBool gJavaXPCOMInitialized = PR_FALSE;
|
||||
PRLock* gJavaXPCOMLock = nsnull;
|
||||
|
||||
static const char* kJavaKeywords[] = {
|
||||
"abstract", "default" , "if" , "private" , "throw" ,
|
||||
"boolean" , "do" , "implements", "protected" , "throws" ,
|
||||
"break" , "double" , "import", "public" , "transient" ,
|
||||
"byte" , "else" , "instanceof", "return" , "try" ,
|
||||
"case" , "extends" , "int" , "short" , "void" ,
|
||||
"catch" , "final" , "interface" , "static" , "volatile" ,
|
||||
"char" , "finally" , "long" , "super" , "while" ,
|
||||
"class" , "float" , "native" , "switch" ,
|
||||
"const" , "for" , "new" , "synchronized",
|
||||
"continue", "goto" , "package" , "this" ,
|
||||
/* added in Java 1.2 */
|
||||
"strictfp",
|
||||
/* added in Java 1.4 */
|
||||
"assert" ,
|
||||
/* added in Java 5.0 */
|
||||
"enum" ,
|
||||
/* Java constants */
|
||||
"true" , "false" , "null" ,
|
||||
/* java.lang.Object methods *
|
||||
* - don't worry about "toString", since it does the same thing *
|
||||
* as Object's "toString" */
|
||||
"clone" , "equals" , "finalize" , "getClass" , "hashCode" ,
|
||||
"notify" , "notifyAll", /*"toString" ,*/ "wait"
|
||||
};
|
||||
|
||||
nsTHashtable<nsDepCharHashKey>* gJavaKeywords = nsnull;
|
||||
|
||||
|
||||
/******************************
|
||||
* InitializeJavaGlobals
|
||||
@ -245,16 +273,35 @@ InitializeJavaGlobals(JNIEnv *env)
|
||||
#endif
|
||||
|
||||
gNativeToJavaProxyMap = new NativeToJavaProxyMap();
|
||||
if (NS_FAILED(gNativeToJavaProxyMap->Init())) {
|
||||
if (!gNativeToJavaProxyMap || NS_FAILED(gNativeToJavaProxyMap->Init())) {
|
||||
NS_WARNING("Problem creating NativeToJavaProxyMap");
|
||||
goto init_error;
|
||||
}
|
||||
gJavaToXPTCStubMap = new JavaToXPTCStubMap();
|
||||
if (NS_FAILED(gJavaToXPTCStubMap->Init())) {
|
||||
if (!gJavaToXPTCStubMap || NS_FAILED(gJavaToXPTCStubMap->Init())) {
|
||||
NS_WARNING("Problem creating JavaToXPTCStubMap");
|
||||
goto init_error;
|
||||
}
|
||||
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 size = NS_ARRAY_LENGTH(kJavaKeywords);
|
||||
gJavaKeywords = new nsTHashtable<nsDepCharHashKey>();
|
||||
if (!gJavaKeywords || NS_FAILED(gJavaKeywords->Init(size))) {
|
||||
NS_WARNING("Failed to init JavaKeywords HashSet");
|
||||
goto init_error;
|
||||
}
|
||||
for (PRUint32 i = 0; i < size && NS_SUCCEEDED(rv); i++) {
|
||||
if (!gJavaKeywords->PutEntry(kJavaKeywords[i])) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to populate JavaKeywords hash");
|
||||
goto init_error;
|
||||
}
|
||||
}
|
||||
|
||||
gJavaXPCOMLock = PR_NewLock();
|
||||
gJavaXPCOMInitialized = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
@ -346,6 +393,11 @@ FreeJavaGlobals(JNIEnv* env)
|
||||
xpcomJavaProxyClass = nsnull;
|
||||
}
|
||||
|
||||
if (gJavaKeywords) {
|
||||
delete gJavaKeywords;
|
||||
gJavaKeywords = nsnull;
|
||||
}
|
||||
|
||||
if (tempLock) {
|
||||
PR_Unlock(tempLock);
|
||||
PR_DestroyLock(tempLock);
|
||||
|
Loading…
Reference in New Issue
Block a user