001: /* FieldIdentifier Copyright (C) 1999-2002 Jochen Hoenicke.
002: *
003: * This program is free software; you can redistribute it and/or modify
004: * it under the terms of the GNU General Public License as published by
005: * the Free Software Foundation; either version 2, or (at your option)
006: * any later version.
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License
014: * along with this program; see the file COPYING. If not, write to
015: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
016: *
017: * $Id: FieldIdentifier.java.in,v 1.4.2.1 2002/05/28 17:34:14 hoenicke Exp $
018: */
019:
020: package jode.obfuscator;
021:
022: import java.lang.reflect.Modifier;
023: import jode.bytecode.*;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.Iterator;
027: import java.util.HashSet;
028: import java.util.Map;
029:
030: public class FieldIdentifier extends Identifier {
031: FieldInfo info;
032: ClassIdentifier clazz;
033: String name;
034: String type;
035: /**
036: * This field tells if the value is not constant. It is initially
037: * set to false, and if a write to that field is found, it is set
038: * to true.
039: */
040: private boolean notConstant;
041: private Object constant;
042:
043: /**
044: * The FieldChangeListener that should be notified if a
045: * write to this field is found.
046: */
047: private Collection fieldListeners;
048:
049: public FieldIdentifier(ClassIdentifier clazz, FieldInfo info) {
050: super (info.getName());
051: this .name = info.getName();
052: this .type = info.getType();
053: this .info = info;
054: this .clazz = clazz;
055: this .constant = info.getConstant();
056: }
057:
058: public void setSingleReachable() {
059: super .setSingleReachable();
060: Main.getClassBundle().analyzeIdentifier(this );
061: }
062:
063: public void setSinglePreserved() {
064: super .setSinglePreserved();
065: setNotConstant();
066: }
067:
068: public void analyze() {
069: String type = getType();
070: int index = type.indexOf('L');
071: if (index != -1) {
072: int end = type.indexOf(';', index);
073: Main.getClassBundle().reachableClass(
074: type.substring(index + 1, end).replace('/', '.'));
075: }
076: }
077:
078: public Identifier getParent() {
079: return clazz;
080: }
081:
082: public String getFullName() {
083: return clazz.getFullName() + "." + getName() + "." + getType();
084: }
085:
086: public String getFullAlias() {
087: return clazz.getFullAlias() + "." + getAlias() + "."
088: + Main.getClassBundle().getTypeAlias(getType());
089: }
090:
091: public String getName() {
092: return name;
093: }
094:
095: public String getType() {
096: return type;
097: }
098:
099: public int getModifiers() {
100: return info.getModifiers();
101: }
102:
103: public Iterator getChilds() {
104: return Collections.EMPTY_LIST.iterator();
105: }
106:
107: public boolean isNotConstant() {
108: return notConstant;
109: }
110:
111: public Object getConstant() {
112: return constant;
113: }
114:
115: public void addFieldListener(Identifier ident) {
116: if (ident == null)
117: throw new NullPointerException();
118: if (fieldListeners == null)
119: fieldListeners = new HashSet();
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 i = fieldListeners.iterator(); i.hasNext();)
133: Main.getClassBundle().analyzeIdentifier(
134: (Identifier) i.next());
135: fieldListeners = null;
136: }
137:
138: public String toString() {
139: return "FieldIdentifier " + getFullName();
140: }
141:
142: public boolean conflicting(String newAlias) {
143: return clazz.fieldConflicts(this , newAlias);
144: }
145:
146: public void doTransformations() {
147: info.setName(getAlias());
148: info.setType(Main.getClassBundle().getTypeAlias(type));
149: }
150: }
|