KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > internal > AST > ASTSynchronizedBlockNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
3  * Copyright (C) 2005 Nomair A. Naeem
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 package soot.dava.internal.AST;
22
23 import soot.*;
24 import soot.jimple.*;
25 import java.util.*;
26 import soot.dava.internal.SET.*;
27 import soot.dava.toolkits.base.AST.*;
28 import soot.dava.toolkits.base.AST.analysis.*;
29
30 public class ASTSynchronizedBlockNode extends ASTLabeledNode
31 {
32     private List body;
33     private ValueBox localBox;
34
35     public ASTSynchronizedBlockNode( SETNodeLabel label, List body, Value local)
36     {
37     super( label);
38     this.body = body;
39     this.localBox = Jimple.v().newLocalBox( local );
40
41     subBodies.add( body);
42     }
43
44     /*
45       Nomair A Naeem 21-FEB-2005
46       Used by UselessLabeledBlockRemove to update a body
47     */

48     public void replaceBody(List body){
49     this.body=body;
50     subBodies=new ArrayList();
51     subBodies.add(body);
52     }
53
54     public int size()
55     {
56     return body.size();
57     }
58     
59     public Local getLocal() {
60         return (Local) localBox.getValue();
61     }
62
63
64     public void setLocal(Local local){
65     this.localBox = Jimple.v().newLocalBox( local );
66     }
67
68     public Object JavaDoc clone()
69     {
70     return new ASTSynchronizedBlockNode( get_Label(), body, getLocal());
71     }
72
73     public void toString( UnitPrinter up)
74     {
75     label_toString(up);
76
77     /* up.literal( "synchronized" );
78           up.literal( " " );
79           up.literal( "(" );
80     */

81     up.literal( "synchronized (");
82     localBox.toString(up);
83     up.literal( ")");
84         up.newline();
85
86         up.literal( "{" );
87         up.newline();
88  
89         up.incIndent();
90         body_toString( up, body );
91         up.decIndent();
92
93         up.literal( "}" );
94         up.newline();
95     }
96
97     public String JavaDoc toString()
98     {
99     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
100
101     b.append( label_toString( ));
102
103     b.append( "synchronized (");
104     b.append( getLocal());
105     b.append( ")");
106     b.append( NEWLINE);
107
108     b.append( "{");
109     b.append( NEWLINE);
110  
111     b.append( body_toString( body));
112
113     b.append( "}");
114     b.append( NEWLINE);
115
116     return b.toString();
117     }
118
119
120
121
122     /*
123       Nomair A. Naeem, 7-FEB-05
124       Part of Visitor Design Implementation for AST
125       See: soot.dava.toolkits.base.AST.analysis For details
126     */

127     public void apply(Analysis a){
128     a.caseASTSynchronizedBlockNode(this);
129     }
130 }
131
Popular Tags