1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import org.apache.bcel.Constants; 23 24 34 public final class SourceFile extends Attribute { 35 36 private int sourcefile_index; 37 38 39 43 public SourceFile(SourceFile c) { 44 this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), c.getConstantPool()); 45 } 46 47 48 56 SourceFile(int name_index, int length, DataInputStream file, ConstantPool constant_pool) 57 throws IOException { 58 this(name_index, length, file.readUnsignedShort(), constant_pool); 59 } 60 61 62 75 public SourceFile(int name_index, int length, int sourcefile_index, ConstantPool constant_pool) { 76 super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool); 77 this.sourcefile_index = sourcefile_index; 78 } 79 80 81 88 public void accept( Visitor v ) { 89 v.visitSourceFile(this); 90 } 91 92 93 99 public final void dump( DataOutputStream file ) throws IOException { 100 super.dump(file); 101 file.writeShort(sourcefile_index); 102 } 103 104 105 108 public final int getSourceFileIndex() { 109 return sourcefile_index; 110 } 111 112 113 116 public final void setSourceFileIndex( int sourcefile_index ) { 117 this.sourcefile_index = sourcefile_index; 118 } 119 120 121 124 public final String getSourceFileName() { 125 ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(sourcefile_index, 126 Constants.CONSTANT_Utf8); 127 return c.getBytes(); 128 } 129 130 131 134 public final String toString() { 135 return "SourceFile(" + getSourceFileName() + ")"; 136 } 137 138 139 142 public Attribute copy( ConstantPool _constant_pool ) { 143 return (SourceFile) clone(); 144 } 145 } 146 | Popular Tags |