/Users/lyon/j4p/src/net/rmi/rmiSynth/lex/LexBody.java

1    /** 
2     * Class LexBody - body(code) of a method 
3     * @author Roman Yedokov 
4     * { object.method } 
5     */ 
6     
7    package net.rmi.rmiSynth.lex; 
8     
9     
10   public class LexBody extends LexStructure { 
11       private String delegObj;        //Delegate object 
12       private boolean ret;            //If returns 
13       private String code; 
14       private boolean tryCatch; 
15    
16       /** 
17        * Constructor 
18        */ 
19       public LexBody() { 
20           delegObj = ""; 
21           code = ""; 
22           tryCatch = false; 
23       } 
24    
25       /** 
26        * Gets cutils.delegate object 
27        * 
28        * @return delegObg 
29        */ 
30       public String getDelegObj() { 
31           return delegObj; 
32       } 
33    
34       /** 
35        * Sets cutils.delegate object 
36        * 
37        * @param _delegObg Delegate object 
38        */ 
39       public void setDelegObj(String _delegObj) { 
40           this.delegObj = _delegObj; 
41       } 
42    
43       /** 
44        * If object is not empty returns it with dot 
45        * Otherwise returns empty string 
46        * 
47        * @ return s 
48        */ 
49       public String doToString() { 
50           String s = ""; 
51           if (!delegObj.equals("")) { 
52               s = delegObj + "."; 
53           } 
54           return s; 
55       } 
56    
57    
58       /** 
59        * Gets code 
60        * 
61        * @return code 
62        */ 
63       public String getCode() { 
64           return code; 
65       } 
66    
67       /** 
68        * Sets code 
69        * 
70        * @param _code Code 
71        */ 
72       public void setCode(String _code) { 
73           this.code = _code; 
74       } 
75    
76       /** 
77        * Sets try-catch block 
78        * 
79        * @param _tryCatch Try-catch block 
80        */ 
81       public void setTryCatch(boolean _tryCatch) { 
82           tryCatch = _tryCatch; 
83       } 
84    
85       /** 
86        * If try-catch block has bben set 
87        * 
88        * @return tryCatch 
89        */ 
90       public boolean isTryCatch() { 
91           return tryCatch; 
92       } 
93    
94       /** 
95        * Set return 
96        * 
97        * @param _ret Return 
98        */ 
99       public void setRet(boolean _ret) { 
100          ret = _ret; 
101      } 
102   
103      /** 
104       * If method returns something 
105       * 
106       * @return ret 
107       */ 
108      public boolean isRet() { 
109          return ret; 
110      } 
111   
112      /** 
113       * Return to string 
114       * 
115       * @return return or "" 
116       */ 
117      public String retToString() { 
118          return ret ? 
119                 "return " : 
120                 ""; 
121      } 
122   
123      /** 
124       * LexBody to string 
125       * 
126       * @return s 
127       */ 
128      public String toString() { 
129          String s = ""; 
130          s = s + (isTryCatch() ? 
131                   "try {\n" : 
132                   ""); 
133          s = s + retToString(); 
134          s = s + doToString(); 
135          s = s + getName(); 
136          s = 
137          s + 
138          (isTryCatch() ? 
139           "\t\t} catch  (Exception e) {e.printStackTrace();}\n" : 
140           ""); 
141          return s; 
142      } 
143   
144      /** 
145       * Code to string 
146       * 
147       * @return s 
148       */ 
149      public String codeToString() { 
150          String s = ""; 
151          s = s + (isTryCatch() ? 
152                   "try {\n" : 
153                   ""); 
154          s = s + code; 
155          s = 
156          s + 
157          (isTryCatch() ? 
158           "\t\t} catch  (Exception e) {e.printStackTrace();}\n" : 
159           ""); 
160          return s; 
161      } 
162  } 
163