KickJava   Java API By Example, From Geeks To Geeks.

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


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 package edu.umd.cs.findbugs.ba.interproc;
20
21 import java.io.IOException JavaDoc;
22 import java.io.Writer JavaDoc;
23
24 import org.apache.bcel.Constants;
25
26 import edu.umd.cs.findbugs.ba.InstanceMethod;
27 import edu.umd.cs.findbugs.ba.StaticMethod;
28 import edu.umd.cs.findbugs.ba.XMethod;
29
30 /**
31  * A MethodPropertyDatabase keeps track of properties of
32  * methods. This is useful for implementing interprocedural analyses.
33  *
34  * @author David Hovemeyer
35  */

36 public abstract class MethodPropertyDatabase<Property>
37         extends PropertyDatabase<XMethod, Property> {
38
39     @Override JavaDoc
40          protected XMethod parseKey(String JavaDoc methodStr) throws PropertyDatabaseFormatException {
41         String JavaDoc[] tuple = methodStr.split(",");
42         if (tuple.length != 4)
43             throw new PropertyDatabaseFormatException("Invalid method tuple: " + methodStr);
44         
45         try {
46             int accessFlags = Integer.parseInt(tuple[3]);
47             boolean isStatic = (accessFlags & Constants.ACC_STATIC) != 0;
48             
49             return isStatic
50                 ? new StaticMethod(tuple[0], tuple[1], tuple[2], accessFlags)
51                 : new InstanceMethod(tuple[0], tuple[1], tuple[2], accessFlags);
52         } catch (NumberFormatException JavaDoc e) {
53             return null;
54         }
55     }
56
57     @Override JavaDoc
58          protected void writeKey(Writer JavaDoc writer, XMethod method) throws IOException JavaDoc {
59         writer.write(method.getClassName());
60         writer.write(",");
61         writer.write(method.getName());
62         writer.write(",");
63         writer.write(method.getSignature());
64         writer.write(",");
65         writer.write(String.valueOf(method.getAccessFlags()));
66     }
67 }
68
Popular Tags