KickJava   Java API By Example, From Geeks To Geeks.

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


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 DInterfaceInvokeExpr extends GInterfaceInvokeExpr
29 {
30     public DInterfaceInvokeExpr( 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( getMethodRef().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     public String JavaDoc toString()
67     {
68     if (getBase().getType() instanceof NullType) {
69         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
70
71         b.append( "((");
72         b.append( getMethodRef().declaringClass().getJavaStyleName());
73         b.append( ") ");
74         
75         String JavaDoc baseStr = ( getBase()).toString();
76         if ((getBase() instanceof Precedence) && ( ((Precedence) getBase()).getPrecedence() < getPrecedence()))
77         baseStr = "(" + baseStr + ")";
78
79         b.append( baseStr);
80         b.append( ").");
81
82         b.append( getMethodRef().name());
83         b.append( "(");
84
85         for (int i=0; i<argBoxes.length; i++) {
86         if(i != 0)
87             b.append(", ");
88         
89         b.append( ( argBoxes[i].getValue()).toString());
90         }
91
92         b.append(")");
93
94         return b.toString();
95     }
96
97     return super.toString();
98     }
99
100     public Object JavaDoc clone()
101     {
102         ArrayList clonedArgs = new ArrayList( getArgCount());
103
104         for(int i = 0; i < getArgCount(); i++)
105             clonedArgs.add(i, Grimp.cloneIfNecessary(getArg(i)));
106         
107         return new DInterfaceInvokeExpr( getBase(), methodRef, clonedArgs);
108     }
109 }
110
Popular Tags