/*
* String[] Interned type locators
*/
out.writeInt(length = this.references.elementSize);
SimpleLookupTable internedTypeLocators = new SimpleLookupTable(length);
if (length > 0) {
keyTable = this.references.keyTable;
for (int i = 0, l = keyTable.length; i < l; i++) {
if (keyTable[i] != null) {
length--;
String key = (String) keyTable[i];
out.writeUTF(key);
internedTypeLocators.put(key, new Integer(internedTypeLocators.elementSize));
}
}
if (JavaBuilder.DEBUG && length != 0)
System.out.println("references table is inconsistent"); //$NON-NLS-1$
}
/*
* Type locators table
* String type name
* int interned locator id
*/
out.writeInt(length = this.typeLocators.elementSize);
if (length > 0) {
keyTable = this.typeLocators.keyTable;
valueTable = this.typeLocators.valueTable;
for (int i = 0, l = keyTable.length; i < l; i++) {
if (keyTable[i] != null) {
length--;
out.writeUTF((String) keyTable[i]);
Integer index = (Integer) internedTypeLocators.get(valueTable[i]);
out.writeInt(index.intValue());
}
}
if (JavaBuilder.DEBUG && length != 0)
System.out.println("typeLocators table is inconsistent"); //$NON-NLS-1$
}
/*
* char[][] Interned root names
* char[][][] Interned qualified names
* char[][] Interned simple names
*/
SimpleLookupTable internedRootNames = new SimpleLookupTable(3);
SimpleLookupTable internedQualifiedNames = new SimpleLookupTable(31);
SimpleLookupTable internedSimpleNames = new SimpleLookupTable(31);
valueTable = this.references.valueTable;
for (int i = 0, l = valueTable.length; i < l; i++) {
if (valueTable[i] != null) {
ReferenceCollection collection = (ReferenceCollection) valueTable[i];
char[][] rNames = collection.rootReferences;
for (int j = 0, m = rNames.length; j < m; j++) {
char[] rName = rNames[j];
if (!internedRootNames.containsKey(rName)) // remember the names have been interned
internedRootNames.put(rName, new Integer(internedRootNames.elementSize));
}
char[][][] qNames = collection.qualifiedNameReferences;
for (int j = 0, m = qNames.length; j < m; j++) {
char[][] qName = qNames[j];
if (!internedQualifiedNames.containsKey(qName)) { // remember the names have been interned
internedQualifiedNames.put(qName, new Integer(internedQualifiedNames.elementSize));
for (int k = 0, n = qName.length; k < n; k++) {
char[] sName = qName[k];
if (!internedSimpleNames.containsKey(sName)) // remember the names have been interned
internedSimpleNames.put(sName, new Integer(internedSimpleNames.elementSize));
}
}
}
char[][] sNames = collection.simpleNameReferences;
for (int j = 0, m = sNames.length; j < m; j++) {
char[] sName = sNames[j];
if (!internedSimpleNames.containsKey(sName)) // remember the names have been interned
internedSimpleNames.put(sName, new Integer(internedSimpleNames.elementSize));
}
}
}
char[][] internedArray = new char[internedRootNames.elementSize][];
Object[] rootNames = internedRootNames.keyTable;
Object[] positions = internedRootNames.valueTable;
for (int i = positions.length; --i >= 0; ) {
if (positions[i] != null) {
int index = ((Integer) positions[i]).intValue();
internedArray[index] = (char[]) rootNames[i];
}
}
writeNames(internedArray, out);
// now write the interned simple names
internedArray = new char[internedSimpleNames.elementSize][];
Object[] simpleNames = internedSimpleNames.keyTable;
positions = internedSimpleNames.valueTable;
for (int i = positions.length; --i >= 0; ) {
if (positions[i] != null) {
int index = ((Integer) positions[i]).intValue();
internedArray[index] = (char[]) simpleNames[i];
}
}
writeNames(internedArray, out);
// now write the interned qualified names as arrays of interned simple names
char[][][] internedQArray = new char[internedQualifiedNames.elementSize][][];
Object[] qualifiedNames = internedQualifiedNames.keyTable;
positions = internedQualifiedNames.valueTable;
for (int i = positions.length; --i >= 0; ) {
if (positions[i] != null) {
int index = ((Integer) positions[i]).intValue();
internedQArray[index] = (char[][]) qualifiedNames[i];
}
}
out.writeInt(length = internedQArray.length);
for (int i = 0; i < length; i++) {
char[][] qName = internedQArray[i];
int qLength = qName.length;
out.writeInt(qLength);
for (int j = 0; j < qLength; j++) {
Integer index = (Integer) internedSimpleNames.get(qName[j]);
out.writeInt(index.intValue());
}
}
/*
* References table
* int interned locator id
* ReferenceCollection
*/
out.writeInt(length = this.references.elementSize);
if (length > 0) {
keyTable = this.references.keyTable;
for (int i = 0, l = keyTable.length; i < l; i++) {
if (keyTable[i] != null) {
length--;
Integer index = (Integer) internedTypeLocators.get(keyTable[i]);
out.writeInt(index.intValue());
ReferenceCollection collection = (ReferenceCollection) valueTable[i];
if (collection instanceof AdditionalTypeCollection) {
out.writeByte(1);
AdditionalTypeCollection atc = (AdditionalTypeCollection) collection;
writeNames(atc.definedTypeNames, out);
} else {
out.writeByte(2);
}
char[][][] qNames = collection.qualifiedNameReferences;
int qLength = qNames.length;
out.writeInt(qLength);
for (int j = 0; j < qLength; j++) {
index = (Integer) internedQualifiedNames.get(qNames[j]);
out.writeInt(index.intValue());
}
char[][] sNames = collection.simpleNameReferences;
int sLength = sNames.length;
out.writeInt(sLength);
for (int j = 0; j < sLength; j++) {
index = (Integer) internedSimpleNames.get(sNames[j]);
out.writeInt(index.intValue());
}
char[][] rNames = collection.rootReferences;
int rLength = rNames.length;
out.writeInt(rLength);