Source Code Cross Referenced for SwitchDensityRule.java in  » Code-Analyzer » pmd-4.2rc1 » net » sourceforge » pmd » rules » design » 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 » pmd 4.2rc1 » net.sourceforge.pmd.rules.design 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /**
02:         * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03:         */package net.sourceforge.pmd.rules.design;
04:
05:        import net.sourceforge.pmd.ast.ASTStatement;
06:        import net.sourceforge.pmd.ast.ASTSwitchLabel;
07:        import net.sourceforge.pmd.ast.ASTSwitchStatement;
08:        import net.sourceforge.pmd.stat.DataPoint;
09:        import net.sourceforge.pmd.stat.StatisticalRule;
10:
11:        /**
12:         * @author David Dixon-Peugh
13:         *
14:         *         <p/>
15:         *         Switch Density - This is the number of statements over the
16:         *         number of cases within a switch.  The higher the value, the
17:         *         more work each case is doing.
18:         *         <p/>
19:         *         Its my theory, that when the Switch Density is high, you should
20:         *         start looking at Subclasses or State Pattern to alleviate the
21:         *         problem.
22:         */
23:        public class SwitchDensityRule extends StatisticalRule {
24:
25:            private static class SwitchDensity {
26:                private int labels = 0;
27:                private int stmts = 0;
28:
29:                public void addSwitchLabel() {
30:                    labels++;
31:                }
32:
33:                public void addStatement() {
34:                    stmts++;
35:                }
36:
37:                public void addStatements(int stmtCount) {
38:                    stmts += stmtCount;
39:                }
40:
41:                public int getStatementCount() {
42:                    return stmts;
43:                }
44:
45:                public double getDensity() {
46:                    if (labels == 0) {
47:                        return 0;
48:                    }
49:                    return (double) stmts / (double) labels;
50:                }
51:            }
52:
53:            public Object visit(ASTSwitchStatement node, Object data) {
54:                SwitchDensity oldData = null;
55:
56:                if (data instanceof  SwitchDensity) {
57:                    oldData = (SwitchDensity) data;
58:                }
59:
60:                SwitchDensity density = new SwitchDensity();
61:
62:                node.childrenAccept(this , density);
63:
64:                DataPoint point = new DataPoint();
65:                point.setNode(node);
66:                point.setScore(density.getDensity());
67:                point.setMessage(getMessage());
68:
69:                addDataPoint(point);
70:
71:                if (data instanceof  SwitchDensity) {
72:                    ((SwitchDensity) data).addStatements(density
73:                            .getStatementCount());
74:                }
75:                return oldData;
76:            }
77:
78:            public Object visit(ASTStatement statement, Object data) {
79:                if (data instanceof  SwitchDensity) {
80:                    ((SwitchDensity) data).addStatement();
81:                }
82:
83:                statement.childrenAccept(this , data);
84:
85:                return data;
86:            }
87:
88:            public Object visit(ASTSwitchLabel switchLabel, Object data) {
89:                if (data instanceof  SwitchDensity) {
90:                    ((SwitchDensity) data).addSwitchLabel();
91:                }
92:
93:                switchLabel.childrenAccept(this, data);
94:                return data;
95:            }
96:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.