01: /* CheckNullOperator Copyright (C) 1999-2002 Jochen Hoenicke.
02: *
03: * This program is free software; you can redistribute it and/or modify
04: * it under the terms of the GNU Lesser General Public License as published by
05: * the Free Software Foundation; either version 2, or (at your option)
06: * any later version.
07: *
08: * This program is distributed in the hope that it will be useful,
09: * 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:
22: import jode.type.Type;
23: import jode.decompiler.LocalInfo;
24: import jode.decompiler.TabbedPrintWriter;
25:
26: import java.util.Collection;
27:
28: /**
29: * This is a pseudo operator, which represents the check against null
30: * that jikes and javac generates for inner classes:
31: *
32: * <pre>
33: * outer.new Inner()
34: * </pre>
35: * is translated by javac to
36: * <pre>
37: * new Outer$Inner(outer ((void) DUP.getClass()));
38: * </pre>
39: * and by jikes to
40: * <pre>
41: * new Outer$Inner(outer (DUP == null ? throw null));
42: * </pre>
43: */
44:
45: public class CheckNullOperator extends Operator {
46: LocalInfo local;
47:
48: public CheckNullOperator(Type type, LocalInfo li) {
49: super (type, 0);
50: local = li;
51: initOperands(1);
52: }
53:
54: public int getPriority() {
55: return 200;
56: }
57:
58: public void updateSubTypes() {
59: local.setType(type);
60: subExpressions[0].setType(Type.tSubType(type));
61: }
62:
63: public void updateType() {
64: Type newType = Type.tSuperType(subExpressions[0].getType())
65: .intersection(type);
66: local.setType(newType);
67: updateParentType(newType);
68: }
69:
70: public void removeLocal() {
71: local.remove();
72: }
73:
74: public void fillInGenSet(Collection in, Collection gen) {
75: if (gen != null)
76: gen.add(local);
77: super .fillInGenSet(in, gen);
78: }
79:
80: public void fillDeclarables(Collection used) {
81: used.add(local);
82: super .fillDeclarables(used);
83: }
84:
85: public void dumpExpression(TabbedPrintWriter writer)
86: throws java.io.IOException {
87: writer.print("(" + local.getName() + " = ");
88: subExpressions[0].dumpExpression(writer, 0);
89: writer.print(").getClass() != null ? " + local.getName()
90: + " : null");
91: }
92:
93: public boolean opEquals(Operator o) {
94: return o instanceof CheckNullOperator;
95: }
96: }
|