01: /* InstanceOfOperator Copyright (C) 1998-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: InstanceOfOperator.java,v 4.12.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.TabbedPrintWriter;
24:
25: public class InstanceOfOperator extends Operator {
26:
27: Type instanceType;
28:
29: public InstanceOfOperator(Type type) {
30: super (Type.tBoolean, 0);
31: this .instanceType = type;
32: initOperands(1);
33: }
34:
35: public int getPriority() {
36: return 550;
37: }
38:
39: public void updateSubTypes() {
40: subExpressions[0].setType(Type.tUObject);
41: }
42:
43: public void updateType() {
44: }
45:
46: public void dumpExpression(TabbedPrintWriter writer)
47: throws java.io.IOException {
48: /* There are special cases where a cast isn't allowed. We
49: * must cast to the common super type before. In these cases
50: * instanceof always return false, but we want to decompile
51: * even bad programs. */
52: Type super Type = instanceType.getCastHelper(subExpressions[0]
53: .getType());
54: if (super Type != null) {
55: writer.startOp(writer.IMPL_PAREN, 2);
56: writer.print("(");
57: writer.printType(super Type);
58: writer.print(") ");
59: writer.breakOp();
60: subExpressions[0].dumpExpression(writer, 700);
61: writer.endOp();
62: } else
63: subExpressions[0].dumpExpression(writer, 550);
64: writer.breakOp();
65: writer.print(" instanceof ");
66: writer.printType(instanceType);
67: }
68: }
|