Source Code Cross Referenced for NameOccurrencesTest.java in  » Code-Analyzer » pmd-4.2rc1 » test » 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 » test.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 test.net.sourceforge.pmd.symboltable;
004:
005:        import static org.junit.Assert.assertEquals;
006:        import static org.junit.Assert.assertFalse;
007:        import static org.junit.Assert.assertTrue;
008:        import net.sourceforge.pmd.PMD;
009:        import net.sourceforge.pmd.ast.ASTPrimaryExpression;
010:        import net.sourceforge.pmd.symboltable.NameFinder;
011:        import net.sourceforge.pmd.symboltable.NameOccurrence;
012:
013:        import org.junit.Test;
014:
015:        import java.util.List;
016:
017:        public class NameOccurrencesTest extends STBBaseTst {
018:
019:            @Test
020:            public void testSuper() {
021:                parseCode(TEST1);
022:                List nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
023:                NameFinder occs = new NameFinder((ASTPrimaryExpression) nodes
024:                        .get(0));
025:                assertEquals("super", occs.getNames().get(0).getImage());
026:            }
027:
028:            @Test
029:            public void testThis() {
030:                parseCode(TEST2);
031:                List nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
032:                NameFinder occs = new NameFinder((ASTPrimaryExpression) nodes
033:                        .get(0));
034:                assertEquals("this", occs.getNames().get(0).getImage());
035:                assertEquals("x", occs.getNames().get(1).getImage());
036:            }
037:
038:            @Test
039:            public void testNameLinkage() {
040:                parseCode(TEST2);
041:                List nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
042:                NameFinder occs = new NameFinder((ASTPrimaryExpression) nodes
043:                        .get(0));
044:                NameOccurrence this NameOccurrence = occs.getNames().get(0);
045:                assertEquals(this NameOccurrence
046:                        .getNameForWhichThisIsAQualifier(), occs.getNames()
047:                        .get(1));
048:            }
049:
050:            @Test
051:            public void testSimpleVariableOccurrence() {
052:                parseCode(TEST3);
053:                List nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
054:                NameFinder occs = new NameFinder((ASTPrimaryExpression) nodes
055:                        .get(0));
056:                assertEquals("x", occs.getNames().get(0).getImage());
057:                assertFalse(occs.getNames().get(0).isThisOrSuper());
058:                assertFalse(occs.getNames().get(0)
059:                        .isMethodOrConstructorInvocation());
060:                assertTrue(occs.getNames().get(0).isOnLeftHandSide());
061:            }
062:
063:            @Test
064:            public void testQualifiedOccurrence() {
065:                parseCode(TEST4);
066:                List nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
067:                NameFinder occs = new NameFinder((ASTPrimaryExpression) nodes
068:                        .get(0));
069:                assertEquals("b", occs.getNames().get(0).getImage());
070:                assertEquals("x", occs.getNames().get(1).getImage());
071:            }
072:
073:            @Test
074:            public void testIsSelfAssignment() {
075:                parseCode(TEST5);
076:                List nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
077:                NameFinder occs = new NameFinder((ASTPrimaryExpression) nodes
078:                        .get(2));
079:                assertTrue(occs.getNames().get(0).isSelfAssignment());
080:
081:                parseCode(TEST6);
082:                nodes = acu.findChildrenOfType(ASTPrimaryExpression.class);
083:                occs = new NameFinder((ASTPrimaryExpression) nodes.get(2));
084:                assertTrue(occs.getNames().get(0).isSelfAssignment());
085:            }
086:
087:            public static final String TEST1 = "public class Foo {" + PMD.EOL
088:                    + " void foo() {" + PMD.EOL + "  super.x = 2;" + PMD.EOL
089:                    + " }" + PMD.EOL + "}";
090:
091:            public static final String TEST2 = "public class Foo {" + PMD.EOL
092:                    + " void foo() {" + PMD.EOL + "  this.x = 2;" + PMD.EOL
093:                    + " }" + PMD.EOL + "}";
094:
095:            public static final String TEST3 = "public class Foo {" + PMD.EOL
096:                    + " void foo() {" + PMD.EOL + "  x = 2;" + PMD.EOL + " }"
097:                    + PMD.EOL + "}";
098:
099:            public static final String TEST4 = "public class Foo {" + PMD.EOL
100:                    + " void foo() {" + PMD.EOL + "  b.x = 2;" + PMD.EOL + " }"
101:                    + PMD.EOL + "}";
102:
103:            public static final String TEST5 = "public class Foo{" + PMD.EOL
104:                    + "    private int counter;" + PMD.EOL
105:                    + "    private Foo(){" + PMD.EOL + "        counter = 0;"
106:                    + PMD.EOL + "    }" + PMD.EOL + "    private int foo(){"
107:                    + PMD.EOL + "        if (++counter < 3) {" + PMD.EOL
108:                    + "            return 0;" + PMD.EOL + "        }" + PMD.EOL
109:                    + "        return 1;" + PMD.EOL + "    }" + PMD.EOL + "}";
110:
111:            public static final String TEST6 = "public class Foo{" + PMD.EOL
112:                    + "    private int counter;" + PMD.EOL
113:                    + "    private Foo(){" + PMD.EOL + "        counter = 0;"
114:                    + PMD.EOL + "    }" + PMD.EOL + "    private int foo(){"
115:                    + PMD.EOL + "        if (++this.counter < 3) {" + PMD.EOL
116:                    + "            return 0;" + PMD.EOL + "        }" + PMD.EOL
117:                    + "        return 1;" + PMD.EOL + "    }" + PMD.EOL + "}";
118:
119:            public static junit.framework.Test suite() {
120:                return new junit.framework.JUnit4TestAdapter(
121:                        NameOccurrencesTest.class);
122:            }
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.