Top Description Fields Constructors Methods
org.apache.bcel.classfile

public final Class SourceFile

extends Attribute
Class Inheritance
Imports
java.io.DataInput, .DataOutputStream, .IOException, org.apache.bcel.Const, org.apache.bcel.util.Args

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.
See Also
Attribute

Field Summary

Modifier and TypeField and Description
private int
Inherited from org.apache.bcel.classfile.Attribute:
constant_poolEMPTY_ARRAYlengthname_indextag

Constructor Summary

AccessConstructor and Description
pack-priv
SourceFile(final int
Index in constant pool to CONSTANT_Utf8
nameIndex
,
final int
Content length in bytes
length
,
final DataInput
Input stream
input
,
final ConstantPool
Array of constants
constantPool
)

Constructs object from input stream.

public
SourceFile(final int
Index in constant pool to CONSTANT_Utf8, which should represent the string "SourceFile".
nameIndex
,
final int
Content length in bytes, the value should be 2.
length
,
final int
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.
sourceFileIndex
,
final ConstantPool
The constant pool that this attribute is associated with.
constantPool
)

public
SourceFile(final SourceFile
Source to copy.
c
)

Initialize from another object.

Method Summary

Modifier and TypeMethod and Description
public void
accept(final Visitor
Visitor object
v
)

Implements abstract org.apache.bcel.classfile.Attribute.accept.

Implements org.apache.bcel.classfile.Node.accept.

Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.
public Attribute

Returns:

deep copy of this attribute
copy
(final ConstantPool
constant pool to save.
constantPool
)

Implements abstract org.apache.bcel.classfile.Attribute.copy.

public void
dump(final DataOutputStream
Output file stream
file
)

Overrides org.apache.bcel.classfile.Attribute.dump.

Dump source file attribute to file stream in binary format.
public int

Returns:

Index in constant pool of source file name.
getSourceFileIndex
()

public String

Returns:

Source file name.
getSourceFileName
()

public void
setSourceFileIndex(final int sourceFileIndex)

public String

Returns:

String representation
toString
()

Overrides org.apache.bcel.classfile.Attribute.toString.

Returns a string representation of the object.
Inherited from org.apache.bcel.classfile.Attribute:
addAttributeReaderaddAttributeReaderclonegetConstantPoolgetLengthgetNamegetNameIndexgetTagprintlnreadAttributereadAttributeremoveAttributeReadersetConstantPoolsetLengthsetNameIndex

Field Detail

sourceFileIndexback to summary
private int sourceFileIndex

Constructor Detail

SourceFileback to summary
pack-priv SourceFile(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool) throws IOException

Constructs object from input stream.

Parameters
nameIndex:int

Index in constant pool to CONSTANT_Utf8

length:int

Content length in bytes

input:DataInput

Input stream

constantPool:ConstantPool

Array of constants

Exceptions
IOException:
if an I/O error occurs.
SourceFileback to summary
public SourceFile(final int nameIndex, final int length, final int sourceFileIndex, final ConstantPool constantPool)
Parameters
nameIndex:int

Index in constant pool to CONSTANT_Utf8, which should represent the string "SourceFile".

length:int

Content length in bytes, the value should be 2.

sourceFileIndex:int

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.

constantPool:ConstantPool

The constant pool that this attribute is associated with.

SourceFileback to summary
public SourceFile(final SourceFile c)

Initialize from another object. Note that both objects use the same references (shallow copy). Use clone() for a physical copy.

Parameters
c:SourceFile

Source to copy.

Method Detail

acceptback to summary
public void accept(final Visitor v)

Implements abstract org.apache.bcel.classfile.Attribute.accept.

Implements org.apache.bcel.classfile.Node.accept.

Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.

Parameters
v:Visitor

Visitor object

Annotations
@Override
copyback to summary
public Attribute copy(final ConstantPool constantPool)

Implements abstract org.apache.bcel.classfile.Attribute.copy.

Parameters
constantPool:ConstantPool

Doc from org.apache.bcel.classfile.Attribute.copy.

constant pool to save.

Returns:Attribute

deep copy of this attribute

Annotations
@Override
dumpback to summary
public void dump(final DataOutputStream file) throws IOException

Overrides org.apache.bcel.classfile.Attribute.dump.

Dump source file attribute to file stream in binary format.

Parameters
file:DataOutputStream

Output file stream

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getSourceFileIndexback to summary
public int getSourceFileIndex()
Returns:int

Index in constant pool of source file name.

getSourceFileNameback to summary
public String getSourceFileName()
Returns:String

Source file name.

setSourceFileIndexback to summary
public void setSourceFileIndex(final int sourceFileIndex)
toStringback to summary
public String toString()

Overrides org.apache.bcel.classfile.Attribute.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

String representation

Annotations
@Override