View Javadoc
1 /* 2 * @(#)FieldInfo.java 1.3 95/08/16 Chuck McManis 3 * 4 * Copyright (c) 1996 Chuck McManis, All Rights Reserved. 5 * 6 * Permission to use, copy, modify, and distribute this software 7 * and its documentation for NON-COMMERCIAL purposes and without 8 * fee is hereby granted provided that this copyright notice 9 * appears in all copies. 10 * 11 * CHUCK MCMANIS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY 12 * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 13 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 14 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. CHUCK MCMANIS SHALL NOT BE 15 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, 16 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. 17 */ 18 19 package ch.elca.dependency.core.classinfo; 20 21 import java.io.DataInputStream; 22 import java.io.DataOutputStream; 23 import java.io.IOException; 24 25 /*** 26 * This class defines a FieldInfo in the class file. Fields are used to 27 * describe instance variables in a class. The toString() method is 28 * augmented by a version that takes an array of ConstantPoolInfo 29 * objects (a constant pool). When a constant pool is available the 30 * toString() method generates a declaration for the field as it would 31 * appear in Java source. 32 * 33 * @version 1.3, 16 Aug 1995 34 * @author Chuck McManis 35 * @see ch.elca.dependency.rawmodel.classinfo.Reader 36 */ 37 38 public class FieldInfo { 39 short accessFlags; 40 ConstantPoolInfo name; 41 ConstantPoolInfo signature; 42 AttributeInfo attributes[]; 43 44 public boolean read(DataInputStream di, ConstantPoolInfo pool[]) 45 throws IOException { 46 int count; 47 48 accessFlags = di.readShort(); 49 name = pool[di.readShort()]; 50 signature = pool[di.readShort()]; 51 count = di.readShort(); 52 if ( count != 0 ) { 53 attributes = new AttributeInfo[count]; 54 for ( int i = 0 ; i < count ; i++ ) { 55 attributes[i] = new AttributeInfo(); 56 if ( ! attributes[i].read(di, pool) ) 57 return (false); 58 } 59 } 60 return (true); 61 } 62 63 public void write(DataOutputStream dos, ConstantPoolInfo pool[]) 64 throws IOException, Exception { 65 66 dos.writeShort(accessFlags); 67 dos.writeShort(ConstantPoolInfo.indexOf(name, pool)); 68 dos.writeShort(ConstantPoolInfo.indexOf(signature, pool)); 69 if ( attributes == null ) { 70 dos.writeShort(0); 71 } else { 72 dos.writeShort(attributes.length); 73 for ( int i = 0 ; i < attributes.length ; i++ ) { 74 attributes[i].write(dos, pool); 75 } 76 } 77 } 78 79 public String toString() { 80 StringBuffer x = new StringBuffer(); 81 82 x.append(Reader.accessString(accessFlags)); 83 x.append(Reader.typeString(signature.toString(), name.toString())); 84 if ( attributes != null ) { 85 x.append(" = "+attributes[0].toString()); 86 } 87 return (x.toString()); 88 } 89 90 public String toString(ConstantPoolInfo pool[]) { 91 StringBuffer x = new StringBuffer(); 92 String mytype; 93 94 x.append(Reader.accessString(accessFlags)); 95 mytype = Reader.typeString(signature.toString(), name.toString()); 96 x.append(mytype); 97 if ( attributes != null ) { 98 if ( mytype.startsWith("boolean") ) { 99 x.append(" "+attributes[0].toBoolean(pool)); 100 } else 101 x.append(" "+attributes[0].toString(pool)); 102 } 103 return (x.toString()); 104 } 105 }

This page was automatically generated by Maven