KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > internal > javaRep > DSpecialInvokeExpr


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
3  * Copyright (C) 2004 Ondrej Lhotak
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.javaRep;
22
23 import soot.*;
24 import java.util.*;
25 import soot.grimp.*;
26 import soot.grimp.internal.*;
27
28 public class DSpecialInvokeExpr extends GSpecialInvokeExpr
29 {
30     public DSpecialInvokeExpr( Value base, SootMethodRef methodRef, java.util.List JavaDoc args)
31     {
32     super( base, methodRef, args);
33     }
34
35     public void toString( UnitPrinter up ) {
36     if (getBase().getType() instanceof NullType) {
37         // OL: I don't know what this is for; I'm just refactoring the
38
// original code. An explanation here would be welcome.
39
up.literal( "((" );
40             up.type( methodRef.declaringClass().getType() );
41             up.literal( ") " );
42         
43             if( PrecedenceTest.needsBrackets( baseBox, this ) ) up.literal("(");
44             baseBox.toString( up );
45             if( PrecedenceTest.needsBrackets( baseBox, this ) ) up.literal(")");
46
47         up.literal( ")" );
48             up.literal( "." );
49
50             up.methodRef( methodRef );
51             up.literal( "(" );
52
53         for (int i=0; i<argBoxes.length; i++) {
54         if(i != 0)
55                     up.literal( ", " );
56         
57                 argBoxes[i].toString(up);
58         }
59
60             up.literal( ")" );
61     } else {
62             super.toString( up );
63         }
64     }
65
66
67     public String JavaDoc toString()
68     {
69     if (getBase().getType() instanceof NullType) {
70         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
71
72         b.append( "((");
73         b.append( methodRef.declaringClass().getJavaStyleName());
74         b.append( ") ");
75         
76         String JavaDoc baseStr = ( getBase()).toString();
77         if ((getBase() instanceof Precedence) && ( ((Precedence) getBase()).getPrecedence() < getPrecedence()))
78         baseStr = "(" + baseStr + ")";
79
80         b.append( baseStr);
81         b.append( ").");
82
83         b.append( methodRef.name());
84         b.append( "(");
85
86         for (int i=0; i<argBoxes.length; i++) {
87         if(i != 0)
88             b.append(", ");
89         
90         b.append( ( argBoxes[i].getValue()).toString());
91         }
92
93         b.append(")");
94
95         return b.toString();
96     }
97
98     return super.toString();
99     }
100
101     public Object JavaDoc clone()
102     {
103         ArrayList clonedArgs = new ArrayList( getArgCount());
104
105         for(int i = 0; i < getArgCount(); i++)
106             clonedArgs.add(i, Grimp.cloneIfNecessary(getArg(i)));
107         
108         return new DSpecialInvokeExpr( getBase(), methodRef, clonedArgs);
109     }
110 }
111
Popular Tags