KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > yworks > yguard > obf > classfile > StackMapFrameInfo


1 package com.yworks.yguard.obf.classfile;
2
3 import java.io.DataInput JavaDoc;
4 import java.io.DataOutput JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.ArrayList JavaDoc;
8
9 /**
10  * Representation of an Local Variable table entry.
11  *
12  * @author Mark Welsh
13  */

14 public class StackMapFrameInfo {
15   private VerificationTypeInfo[] verificationTypeInfoStack;
16   private int u2_offset_delta;
17   private VerificationTypeInfo[] verificationTypeInfoLocals;
18   private int u1_frameType;
19   // Constants -------------------------------------------------------------
20

21
22     // Class Methods ---------------------------------------------------------
23
public static StackMapFrameInfo create(DataInput JavaDoc din) throws java.io.IOException JavaDoc
24     {
25       if (din == null) throw new NullPointerException JavaDoc("DataInput cannot be null!");
26         StackMapFrameInfo smfi = new StackMapFrameInfo();
27         smfi.read(din);
28         return smfi;
29     }
30
31
32     // Instance Methods ------------------------------------------------------
33
private StackMapFrameInfo() {}
34
35     /** Check for Utf8 references to constant pool and mark them. */
36     protected void markUtf8Refs(ConstantPool pool)
37     {
38       if (u1_frameType < 64){
39         // SAME
40
} else if (u1_frameType >= 64 && u1_frameType <= 127){
41         // SAME_LOCALS_1_STACK_ITEM;
42
verificationTypeInfoStack[0].markUtf8Refs(pool);
43       } else if (u1_frameType == 247){
44         // SAME_LOCALS_1_STACK_ITEM_EXTENDED
45
verificationTypeInfoStack[0].markUtf8Refs(pool);
46       } else if (u1_frameType >= 248 && u1_frameType <= 250){
47         // CHOP
48
} else if (u1_frameType == 251){
49         // SAME_FRAME_EXTENDED
50
} else if (u1_frameType >= 252 && u1_frameType <= 254){
51         // APPEND
52
for (int i = 0; i < verificationTypeInfoStack.length; i++) {
53           verificationTypeInfoStack[i].markUtf8Refs(pool);
54         }
55       } else if (u1_frameType == 255){
56         // FULL_FRAME
57
for (int i = 0; i < verificationTypeInfoLocals.length; i++) {
58           verificationTypeInfoLocals[i].markUtf8Refs(pool);
59         }
60         for (int i = 0; i < verificationTypeInfoStack.length; i++) {
61           verificationTypeInfoStack[i].markUtf8Refs(pool);
62         }
63       } else {
64         throw new IllegalArgumentException JavaDoc("Unknown frame type " + u1_frameType);
65       }
66     }
67
68
69   public Collection JavaDoc getVerificationTypeInfos(){
70     ArrayList JavaDoc result = new ArrayList JavaDoc();
71     if (verificationTypeInfoLocals != null){
72       for (int i = 0; i < verificationTypeInfoLocals.length; i++) {
73         VerificationTypeInfo verificationTypeInfo = verificationTypeInfoLocals[i];
74         result.add(verificationTypeInfo);
75       }
76     }
77     if (verificationTypeInfoStack != null){
78       for (int i = 0; i < verificationTypeInfoStack.length; i++) {
79         VerificationTypeInfo verificationTypeInfo = verificationTypeInfoStack[i];
80         result.add(verificationTypeInfo);
81       }
82     }
83     return result;
84   }
85
86   private void read(DataInput JavaDoc din) throws java.io.IOException JavaDoc
87     {
88       verificationTypeInfoLocals = null;
89       verificationTypeInfoStack = null;
90       u1_frameType = din.readUnsignedByte();
91       if (u1_frameType < 64){
92         // SAME
93
} else if (u1_frameType >= 64 && u1_frameType <= 127){
94         // SAME_LOCALS_1_STACK_ITEM;
95
verificationTypeInfoStack = new VerificationTypeInfo[1];
96         verificationTypeInfoStack[0] = VerificationTypeInfo.create(din);
97       } else if (u1_frameType == 247){
98         // SAME_LOCALS_1_STACK_ITEM_EXTENDED
99
u2_offset_delta = din.readUnsignedShort();
100         verificationTypeInfoStack = new VerificationTypeInfo[1];
101         verificationTypeInfoStack[0] = VerificationTypeInfo.create(din);
102       } else if (u1_frameType >= 248 && u1_frameType <= 250){
103         // CHOP
104
u2_offset_delta = din.readUnsignedShort();
105       } else if (u1_frameType == 251){
106         // SAME_FRAME_EXTENDED
107
u2_offset_delta = din.readUnsignedShort();
108       } else if (u1_frameType >= 252 && u1_frameType <= 254){
109         // APPEND
110
u2_offset_delta = din.readUnsignedShort();
111         int count = u1_frameType - 251;
112         verificationTypeInfoStack = new VerificationTypeInfo[count];
113         for (int i = 0; i < verificationTypeInfoStack.length; i++) {
114           verificationTypeInfoStack[i] = VerificationTypeInfo.create(din);
115         }
116       } else if (u1_frameType == 255){
117         // FULL_FRAME
118
u2_offset_delta = din.readUnsignedShort();
119         verificationTypeInfoLocals = new VerificationTypeInfo[din.readUnsignedShort()];
120         for (int i = 0; i < verificationTypeInfoLocals.length; i++) {
121           verificationTypeInfoLocals[i] = VerificationTypeInfo.create(din);
122         }
123         verificationTypeInfoStack = new VerificationTypeInfo[din.readUnsignedShort()];
124         for (int i = 0; i < verificationTypeInfoStack.length; i++) {
125           verificationTypeInfoStack[i] = VerificationTypeInfo.create(din);
126         }
127       } else {
128         throw new IllegalArgumentException JavaDoc("Unknown frame type " + u1_frameType);
129       }
130     }
131
132     /** Export the representation to a DataOutput stream. */
133     public void write(DataOutput JavaDoc dout) throws java.io.IOException JavaDoc
134     {
135       dout.writeByte(u1_frameType);
136       if (u1_frameType < 64){
137         // SAME
138
} else if (u1_frameType >= 64 && u1_frameType <= 127){
139         // SAME_LOCALS_1_STACK_ITEM;
140
verificationTypeInfoStack[0].write(dout);
141       } else if (u1_frameType == 247){
142         // SAME_LOCALS_1_STACK_ITEM_EXTENDED
143
dout.writeShort(u2_offset_delta);
144         verificationTypeInfoStack[0].write(dout);
145       } else if (u1_frameType >= 248 && u1_frameType <= 250){
146         // CHOP
147
dout.writeShort(u2_offset_delta);
148       } else if (u1_frameType == 251){
149         // SAME_FRAME_EXTENDED
150
dout.writeShort(u2_offset_delta);
151       } else if (u1_frameType >= 252 && u1_frameType <= 254){
152         // APPEND
153
dout.writeShort(u2_offset_delta);
154         for (int i = 0; i < verificationTypeInfoStack.length; i++) {
155           verificationTypeInfoStack[i].write(dout);
156         }
157       } else if (u1_frameType == 255){
158         // FULL_FRAME
159
dout.writeShort(u2_offset_delta);
160         dout.writeShort(verificationTypeInfoLocals.length);
161         for (int i = 0; i < verificationTypeInfoLocals.length; i++) {
162           verificationTypeInfoLocals[i].write(dout);
163         }
164         dout.writeShort(verificationTypeInfoStack.length);
165         for (int i = 0; i < verificationTypeInfoStack.length; i++) {
166           verificationTypeInfoStack[i].write(dout);
167         }
168       } else {
169         throw new IllegalArgumentException JavaDoc("Unknown frame type " + u1_frameType);
170       }
171     }
172 }
173
Popular Tags