1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import java.io.*; 59 60 69 public final class SourceFile extends Attribute { 70 private int sourcefile_index; 71 72 76 public SourceFile(SourceFile c) { 77 this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), 78 c.getConstantPool()); 79 } 80 81 89 SourceFile(int name_index, int length, DataInputStream file, 90 ConstantPool constant_pool) throws IOException 91 { 92 this(name_index, length, file.readUnsignedShort(), constant_pool); 93 } 94 95 101 public SourceFile(int name_index, int length, int sourcefile_index, 102 ConstantPool constant_pool) 103 { 104 super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool); 105 this.sourcefile_index = sourcefile_index; 106 } 107 108 115 public void accept(Visitor v) { 116 v.visitSourceFile(this); 117 } 118 119 125 public final void dump(DataOutputStream file) throws IOException 126 { 127 super.dump(file); 128 file.writeShort(sourcefile_index); 129 } 130 131 134 public final int getSourceFileIndex() { return sourcefile_index; } 135 136 139 public final void setSourceFileIndex(int sourcefile_index) { 140 this.sourcefile_index = sourcefile_index; 141 } 142 143 146 public final String getSourceFileName() { 147 ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(sourcefile_index, 148 Constants.CONSTANT_Utf8); 149 return c.getBytes(); 150 } 151 152 155 public final String toString() { 156 return "SourceFile(" + getSourceFileName() + ")"; 157 } 158 159 162 public Attribute copy(ConstantPool constant_pool) { 163 return (SourceFile)clone(); 164 } 165 } 166 | Popular Tags |