KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > expr > GetFieldOperator


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

19
20 package jode.expr;
21 import jode.type.Type;
22 import jode.type.NullType;
23 import jode.type.ClassInterfacesType;
24 import jode.bytecode.FieldInfo;
25 import jode.bytecode.ClassInfo;
26 import jode.bytecode.Reference;
27 import jode.decompiler.MethodAnalyzer;
28 import jode.decompiler.ClassAnalyzer;
29 import jode.decompiler.MethodAnalyzer;
30 import jode.decompiler.FieldAnalyzer;
31 import jode.decompiler.TabbedPrintWriter;
32 import jode.decompiler.Scope;
33
34 public class GetFieldOperator extends FieldOperator {
35     public GetFieldOperator(MethodAnalyzer methodAnalyzer, boolean staticFlag,
36                 Reference ref) {
37         super(methodAnalyzer, staticFlag, ref);
38     }
39
40     public Expression simplify() {
41     if (!staticFlag) {
42         subExpressions[0] = subExpressions[0].simplify();
43         subExpressions[0].parent = this;
44         if (subExpressions[0] instanceof ThisOperator) {
45         FieldAnalyzer field = getField();
46         /* This should check for isFinal(), but sadly,
47          * sometimes jikes doesn't make a val$ field final. I
48          * don't know when, or why, so I currently ignore
49          * isFinal.
50          */

51         if (field != null && field.isSynthetic()) {
52             Expression constant = field.getConstant();
53             if (constant instanceof ThisOperator
54             || constant instanceof OuterLocalOperator)
55             return constant;
56         }
57         }
58     }
59     return this;
60     }
61
62     public boolean opEquals(Operator o) {
63     return o instanceof GetFieldOperator
64         && ((GetFieldOperator)o).ref.equals(ref);
65     }
66 }
67
Popular Tags