* Copyright (C) 2010 Robert Futrell
* robert_futrell at users.sourceforge.net
* http://fifesoft.com/rsyntaxtextarea
* This library is distributed under a modified BSD license. See the included
* RSTALanguageSupport.License.txt file for details.
package org.fife.rsta.ac.java.classreader.attributes;
import org.fife.rsta.ac.java.classreader.ClassFile;
import org.fife.rsta.ac.java.classreader.constantpool.ConstantUtf8Info;
* The <code>SourceFile</code> attribute, an optional fixed-length attribute
* in the attributes table of a {@link ClassFile}. There can be no more than
* one <code>SourceFile</code> attribute for a given <code>ClassFile</code>.
public class SourceFile extends AttributeInfo {
* Index into the constant pool of a {@link ConstantUtf8Info} structure
* representing the name of the source file from which this class file
private int sourceFileIndex;
* @param cf The class file.
* @param sourceFileIndex Index into the constant pool of a
* {@link ConstantUtf8Info} structure representing the source file
public SourceFile(ClassFile cf, int sourceFileIndex) {
this.sourceFileIndex = sourceFileIndex;
* Returns the name of the source file that was compiled to create this
* @return The name of the source file.
public String getSourceFileName() {
return getClassFile().getUtf8ValueFromConstantPool(sourceFileIndex);
* Returns a string representation of this attribute. Useful for
* @return A string representation of this attribute.
public String toString() {
"file=" + getSourceFileName() +