Bug 1322650 - Force static accessors for some types during JNI bindings generation r=jchen
MozReview-Commit-ID: 94iFlTHCCxb
--- a/build/annotationProcessors/CodeGenerator.java
+++ b/build/annotationProcessors/CodeGenerator.java
@@ -399,16 +399,28 @@ public class CodeGenerator {
}
}
return out.append('"').toString();
}
return String.valueOf(val);
}
+ private boolean typeNeedsAccessor(Class<?> type) {
+ final String[] accessorNames = new String[]{ "android.os.Build" };
+
+ for (String name : accessorNames) {
+ if (type.getCanonicalName().startsWith(name)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public void generateField(AnnotatableEntity annotatedField) {
final Field field = annotatedField.getField();
final AnnotationInfo info = annotatedField.mAnnotationInfo;
final String uniqueName = info.wrapperName;
final Class<?> type = field.getType();
// Handles a peculiar case when dealing with enum types. We don't care about this field.
// It just gets in the way and stops our code from compiling.
@@ -420,18 +432,19 @@ public class CodeGenerator {
if (info.dispatchTarget != AnnotationInfo.DispatchTarget.CURRENT) {
throw new IllegalStateException("Invalid dispatch target \"" +
info.dispatchTarget.name().toLowerCase() +
"\" for field " + clsName + "::" + uniqueName);
}
final boolean isStatic = Utils.isStatic(field);
final boolean isFinal = Utils.isFinal(field);
+ final boolean needsAccessor = typeNeedsAccessor(field.getDeclaringClass());
- if (isStatic && isFinal && (type.isPrimitive() || type.equals(String.class))) {
+ if (!needsAccessor && isStatic && isFinal && (type.isPrimitive() || type.equals(String.class))) {
Object val = null;
try {
field.setAccessible(true);
val = field.get(null);
} catch (final IllegalAccessException e) {
}
if (val != null && type.isPrimitive()) {