KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > expr > NewArrayOperator


1 /* NewArrayOperator 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: NewArrayOperator.java,v 4.10.2.2 2002/05/28 17:34:06 hoenicke Exp $
18  */

19
20 package jode.expr;
21 import jode.type.Type;
22 import jode.type.ArrayType;
23 import jode.decompiler.TabbedPrintWriter;
24
25 public class NewArrayOperator extends Operator {
26     String JavaDoc baseTypeString;
27
28     public NewArrayOperator(Type arrayType, int dimensions) {
29         super(arrayType, 0);
30     initOperands(dimensions);
31     }
32
33     public int getDimensions() {
34     return subExpressions.length;
35     }
36
37     public int getPriority() {
38         return 900;
39     }
40
41     public void updateSubTypes() {
42         for (int i=0; i< subExpressions.length; i++)
43             subExpressions[i].setType(Type.tUInt);
44     }
45
46     public void updateType() {
47     }
48
49     public void dumpExpression(TabbedPrintWriter writer)
50     throws java.io.IOException JavaDoc {
51         Type flat = type.getCanonic();
52     int depth = 0;
53         while (flat instanceof ArrayType) {
54             flat = ((ArrayType)flat).getElementType();
55         depth++;
56         }
57     writer.print("new ");
58     writer.printType(flat.getHint());
59     for (int i=0; i< depth; i++) {
60         writer.breakOp();
61         writer.print("[");
62             if (i < subExpressions.length)
63         subExpressions[i].dumpExpression(writer, 0);
64         writer.print("]");
65     }
66     }
67 }
68
Popular Tags