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


001:        /**
002:         * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003:         */package net.sourceforge.pmd.symboltable;
004:
005:        import net.sourceforge.pmd.ast.ASTFormalParameter;
006:        import net.sourceforge.pmd.ast.ASTFormalParameters;
007:        import net.sourceforge.pmd.ast.ASTMethodDeclarator;
008:        import net.sourceforge.pmd.ast.ASTPrimitiveType;
009:        import net.sourceforge.pmd.ast.SimpleNode;
010:
011:        public class MethodNameDeclaration extends AbstractNameDeclaration {
012:
013:            public MethodNameDeclaration(ASTMethodDeclarator node) {
014:                super (node);
015:            }
016:
017:            public int getParameterCount() {
018:                return ((ASTMethodDeclarator) node).getParameterCount();
019:            }
020:
021:            public ASTMethodDeclarator getMethodNameDeclaratorNode() {
022:                return (ASTMethodDeclarator) node;
023:            }
024:
025:            public String getParameterDisplaySignature() {
026:                StringBuffer sb = new StringBuffer("(");
027:                ASTFormalParameters params = (ASTFormalParameters) node
028:                        .jjtGetChild(0);
029:                // TODO - this can be optimized - add [0] then ,[n] in a loop.
030:                //        no need to trim at the end
031:                for (int i = 0; i < ((ASTMethodDeclarator) node)
032:                        .getParameterCount(); i++) {
033:                    ASTFormalParameter p = (ASTFormalParameter) params
034:                            .jjtGetChild(i);
035:                    sb.append(p.getTypeNode().getTypeImage());
036:                    sb.append(',');
037:                }
038:                if (sb.charAt(sb.length() - 1) == ',') {
039:                    sb.deleteCharAt(sb.length() - 1);
040:                }
041:                sb.append(')');
042:                return sb.toString();
043:            }
044:
045:            public boolean equals(Object o) {
046:                MethodNameDeclaration other = (MethodNameDeclaration) o;
047:
048:                // compare name
049:                if (!other.node.getImage().equals(node.getImage())) {
050:                    return false;
051:                }
052:
053:                // compare parameter count - this catches the case where there are no params, too
054:                if (((ASTMethodDeclarator) (other.node)).getParameterCount() != ((ASTMethodDeclarator) node)
055:                        .getParameterCount()) {
056:                    return false;
057:                }
058:
059:                // compare parameter types
060:                ASTFormalParameters myParams = (ASTFormalParameters) node
061:                        .jjtGetChild(0);
062:                ASTFormalParameters otherParams = (ASTFormalParameters) other.node
063:                        .jjtGetChild(0);
064:                for (int i = 0; i < ((ASTMethodDeclarator) node)
065:                        .getParameterCount(); i++) {
066:                    ASTFormalParameter myParam = (ASTFormalParameter) myParams
067:                            .jjtGetChild(i);
068:                    ASTFormalParameter otherParam = (ASTFormalParameter) otherParams
069:                            .jjtGetChild(i);
070:
071:                    SimpleNode myTypeNode = (SimpleNode) myParam.getTypeNode()
072:                            .jjtGetChild(0);
073:                    SimpleNode otherTypeNode = (SimpleNode) otherParam
074:                            .getTypeNode().jjtGetChild(0);
075:
076:                    // compare primitive vs reference type
077:                    if (myTypeNode.getClass() != otherTypeNode.getClass()) {
078:                        return false;
079:                    }
080:
081:                    // simple comparison of type images
082:                    // this can be fooled by one method using "String"
083:                    // and the other method using "java.lang.String"
084:                    // once we get real types in here that should get fixed
085:                    String myTypeImg;
086:                    String otherTypeImg;
087:                    if (myTypeNode instanceof  ASTPrimitiveType) {
088:                        myTypeImg = myTypeNode.getImage();
089:                        otherTypeImg = otherTypeNode.getImage();
090:                    } else {
091:                        myTypeImg = ((SimpleNode) (myTypeNode.jjtGetChild(0)))
092:                                .getImage();
093:                        otherTypeImg = ((SimpleNode) (otherTypeNode
094:                                .jjtGetChild(0))).getImage();
095:                    }
096:
097:                    if (!myTypeImg.equals(otherTypeImg)) {
098:                        return false;
099:                    }
100:
101:                    // if type is ASTPrimitiveType and is an array, make sure the other one is also
102:                }
103:                return true;
104:            }
105:
106:            public int hashCode() {
107:                return node.getImage().hashCode()
108:                        + ((ASTMethodDeclarator) node).getParameterCount();
109:            }
110:
111:            public String toString() {
112:                return "Method " + node.getImage() + ", line "
113:                        + node.getBeginLine() + ", params = "
114:                        + ((ASTMethodDeclarator) node).getParameterCount();
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.