KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > expr > InstanceOfOperator


1 /* InstanceOfOperator Copyright (C) 1998-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: InstanceOfOperator.java,v 4.12.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.TabbedPrintWriter;
23
24 public class InstanceOfOperator extends Operator {
25
26     Type instanceType;
27
28     public InstanceOfOperator(Type type) {
29         super(Type.tBoolean, 0);
30         this.instanceType = type;
31     initOperands(1);
32     }
33
34     public int getPriority() {
35         return 550;
36     }
37
38     public void updateSubTypes() {
39     subExpressions[0].setType(Type.tUObject);
40     }
41
42     public void updateType() {
43     }
44
45     public void dumpExpression(TabbedPrintWriter writer)
46     throws java.io.IOException JavaDoc {
47     /* There are special cases where a cast isn't allowed. We
48      * must cast to the common super type before. In these cases
49      * instanceof always return false, but we want to decompile
50      * even bad programs. */

51     Type superType
52         = instanceType.getCastHelper(subExpressions[0].getType());
53     if (superType != null) {
54         writer.startOp(writer.IMPL_PAREN, 2);
55         writer.print("(");
56         writer.printType(superType);
57         writer.print(") ");
58         writer.breakOp();
59         subExpressions[0].dumpExpression(writer, 700);
60         writer.endOp();
61     } else
62         subExpressions[0].dumpExpression(writer, 550);
63     writer.breakOp();
64         writer.print(" instanceof ");
65     writer.printType(instanceType);
66     }
67 }
68
Popular Tags