package com.de22.javabytecode.attribute; import com.de22.javabytecode.*; /** * Copyright Wynne Crisman 1999,2006
* A reference to the source file name associated with the class file. */ public class SourceFile extends CodeAttribute { private short sourceFileIndex = 0; public static final String DEFAULT_NAME = "SourceFile"; /** * SourceFile constructor. * @param type The class this constant is a member of. */ public SourceFile(Type type) { super(type); }//SourceFile()// /** * Gets the index in the constant pool of the source file's name. * @return The index to the source file name constant (UTF8) in the constant pool. */ public short getSourceFileIndex() { return sourceFileIndex; }//getSourceFileIndex()// /** * Sets the index in the constant pool of the source file's name. * @param sourceFileIndex The index to the source file name constant (UTF8) in the constant pool. */ public void setSourceFileIndex(short sourceFileIndex) { this.sourceFileIndex = sourceFileIndex; }//setSourceFileIndex()// /** * Gets the attribute's default name as it is stored in the class bytes. * @return The default name identifying the attribute's type. */ public String getDefaultName() { return DEFAULT_NAME; }//getDefaultName()// /** * Gets the size in number of bytes of the component and all subcomponents. * @return The number of bytes required to represent the component and all subcomponents. */ public int getSize() { return 2; }//getSize()// /** * Reads this object from the given stream. * @param in The input stream to read this object from. */ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException { super.readExternal(in); in.readInt(); //Read the size of the attribute.// sourceFileIndex = in.readShort(); }//readExternal()// /** * @see Component.toString(StringBuffer, int) */ public void toString(StringBuffer buffer, int tabCount) { appendTabs(buffer, tabCount); buffer.append("Source File Reference CodeAttribute (sourceFileIndex="); buffer.append(sourceFileIndex); buffer.append(" fileName='"); buffer.append(getType().getConstant(sourceFileIndex)); buffer.append("')"); appendEndOfLine(buffer); }//toString()// /** * Writes this object to the given stream. * @param out The output stream to write this object to. */ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { super.writeExternal(out); out.writeShort(sourceFileIndex); }//writeExternal()// }//SourceFile//