Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jreversepro/revengine/JCaseEntry.java


1   /*
2    * @(#)JCaseEntry.java
3    *
4    * JReversePro - Java Decompiler / Disassembler.
5    * Copyright (C) 2000 2001 Karthik Kumar.
6    * EMail: akkumar@users.sourceforge.net
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it , under the terms of the GNU General Public License as published
10   * by the Free Software Foundation; either version 2 of the License,
11   * or (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   * See the GNU General Public License for more details.
17   * You should have received a copy of the GNU General Public License
18   * along with this program.If not, write to
19   *  The Free Software Foundation, Inc.,
20   *  59 Temple Place - Suite 330,
21   *  Boston, MA 02111-1307, USA.
22   */
23  package jreversepro.revengine;
24  
25  import jreversepro.common.KeyWords;
26  
27  import java.util.List;
28  import java.util.Vector;
29  
30  
31  /**
32   * <b>JCaseEntry</b> is the abstract representation of a case entry
33   *
34   * @author      Karthik Kumar
35   **/
36  public class JCaseEntry  implements KeyWords {
37      /**
38       * List of case targets that have similar target.
39       * Ordinarily they have just one entry. But sometimes they 
40       * may have more than one entry.
41       * For eg.
42       *
43       * case 12:
44       * case 13:
45       * case 18:
46       *    <<do Something>>
47       *
48       * In this case there will be three entries in the list.
49       **/ 
50      List values;
51  
52      /**
53       * Target of this group of case entry.
54       **/
55      int target;
56  
57      /**
58       * End Pc of this case target and the beginnin of the next target.
59       **/
60      int endTarget;
61  
62      /**
63       * Empty constructor.
64       **/
65      public JCaseEntry () {
66          values =  new Vector();
67      }
68  
69      /**
70       * @param name Name of the case target.
71       * @param targetPc PC of the corresponding handler for this
72       * case target.
73       **/
74      public JCaseEntry (String name, int targetPc) {
75          target = targetPc;
76          values =  new Vector();
77          values.add(name);
78      }
79  
80      /**
81       * Adds another case target.
82       * @param name Name of the case target.
83       **/
84      public void addValue(String name) {
85          values.add(name);
86      }
87  
88      /**
89       * @return Returns the List of case targets.
90       * Members are 'String'.
91       **/
92      public List getValues() {
93         return values;
94      }
95  
96      /**
97       * @return Returns the targetPc of the beginning branch
98       **/
99      public int getTarget() {
100         return target;
101     }
102 
103     /** Setter method for TargetPc 
104      * @param targetPc TargetPc
105      **/
106     public void setTarget(int targetPc) {
107         target = targetPc;
108     }
109 
110     /**
111      * @return Returns End of the target for this case block.
112      **/
113     public int getEndTarget() {
114         return endTarget;
115     }
116 
117     /**
118      * Setter method for endTarget.
119      * @param endTarget End Target for this case group block.
120      **/
121     public void setEndTarget(int endTarget) {
122         this.endTarget = endTarget;
123     }
124 
125     /**
126      * Returns a string with the case targets and the 
127      * correpoding branch PCs listed.
128      * @return Disassembled piece of code.
129      **/
130     public String disAssemble() {
131         StringBuffer sb = new StringBuffer();
132         for (int i = 0 ; i < values.size() ; i++) {
133             sb.append (values.get(i) + ":\n\t\t\t");
134         }
135         sb.append("\n\t\t\t\t" + GOTO + " " + target);
136         return sb.toString();
137     }
138 
139     /**
140      * @return Returns a Stringified form of the class.
141      **/
142     public String toString() {
143         StringBuffer sb =  new StringBuffer();
144         sb.append(disAssemble() + " upto " + endTarget);
145         return sb.toString();
146     }
147 }