FileDocCategorySizeDatePackage
SourceFile.javaAPI DocJava SE 6 API6426Tue Jun 10 00:22:18 BST 2008com.sun.org.apache.bcel.internal.classfile

SourceFile

public final class SourceFile extends Attribute
This class is derived from Attribute and represents a reference to the source file of this class. At most one SourceFile attribute should appear per classfile. The intention of this class is that it is instantiated from the Attribute.readAttribute() method.
version
$Id: SourceFile.java,v 1.1.2.1 2005/07/31 23:46:26 jeffsuttor Exp $
author
M. Dahm
see
Attribute

Fields Summary
private int
sourcefile_index
Constructors Summary
public SourceFile(SourceFile c)
Initialize from another object. Note that both objects use the same references (shallow copy). Use clone() for a physical copy.

    this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(),
	 c.getConstantPool());
  
SourceFile(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
Construct object from file stream.

param
name_index Index in constant pool to CONSTANT_Utf8
param
length Content length in bytes
param
file Input stream
param
constant_pool Array of constants
throws
IOException

    this(name_index, length, file.readUnsignedShort(), constant_pool);
  
public SourceFile(int name_index, int length, int sourcefile_index, ConstantPool constant_pool)

param
name_index Index in constant pool to CONSTANT_Utf8, which should represent the string "SourceFile".
param
length Content length in bytes, the value should be 2.
param
constant_pool The constant pool that this attribute is associated with.
param
sourcefile_index Index in constant pool to CONSTANT_Utf8. This string will be interpreted as the name of the file from which this class was compiled. It will not be interpreted as indicating the name of the directory contqining the file or an absolute path; this information has to be supplied the consumer of this attribute - in many cases, the JVM.

    super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool);
    this.sourcefile_index = sourcefile_index;
  
Methods Summary
public voidaccept(com.sun.org.apache.bcel.internal.classfile.Visitor v)
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.

param
v Visitor object

    v.visitSourceFile(this);
  
public com.sun.org.apache.bcel.internal.classfile.Attributecopy(com.sun.org.apache.bcel.internal.classfile.ConstantPool constant_pool)

return
deep copy of this attribute

    return (SourceFile)clone();
  
public final voiddump(java.io.DataOutputStream file)
Dump source file attribute to file stream in binary format.

param
file Output file stream
throws
IOException

    super.dump(file);
    file.writeShort(sourcefile_index);
  
public final intgetSourceFileIndex()

return
Index in constant pool of source file name.

 return sourcefile_index; 
public final java.lang.StringgetSourceFileName()

return
Source file name.

    ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(sourcefile_index, 
							     Constants.CONSTANT_Utf8);
    return c.getBytes();
  
public final voidsetSourceFileIndex(int sourcefile_index)

param
sourcefile_index.

    this.sourcefile_index = sourcefile_index;
  
public final java.lang.StringtoString()

return
String representation

    return "SourceFile(" + getSourceFileName() + ")";