KickJava   Java API By Example, From Geeks To Geeks.

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


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

21 public class DefaultStackMapFrame extends ClassFileStruct implements IStackMapFrame {
22     private static final IVerificationTypeInfo[] EMPTY_LOCALS_OR_STACK_ITEMS = new IVerificationTypeInfo[0];
23
24     private int readOffset;
25     private int numberOfLocals;
26     private int numberOfStackItems;
27     private IVerificationTypeInfo[] locals;
28     private IVerificationTypeInfo[] stackItems;
29     private int offsetDelta;
30     
31     /**
32      * Constructor for StackMapFrame.
33      *
34      * @param classFileBytes
35      * @param constantPool
36      * @param offset
37      * @throws ClassFormatException
38      */

39     public DefaultStackMapFrame(
40             byte[] classFileBytes,
41             IConstantPool constantPool,
42             int offset) throws ClassFormatException {
43         // FULL_FRAME
44
this.offsetDelta = u2At(classFileBytes, 0, offset);
45         int tempLocals = u2At(classFileBytes, 2, offset);
46         this.numberOfLocals = tempLocals;
47         if (tempLocals != 0) {
48             this.locals = new IVerificationTypeInfo[tempLocals];
49             this.readOffset = 4;
50             for (int i = 0; i < tempLocals; i++) {
51                 VerificationInfo verificationInfo = new VerificationInfo(classFileBytes, constantPool, offset + this.readOffset);
52                 this.locals[i] = verificationInfo;
53                 this.readOffset += verificationInfo.sizeInBytes();
54             }
55         } else {
56             this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
57         }
58         int tempStackItems = u2At(classFileBytes, readOffset, offset);
59         this.readOffset += 2;
60         this.numberOfStackItems = tempStackItems;
61         if (tempStackItems != 0) {
62             this.stackItems = new IVerificationTypeInfo[tempStackItems];
63             for (int i = 0; i < tempStackItems; i++) {
64                 VerificationInfo verificationInfo = new VerificationInfo(classFileBytes, constantPool, offset + this.readOffset);
65                 this.stackItems[i] = verificationInfo;
66                 this.readOffset += verificationInfo.sizeInBytes();
67             }
68         } else {
69             this.stackItems = EMPTY_LOCALS_OR_STACK_ITEMS;
70         }
71     }
72     int sizeInBytes() {
73         return this.readOffset;
74     }
75     public int getFrameType() {
76         return 255; // full_frame
77
}
78     public IVerificationTypeInfo[] getLocals() {
79         return this.locals;
80     }
81     public int getNumberOfLocals() {
82         return this.numberOfLocals;
83     }
84     public int getNumberOfStackItems() {
85         return this.numberOfStackItems;
86     }
87     public int getOffsetDelta() {
88         return this.offsetDelta;
89     }
90     public IVerificationTypeInfo[] getStackItems() {
91         return this.stackItems;
92     }
93 }
94
Popular Tags