MCPcopy Create free account
hub / github.com/CyanogenMod/android_frameworks_base / modifyFieldIfSet

Method modifyFieldIfSet

core/java/android/os/Debug.java:1399–1441  ·  view source on GitHub ↗

Looks up the property that corresponds to the field, and sets the field's value if the types match.

(final Field field, final TypedProperties properties,
                                         final String propertyName)

Source from the content-addressed store, hash-verified

1397 * if the types match.
1398 */
1399 private static void modifyFieldIfSet(final Field field, final TypedProperties properties,
1400 final String propertyName) {
1401 if (field.getType() == java.lang.String.class) {
1402 int stringInfo = properties.getStringInfo(propertyName);
1403 switch (stringInfo) {
1404 case TypedProperties.STRING_SET:
1405 // Handle as usual below.
1406 break;
1407 case TypedProperties.STRING_NULL:
1408 try {
1409 field.set(null, null); // null object for static fields; null string
1410 } catch (IllegalAccessException ex) {
1411 throw new IllegalArgumentException(
1412 "Cannot set field for " + propertyName, ex);
1413 }
1414 return;
1415 case TypedProperties.STRING_NOT_SET:
1416 return;
1417 case TypedProperties.STRING_TYPE_MISMATCH:
1418 throw new IllegalArgumentException(
1419 "Type of " + propertyName + " " +
1420 " does not match field type (" + field.getType() + ")");
1421 default:
1422 throw new IllegalStateException(
1423 "Unexpected getStringInfo(" + propertyName + ") return value " +
1424 stringInfo);
1425 }
1426 }
1427 Object value = properties.get(propertyName);
1428 if (value != null) {
1429 if (!fieldTypeMatches(field, value.getClass())) {
1430 throw new IllegalArgumentException(
1431 "Type of " + propertyName + " (" + value.getClass() + ") " +
1432 " does not match field type (" + field.getType() + ")");
1433 }
1434 try {
1435 field.set(null, value); // null object for static fields
1436 } catch (IllegalAccessException ex) {
1437 throw new IllegalArgumentException(
1438 "Cannot set field for " + propertyName, ex);
1439 }
1440 }
1441 }
1442
1443
1444 /**

Callers 1

setFieldsOnMethod · 0.95

Calls 5

fieldTypeMatchesMethod · 0.95
getStringInfoMethod · 0.80
getTypeMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected