mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1210585 - Use equals to compare Class instances; r=snorp
The code generator uses == and != to compare two instances of Class, but it really should be using equals because two distinct instances of Class can refer to the same class type.
This commit is contained in:
parent
654a730e13
commit
f133e47c1a
@ -77,7 +77,7 @@ public class CodeGenerator {
|
||||
String clsName = this.clsName;
|
||||
|
||||
while (cls != null) {
|
||||
if (type == cls) {
|
||||
if (type.equals(cls)) {
|
||||
return clsName;
|
||||
}
|
||||
cls = cls.getDeclaringClass();
|
||||
@ -181,7 +181,7 @@ public class CodeGenerator {
|
||||
proto.append(", ");
|
||||
}
|
||||
|
||||
if (info.catchException && returnType != void.class) {
|
||||
if (info.catchException && !returnType.equals(void.class)) {
|
||||
proto.append(getNativeReturnType(returnType, info)).append('*');
|
||||
if (includeArgName) {
|
||||
proto.append(" a").append(argIndex++);
|
||||
@ -239,7 +239,7 @@ public class CodeGenerator {
|
||||
// We initialize rv to NS_OK instead of NS_ERROR_* because loading NS_OK (0) uses
|
||||
// fewer instructions. We are guaranteed to set rv to the correct value later.
|
||||
|
||||
if (info.catchException && returnType == void.class) {
|
||||
if (info.catchException && returnType.equals(void.class)) {
|
||||
def.append(
|
||||
" nsresult rv = NS_OK;\n" +
|
||||
" ");
|
||||
@ -350,14 +350,14 @@ public class CodeGenerator {
|
||||
private String getLiteral(Object val, AnnotationInfo info) {
|
||||
final Class<?> type = val.getClass();
|
||||
|
||||
if (type == char.class || type == Character.class) {
|
||||
if (type.equals(char.class) || type.equals(Character.class)) {
|
||||
final char c = (char) val;
|
||||
if (c >= 0x20 && c < 0x7F) {
|
||||
return "'" + c + '\'';
|
||||
}
|
||||
return "u'\\u" + Integer.toHexString(0x10000 | (int) c).substring(1) + '\'';
|
||||
|
||||
} else if (type == CharSequence.class || type == String.class) {
|
||||
} else if (type.equals(CharSequence.class) || type.equals(String.class)) {
|
||||
final CharSequence str = (CharSequence) val;
|
||||
final StringBuilder out = new StringBuilder(info.narrowChars ? "u8\"" : "u\"");
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
@ -389,7 +389,7 @@ public class CodeGenerator {
|
||||
final boolean isStatic = Utils.isStatic(field);
|
||||
final boolean isFinal = Utils.isFinal(field);
|
||||
|
||||
if (isStatic && isFinal && (type.isPrimitive() || type == String.class)) {
|
||||
if (isStatic && isFinal && (type.isPrimitive() || type.equals(String.class))) {
|
||||
Object val = null;
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
@ -406,7 +406,7 @@ public class CodeGenerator {
|
||||
"\n");
|
||||
return;
|
||||
|
||||
} else if (val != null && type == String.class) {
|
||||
} else if (val != null && type.equals(String.class)) {
|
||||
final String nativeType = info.narrowChars ? "char" : "char16_t";
|
||||
|
||||
header.append(
|
||||
|
@ -81,17 +81,17 @@ public class Utils {
|
||||
return "mozilla::jni::ObjectArray::Param";
|
||||
}
|
||||
|
||||
if (type == String.class || type == CharSequence.class) {
|
||||
if (type.equals(String.class) || type.equals(CharSequence.class)) {
|
||||
return "mozilla::jni::String::Param";
|
||||
}
|
||||
|
||||
if (type == Class.class) {
|
||||
if (type.equals(Class.class)) {
|
||||
// You're doing reflection on Java objects from inside C, returning Class objects
|
||||
// to C, generating the corresponding code using this Java program. Really?!
|
||||
return "mozilla::jni::ClassObject::Param";
|
||||
}
|
||||
|
||||
if (type == Throwable.class) {
|
||||
if (type.equals(Throwable.class)) {
|
||||
return "mozilla::jni::Throwable::Param";
|
||||
}
|
||||
|
||||
@ -113,17 +113,17 @@ public class Utils {
|
||||
return "mozilla::jni::ObjectArray::LocalRef";
|
||||
}
|
||||
|
||||
if (type == String.class) {
|
||||
if (type.equals(String.class)) {
|
||||
return "mozilla::jni::String::LocalRef";
|
||||
}
|
||||
|
||||
if (type == Class.class) {
|
||||
if (type.equals(Class.class)) {
|
||||
// You're doing reflection on Java objects from inside C, returning Class objects
|
||||
// to C, generating the corresponding code using this Java program. Really?!
|
||||
return "mozilla::jni::ClassObject::LocalRef";
|
||||
}
|
||||
|
||||
if (type == Throwable.class) {
|
||||
if (type.equals(Throwable.class)) {
|
||||
return "mozilla::jni::Throwable::LocalRef";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user