KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > obfuscator > FieldIdentifier


1 /* FieldIdentifier Copyright (C) 1999-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 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 General Public License
14  * along with this program; see the file COPYING. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: FieldIdentifier.java.in,v 1.4.2.1 2002/05/28 17:34:14 hoenicke Exp $
18  */

19
20 package jode.obfuscator;
21 import java.lang.reflect.Modifier JavaDoc;
22 import jode.bytecode.*;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Map JavaDoc;
28
29
30 public class FieldIdentifier extends Identifier{
31     FieldInfo info;
32     ClassIdentifier clazz;
33     String JavaDoc name;
34     String JavaDoc type;
35     /**
36      * This field tells if the value is not constant. It is initially
37      * set to false, and if a write to that field is found, it is set
38      * to true.
39      */

40     private boolean notConstant;
41     private Object JavaDoc constant;
42
43     /**
44      * The FieldChangeListener that should be notified if a
45      * write to this field is found.
46      */

47     private Collection JavaDoc fieldListeners;
48
49     public FieldIdentifier(ClassIdentifier clazz, FieldInfo info) {
50     super(info.getName());
51     this.name = info.getName();
52     this.type = info.getType();
53     this.info = info;
54     this.clazz = clazz;
55     this.constant = info.getConstant();
56     }
57
58     public void setSingleReachable() {
59     super.setSingleReachable();
60     Main.getClassBundle().analyzeIdentifier(this);
61     }
62     
63     public void setSinglePreserved() {
64     super.setSinglePreserved();
65     setNotConstant();
66     }
67     
68     public void analyze() {
69     String JavaDoc type = getType();
70     int index = type.indexOf('L');
71     if (index != -1) {
72         int end = type.indexOf(';', index);
73         Main.getClassBundle().reachableClass
74         (type.substring(index+1, end).replace('/', '.'));
75     }
76     }
77
78     public Identifier getParent() {
79     return clazz;
80     }
81
82     public String JavaDoc getFullName() {
83     return clazz.getFullName() + "." + getName() + "." + getType();
84     }
85
86     public String JavaDoc getFullAlias() {
87     return clazz.getFullAlias() + "." + getAlias() + "."
88         + Main.getClassBundle().getTypeAlias(getType());
89     }
90
91     public String JavaDoc getName() {
92     return name;
93     }
94
95     public String JavaDoc getType() {
96     return type;
97     }
98     
99     public int getModifiers() {
100     return info.getModifiers();
101     }
102
103     public Iterator JavaDoc getChilds() {
104     return Collections.EMPTY_LIST.iterator();
105     }
106
107     public boolean isNotConstant() {
108     return notConstant;
109     }
110     
111     public Object JavaDoc getConstant() {
112     return constant;
113     }
114     
115     public void addFieldListener(Identifier ident) {
116     if (ident == null)
117         throw new NullPointerException JavaDoc();
118     if (fieldListeners == null)
119         fieldListeners = new HashSet JavaDoc();
120     if (!fieldListeners.contains(ident))
121         fieldListeners.add(ident);
122     }
123
124     public void setNotConstant() {
125     if (notConstant)
126         return;
127
128     notConstant = true;
129     if (fieldListeners == null)
130         return;
131
132     for (Iterator JavaDoc i = fieldListeners.iterator(); i.hasNext(); )
133         Main.getClassBundle().analyzeIdentifier((Identifier) i.next());
134     fieldListeners = null;
135     }
136
137     public String JavaDoc toString() {
138     return "FieldIdentifier "+getFullName();
139     }
140
141     public boolean conflicting(String JavaDoc newAlias) {
142     return clazz.fieldConflicts(this, newAlias);
143     }
144
145     public void doTransformations() {
146     info.setName(getAlias());
147     info.setType(Main.getClassBundle().getTypeAlias(type));
148     }
149 }
150
Popular Tags