KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.IStackMapFrame;
16 import org.eclipse.jdt.core.util.IStackMapTableAttribute;
17 /**
18  * Default implementation of IStackMapTableAttribute.
19  * @see IStackMapTableAttribute
20  */

21 public class StackMapTableAttribute
22     extends ClassFileAttribute
23     implements IStackMapTableAttribute {
24
25     private static final IStackMapFrame[] NO_FRAMES = new IStackMapFrame[0];
26     private static final byte[] NO_ENTRIES = new byte[0];
27
28     private int numberOfEntries;
29     private IStackMapFrame[] frames;
30     
31     private byte[] bytes;
32
33     /**
34      * Constructor for LineNumberAttribute.
35      * @param classFileBytes
36      * @param constantPool
37      * @param offset
38      * @throws ClassFormatException
39      */

40     public StackMapTableAttribute(
41             byte[] classFileBytes,
42             IConstantPool constantPool,
43             int offset)
44             throws ClassFormatException {
45         super(classFileBytes, constantPool, offset);
46         
47         final int length = u2At(classFileBytes, 6, offset);
48         this.numberOfEntries = length;
49         if (length != 0) {
50             int readOffset = 8;
51             this.frames = new IStackMapFrame[length];
52             for (int i = 0; i < length; i++) {
53                 StackMapFrame frame = new StackMapFrame(classFileBytes, constantPool, offset + readOffset);
54                 this.frames[i] = frame;
55                 readOffset += frame.sizeInBytes();
56             }
57         } else {
58             this.frames = NO_FRAMES;
59         }
60         final int byteLength = (int) u4At(classFileBytes, 2, offset);
61         
62         if (length != 0) {
63             System.arraycopy(classFileBytes, offset + 6, this.bytes = new byte[byteLength], 0, byteLength);
64         } else {
65             this.bytes = NO_ENTRIES;
66         }
67     }
68
69     public int getNumberOfEntries() {
70         return this.numberOfEntries;
71     }
72
73     public IStackMapFrame[] getStackMapFrame() {
74         return this.frames;
75     }
76     
77     /**
78      */

79     public byte[] getBytes() {
80         return this.bytes;
81     }
82 }
83
Popular Tags