01: /*
02: * Bytecode analysis framework
03: * Copyright (C) 2005, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.ba.type;
21:
22: import java.util.ArrayList;
23: import java.util.Collection;
24: import java.util.Iterator;
25: import java.util.StringTokenizer;
26:
27: import org.apache.bcel.generic.ReferenceType;
28: import org.apache.bcel.generic.Type;
29:
30: import edu.umd.cs.findbugs.ba.interproc.FieldPropertyDatabase;
31: import edu.umd.cs.findbugs.ba.interproc.PropertyDatabaseFormatException;
32: import edu.umd.cs.findbugs.classfile.FieldDescriptor;
33:
34: /**
35: * @author David Hovemeyer
36: */
37: public class FieldStoreTypeDatabase extends
38: FieldPropertyDatabase<FieldStoreType> {
39:
40: public static final String DEFAULT_FILENAME = "fieldStoreTypes.db";
41:
42: public void purgeBoringEntries() {
43: Collection<FieldDescriptor> keys = new ArrayList<FieldDescriptor>(
44: getKeys());
45: for (FieldDescriptor f : keys) {
46: String s = f.getSignature();
47: FieldStoreType type = getProperty(f);
48: Type fieldType = Type.getType(f.getSignature());
49: if (!(fieldType instanceof ReferenceType)) {
50: removeProperty(f);
51: continue;
52: }
53: ReferenceType storeType = type
54: .getLoadType((ReferenceType) fieldType);
55: if (storeType.equals(fieldType))
56: removeProperty(f);
57: }
58: }
59:
60: @Override
61: protected FieldStoreType decodeProperty(String propStr)
62: throws PropertyDatabaseFormatException {
63: FieldStoreType property = new FieldStoreType();
64: StringTokenizer t = new StringTokenizer(propStr, ",");
65: while (t.hasMoreTokens()) {
66: String signature = t.nextToken();
67: property.addTypeSignature(signature);
68: }
69: return property;
70: }
71:
72: @Override
73: protected String encodeProperty(FieldStoreType property) {
74: StringBuffer buf = new StringBuffer();
75: for (Iterator<String> i = property.signatureIterator(); i
76: .hasNext();) {
77: if (buf.length() > 0) {
78: buf.append(',');
79: }
80: buf.append(i.next());
81: }
82: return buf.toString();
83: }
84:
85: }
|