1 /******************************************************************************* 2 * Copyright (c) 2015, 2016 Google, Inc and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Stefan Xenos (Google) - Initial implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.core.nd.field; 15 16 import org.eclipse.jdt.internal.core.nd.db.Database; 17 18 /** 19 * Represents a single field of a struct in the {@link Database}. Holds metadata for that field 20 * and permits laziy initialization of the field offset. Fields are normally instantiated as static 21 * variables. Collectively, they describe the database schema but they are not associated with any 22 * particular instance of data in the database. 23 * <p> 24 * Fields are temporarily mutable. On construction, a number of attributes (such as offset) are 25 * computed in a second pass or are initialized as other fields are constructed. Generally such 26 * attributes can't be computed in the constructor since they depend on knowledge of other fields 27 * that must be instantiated first. However, once {@link StructDef#done()} has been called on the 28 * last {@link StructDef}, fields are immutable and should not ever be modified again. 29 */ 30 public interface IField { 31 /** 32 * Sets the field offset (bytes from the start of the struct). This is invoked some time after field construction, 33 * after the sizes of all preceeding fields are known. 34 */ setOffset(int offset)35 void setOffset(int offset); 36 37 /** 38 * Returns the size of the field, in bytes. 39 */ getRecordSize()40 int getRecordSize(); 41 42 /** 43 * Returns the required byte alignment for the field. 44 */ getAlignment()45 default int getAlignment() { 46 return 1; 47 } 48 49 /** 50 * Returns the name of the field. This is mainly used for error messages, debug output, and diagnostic tools. 51 * Meant to be programmer-readable but not user-readable. 52 */ getFieldName()53 String getFieldName(); 54 55 /** 56 * Returns the field offset, in bytes from the start of the struct. 57 */ getOffset()58 int getOffset(); 59 } 60