KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > interproc > FieldPropertyDatabase


1 /*
2  * Bytecode analysis framework
3  * Copyright (C) 2005, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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.interproc;
21
22 import java.io.IOException JavaDoc;
23 import java.io.Writer JavaDoc;
24
25 import org.apache.bcel.Constants;
26
27 import edu.umd.cs.findbugs.ba.InstanceField;
28 import edu.umd.cs.findbugs.ba.StaticField;
29 import edu.umd.cs.findbugs.ba.XField;
30
31 /**
32  * Interprocedural field property database.
33  *
34  * @author David Hovemeyer
35  */

36 public abstract class FieldPropertyDatabase<Property>
37         extends PropertyDatabase<XField, Property> {
38
39     /* (non-Javadoc)
40      * @see edu.umd.cs.findbugs.ba.interproc.PropertyDatabase#parseKey(java.lang.String)
41      */

42     //@Override
43
@Override JavaDoc
44          protected XField parseKey(String JavaDoc s) throws PropertyDatabaseFormatException {
45         String JavaDoc[] tuple = s.split(",");
46         if (tuple.length != 4) {
47             throw new PropertyDatabaseFormatException("Invalid field tuple: " + s);
48         }
49         
50         String JavaDoc className = tuple[0];
51         String JavaDoc fieldName = tuple[1];
52         String JavaDoc signature = tuple[2];
53         int accessFlags;
54         try {
55             accessFlags = Integer.parseInt(tuple[3]);
56         } catch (NumberFormatException JavaDoc e) {
57             throw new PropertyDatabaseFormatException("Invalid field access flags: " + tuple[3]);
58         }
59
60         return (accessFlags & Constants.ACC_STATIC) != 0
61             ? new StaticField(className, fieldName, signature, accessFlags)
62             : new InstanceField(className, fieldName, signature, accessFlags);
63     }
64
65     /* (non-Javadoc)
66      * @see edu.umd.cs.findbugs.ba.interproc.PropertyDatabase#writeKey(java.io.Writer, KeyType)
67      */

68     //@Override
69
@Override JavaDoc
70          protected void writeKey(Writer JavaDoc writer, XField key) throws IOException JavaDoc {
71         writer.write(key.getClassName());
72         writer.write(",");
73         writer.write(key.getName());
74         writer.write(",");
75         writer.write(key.getSignature());
76         writer.write(",");
77         writer.write(String.valueOf(key.getAccessFlags()));
78     }
79
80 }
81
Popular Tags