MCPcopy Create free account
hub / github.com/java-native-access/jna / deriveLayout

Method deriveLayout

src/com/sun/jna/Structure.java:1335–1474  ·  view source on GitHub ↗

Calculates the size, alignment, and field layout of this structure. Also initializes any null-valued Structure or NativeMapped members.

(boolean force, boolean avoidFFIType)

Source from the content-addressed store, hash-verified

1333 members.
1334 */
1335 private LayoutInfo deriveLayout(boolean force, boolean avoidFFIType) {
1336 int calculatedSize = 0;
1337 List<Field> fields = getFields(force);
1338 if (fields == null) {
1339 return null;
1340 }
1341
1342 LayoutInfo info = new LayoutInfo();
1343 info.alignType = this.alignType;
1344 info.typeMapper = this.typeMapper;
1345
1346 boolean firstField = true;
1347 for (Iterator<Field> i=fields.iterator();i.hasNext();firstField=false) {
1348 Field field = i.next();
1349 int modifiers = field.getModifiers();
1350
1351 Class<?> type = field.getType();
1352 if (type.isArray()) {
1353 info.variable = true;
1354 }
1355 StructField structField = new StructField();
1356 structField.isVolatile = Modifier.isVolatile(modifiers);
1357 structField.isReadOnly = Modifier.isFinal(modifiers);
1358 if (structField.isReadOnly) {
1359 if (!Platform.RO_FIELDS) {
1360 throw new IllegalArgumentException("This VM does not support read-only fields (field '"
1361 + field.getName() + "' within " + getClass() + ")");
1362 }
1363 // In J2SE VMs, this allows overriding the value of final
1364 // fields
1365 field.setAccessible(true);
1366 }
1367 structField.field = field;
1368 structField.name = field.getName();
1369 structField.type = type;
1370
1371 // Check for illegal field types
1372 if (Callback.class.isAssignableFrom(type) && !type.isInterface()) {
1373 throw new IllegalArgumentException("Structure Callback field '"
1374 + field.getName()
1375 + "' must be an interface");
1376 }
1377 if (type.isArray()
1378 && Structure.class.equals(type.getComponentType())) {
1379 String msg = "Nested Structure arrays must use a "
1380 + "derived Structure type so that the size of "
1381 + "the elements can be determined";
1382 throw new IllegalArgumentException(msg);
1383 }
1384
1385 int fieldAlignment = 1;
1386 if (!Modifier.isPublic(field.getModifiers())) {
1387 continue;
1388 }
1389
1390 Object value = getFieldValue(structField.field);
1391 if (value == null && type.isArray()) {
1392 if (force) {

Callers 1

calculateSizeMethod · 0.95

Calls 15

getFieldsMethod · 0.95
getFieldValueMethod · 0.95
getInstanceMethod · 0.95
nativeTypeMethod · 0.95
toNativeMethod · 0.95
initializeFieldMethod · 0.95
getNativeSizeMethod · 0.95
getNativeAlignmentMethod · 0.95
addPaddingMethod · 0.95
getTypeInfoMethod · 0.95
getModifiersMethod · 0.80
isArrayMethod · 0.80

Tested by

no test coverage detected