Source Code Cross Referenced for TestDataflowAnalysis.java in  » Code-Analyzer » findbugs » edu » umd » cs » findbugs » detect » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » findbugs » edu.umd.cs.findbugs.detect 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FindBugs - Find Bugs in Java programs
003:         * Copyright (C) 2003-2007 University of Maryland
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:
020:        package edu.umd.cs.findbugs.detect;
021:
022:        import java.util.Iterator;
023:
024:        import edu.umd.cs.findbugs.BugReporter;
025:        import edu.umd.cs.findbugs.Detector2;
026:        import edu.umd.cs.findbugs.DetectorFactoryCollection;
027:        import edu.umd.cs.findbugs.NonReportingDetector;
028:        import edu.umd.cs.findbugs.Plugin;
029:        import edu.umd.cs.findbugs.PluginLoader;
030:        import edu.umd.cs.findbugs.SystemProperties;
031:        import edu.umd.cs.findbugs.ba.Dataflow;
032:        import edu.umd.cs.findbugs.ba.DataflowCFGPrinter;
033:        import edu.umd.cs.findbugs.ba.SignatureConverter;
034:        import edu.umd.cs.findbugs.ba.XMethod;
035:        import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
036:        import edu.umd.cs.findbugs.classfile.ClassDescriptor;
037:        import edu.umd.cs.findbugs.classfile.Global;
038:        import edu.umd.cs.findbugs.classfile.IAnalysisCache;
039:        import edu.umd.cs.findbugs.classfile.MethodDescriptor;
040:        import edu.umd.cs.findbugs.classfile.analysis.ClassInfo;
041:
042:        /**
043:         * This detector is just a test harness to test a dataflow
044:         * analysis class specified by the dataflow.classname property.
045:         * 
046:         * @author David Hovemeyer
047:         */
048:        public class TestDataflowAnalysis implements  Detector2,
049:                NonReportingDetector {
050:
051:            private String dataflowClassName;
052:            private String methodName;
053:            private Class<? extends Dataflow> dataflowClass;
054:            private boolean initialized;
055:
056:            public TestDataflowAnalysis(BugReporter bugReporter) {
057:                dataflowClassName = SystemProperties
058:                        .getProperty("dataflow.classname");
059:                methodName = SystemProperties.getProperty("dataflow.method");
060:            }
061:
062:            /* (non-Javadoc)
063:             * @see edu.umd.cs.findbugs.Detector2#finishPass()
064:             */
065:            public void finishPass() {
066:            }
067:
068:            /* (non-Javadoc)
069:             * @see edu.umd.cs.findbugs.Detector2#getDetectorClassName()
070:             */
071:            public String getDetectorClassName() {
072:                return getClass().getName();
073:            }
074:
075:            /* (non-Javadoc)
076:             * @see edu.umd.cs.findbugs.Detector2#visitClass(edu.umd.cs.findbugs.classfile.ClassDescriptor)
077:             */
078:            public void visitClass(ClassDescriptor classDescriptor)
079:                    throws CheckedAnalysisException {
080:                if (dataflowClassName == null) {
081:                    return;
082:                }
083:
084:                if (!initialized) {
085:                    initialize();
086:                }
087:
088:                if (dataflowClass == null) {
089:                    return;
090:                }
091:
092:                IAnalysisCache analysisCache = Global.getAnalysisCache();
093:
094:                ClassInfo classInfo = analysisCache.getClassAnalysis(
095:                        ClassInfo.class, classDescriptor);
096:
097:                // Test dataflow analysis on each method]
098:                for (XMethod xMethod : classInfo.getXMethods()) {
099:                    if (methodName != null
100:                            && !methodName.equals(xMethod.getName())) {
101:                        continue;
102:                    }
103:                    MethodDescriptor methodDescriptor = xMethod
104:                            .getMethodDescriptor();
105:
106:                    System.out
107:                            .println("-----------------------------------------------------------------");
108:                    System.out.println("Method: "
109:                            + SignatureConverter
110:                                    .convertMethodSignature(methodDescriptor));
111:                    System.out
112:                            .println("-----------------------------------------------------------------");
113:
114:                    // Create and execute the dataflow analysis
115:                    Dataflow dataflow = analysisCache.getMethodAnalysis(
116:                            dataflowClass, methodDescriptor);
117:
118:                    System.out.println("Dataflow finished after "
119:                            + dataflow.getNumIterations());
120:
121:                    if (SystemProperties.getBoolean("dataflow.printcfg")) {
122:                        DataflowCFGPrinter cfgPrinter = new DataflowCFGPrinter(
123:                                dataflow);
124:                        cfgPrinter.print(System.out);
125:                    }
126:
127:                }
128:            }
129:
130:            private void initialize() throws CheckedAnalysisException {
131:                initialized = true;
132:
133:                IAnalysisCache analysisCache = Global.getAnalysisCache();
134:
135:                Class<?> cls = null;
136:
137:                // First, try loading the dataflow class from the general findBugs code.
138:                try {
139:                    cls = getClass().getClassLoader().loadClass(
140:                            dataflowClassName);
141:                } catch (ClassNotFoundException e) {
142:                    // Ignore
143:                }
144:
145:                if (cls == null) {
146:                    // Find the dataflow class from the plugin in which it was loaded
147:
148:                    DetectorFactoryCollection detectorFactoryCollection = analysisCache
149:                            .getDatabase(DetectorFactoryCollection.class);
150:                    for (Iterator<Plugin> i = detectorFactoryCollection
151:                            .pluginIterator(); i.hasNext();) {
152:                        Plugin plugin = i.next();
153:                        PluginLoader pluginLoader = plugin.getPluginLoader();
154:
155:                        try {
156:                            cls = pluginLoader.getClassLoader().loadClass(
157:                                    dataflowClassName);
158:                            break;
159:                        } catch (ClassNotFoundException e) {
160:                            // Ignore
161:                        }
162:
163:                    }
164:                }
165:
166:                if (cls == null) {
167:                    analysisCache.getErrorLogger().logError(
168:                            "TestDataflowAnalysis: could not load class "
169:                                    + dataflowClassName);
170:                    return;
171:                }
172:
173:                if (!Dataflow.class.isAssignableFrom(cls)) {
174:                    analysisCache.getErrorLogger().logError(
175:                            "TestDataflowAnalysis: " + dataflowClassName
176:                                    + " is not a Dataflow class");
177:                    return;
178:                }
179:
180:                dataflowClass = (Class<? extends Dataflow>) cls;
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.