KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > util > SourceFileAttribute


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.util;
12
13 import org.eclipse.jdt.core.util.ClassFormatException;
14 import org.eclipse.jdt.core.util.IConstantPool;
15 import org.eclipse.jdt.core.util.IConstantPoolConstant;
16 import org.eclipse.jdt.core.util.IConstantPoolEntry;
17 import org.eclipse.jdt.core.util.ISourceAttribute;
18
19 /**
20  * Default implementation of ISourceAttribute
21  */

22 public class SourceFileAttribute
23     extends ClassFileAttribute
24     implements ISourceAttribute {
25
26     private int sourceFileIndex;
27     private char[] sourceFileName;
28     
29     /**
30      * Constructor for SourceFileAttribute.
31      * @param classFileBytes
32      * @param constantPool
33      * @param offset
34      * @throws ClassFormatException
35      */

36     public SourceFileAttribute(
37         byte[] classFileBytes,
38         IConstantPool constantPool,
39         int offset)
40         throws ClassFormatException {
41         super(classFileBytes, constantPool, offset);
42         this.sourceFileIndex = u2At(classFileBytes, 6, offset);
43         IConstantPoolEntry constantPoolEntry = constantPool.decodeEntry(this.sourceFileIndex);
44         if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
45             throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
46         }
47         this.sourceFileName = constantPoolEntry.getUtf8Value();
48     }
49     /**
50      * @see ISourceAttribute#getSourceFileIndex()
51      */

52     public int getSourceFileIndex() {
53         return this.sourceFileIndex;
54     }
55
56     /**
57      * @see ISourceAttribute#getSourceFileName()
58      */

59     public char[] getSourceFileName() {
60         return this.sourceFileName;
61     }
62
63 }
64
Popular Tags