Source Code Cross Referenced for ExceptionHandlerMap.java in  » Code-Analyzer » findbugs » edu » umd » cs » findbugs » ba » 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.ba 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Bytecode Analysis Framework
003:         * Copyright (C) 2003,2004 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.ba;
021:
022:        import java.util.IdentityHashMap;
023:        import java.util.LinkedList;
024:        import java.util.List;
025:
026:        import org.apache.bcel.generic.CodeExceptionGen;
027:        import org.apache.bcel.generic.InstructionHandle;
028:        import org.apache.bcel.generic.MethodGen;
029:
030:        /**
031:         * This class provides a convenient way of determining the exception handlers
032:         * for instructions in a method.  Essentially, it's a
033:         * a map of InstructionHandles to lists of CodeExceptionGen objects.
034:         * This class also maps instructions which are the start of exception handlers
035:         * to the CodeExceptionGen object representing the handler.
036:         *
037:         * @author David Hovemeyer
038:         */
039:        public class ExceptionHandlerMap {
040:            private IdentityHashMap<InstructionHandle, List<CodeExceptionGen>> codeToHandlerMap;
041:            private IdentityHashMap<InstructionHandle, CodeExceptionGen> startInstructionToHandlerMap;
042:
043:            /**
044:             * Constructor.
045:             *
046:             * @param methodGen the method to build the map for
047:             */
048:            public ExceptionHandlerMap(MethodGen methodGen) {
049:                codeToHandlerMap = new IdentityHashMap<InstructionHandle, List<CodeExceptionGen>>();
050:                startInstructionToHandlerMap = new IdentityHashMap<InstructionHandle, CodeExceptionGen>();
051:                build(methodGen);
052:            }
053:
054:            /**
055:             * Get the list of exception handlers (CodeExceptionGen objects)
056:             * which are specified to handle exceptions for the instruction whose
057:             * handle is given.  Note that the handlers in the returned list
058:             * are <b>in order of priority</b>, as defined in the method's exception handler
059:             * table.
060:             *
061:             * @param handle the handle of the instruction we want the exception handlers for
062:             * @return the list of exception handlers, or null if there are no handlers
063:             *         registered for the instruction
064:             */
065:            public List<CodeExceptionGen> getHandlerList(
066:                    InstructionHandle handle) {
067:                return codeToHandlerMap.get(handle);
068:            }
069:
070:            /**
071:             * If the given instruction is the start of an exception  handler,
072:             * get the CodeExceptionGen object representing the handler.
073:             *
074:             * @param start the instruction
075:             * @return the CodeExceptionGen object, or null if the instruction is not the
076:             *         start of an exception handler
077:             */
078:            public CodeExceptionGen getHandlerForStartInstruction(
079:                    InstructionHandle start) {
080:                return startInstructionToHandlerMap.get(start);
081:            }
082:
083:            private void build(MethodGen methodGen) {
084:                CodeExceptionGen[] handlerList = methodGen
085:                        .getExceptionHandlers();
086:
087:                // Map handler start instructions to the actual exception handlers
088:                for (CodeExceptionGen exceptionHandler : handlerList) {
089:                    startInstructionToHandlerMap.put(exceptionHandler
090:                            .getHandlerPC(), exceptionHandler);
091:                }
092:
093:                // For each instruction, determine which handlers it can reach
094:                InstructionHandle handle = methodGen.getInstructionList()
095:                        .getStart();
096:                while (handle != null) {
097:                    int offset = handle.getPosition();
098:
099:                    handlerLoop: for (CodeExceptionGen exceptionHandler : handlerList) {
100:                        int startOfRange = exceptionHandler.getStartPC()
101:                                .getPosition();
102:                        int endOfRange = exceptionHandler.getEndPC()
103:                                .getPosition();
104:
105:                        if (offset >= startOfRange && offset <= endOfRange) {
106:                            // This handler is reachable from the instruction
107:                            addHandler(handle, exceptionHandler);
108:
109:                            // If this handler handles all exception types
110:                            // i.e., an ANY handler, or catch(Throwable...),
111:                            // then no further (lower-priority)
112:                            // handlers are reachable from the instruction.
113:                            if (Hierarchy
114:                                    .isUniversalExceptionHandler(exceptionHandler
115:                                            .getCatchType()))
116:                                break handlerLoop;
117:                        }
118:                    }
119:
120:                    handle = handle.getNext();
121:                }
122:            }
123:
124:            private void addHandler(InstructionHandle handle,
125:                    CodeExceptionGen exceptionHandler) {
126:                List<CodeExceptionGen> handlerList = codeToHandlerMap
127:                        .get(handle);
128:                if (handlerList == null) {
129:                    handlerList = new LinkedList<CodeExceptionGen>();
130:                    codeToHandlerMap.put(handle, handlerList);
131:                }
132:                handlerList.add(exceptionHandler);
133:            }
134:        }
135:
136:        // vim:ts=4
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.