KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > expr > CheckNullOperator


1 /* CheckNullOperator Copyright (C) 1999-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; see the file COPYING.LESSER. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: CheckNullOperator.java.in,v 4.1.2.1 2002/05/28 17:34:06 hoenicke Exp $
18  */

19
20 package jode.expr;
21 import jode.type.Type;
22 import jode.decompiler.LocalInfo;
23 import jode.decompiler.TabbedPrintWriter;
24
25 import java.util.Collection JavaDoc;
26
27 /**
28  * This is a pseudo operator, which represents the check against null
29  * that jikes and javac generates for inner classes:
30  *
31  * <pre>
32  * outer.new Inner()
33  * </pre>
34  * is translated by javac to
35  * <pre>
36  * new Outer$Inner(outer ((void) DUP.getClass()));
37  * </pre>
38  * and by jikes to
39  * <pre>
40  * new Outer$Inner(outer (DUP == null ? throw null));
41  * </pre>
42  */

43
44 public class CheckNullOperator extends Operator {
45     LocalInfo local;
46
47     public CheckNullOperator(Type type, LocalInfo li) {
48         super(type, 0);
49     local = li;
50     initOperands(1);
51     }
52
53     public int getPriority() {
54         return 200;
55     }
56
57     public void updateSubTypes() {
58     local.setType(type);
59     subExpressions[0].setType(Type.tSubType(type));
60     }
61
62     public void updateType() {
63     Type newType = Type.tSuperType(subExpressions[0].getType())
64         .intersection(type);
65     local.setType(newType);
66     updateParentType(newType);
67     }
68
69     public void removeLocal() {
70     local.remove();
71     }
72
73     public void fillInGenSet(Collection JavaDoc in, Collection JavaDoc gen) {
74     if (gen != null)
75         gen.add(local);
76     super.fillInGenSet(in, gen);
77     }
78
79     public void fillDeclarables(Collection JavaDoc used) {
80     used.add(local);
81     super.fillDeclarables(used);
82     }
83
84     public void dumpExpression(TabbedPrintWriter writer)
85     throws java.io.IOException JavaDoc {
86     writer.print("("+local.getName()+" = ");
87     subExpressions[0].dumpExpression(writer, 0);
88     writer.print(").getClass() != null ? "+local.getName()+" : null");
89     }
90
91     public boolean opEquals(Operator o) {
92     return o instanceof CheckNullOperator;
93     }
94 }
95
Popular Tags