Source Code Cross Referenced for Parameter.java in  » IDE » tIDE » javaparser » 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 » IDE » tIDE » javaparser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package javaparser;
002:
003:        import java.util.*;
004:        import javaparser.javacc_gen.*;
005:
006:        /** The parameter of a method or constructor of a for loop
007:         *   or a field in a class.
008:         */
009:        public class Parameter {
010:            public final String type; // ex: "double" or double[]  or "Vector<String>"
011:            public final String name; // ex: "a"
012:
013:            // declaration position (start)
014:            public int line, col;
015:
016:            //  public Token validFrom = null;   //=> just look in the method or class or constructor
017:            //  public Token validTo = null;
018:
019:            public boolean isParameterAfterLine(int _line) {
020:                if (line > _line)
021:                    return true;
022:                return false;
023:            }
024:
025:            public Parameter(String type, String name) {
026:                this .type = type;
027:                this .name = name;
028:            }
029:
030:            /** Occurs in methods and constructors
031:                parsed during simplified syntax tree construction
032:             */
033:            public static Parameter parseFromFormalParamNode(
034:                    RAWParserTreeNode formalParameterNode) {
035:                String type = CCTreeUtils.getImageOfAllSubElements(CCTreeUtils
036:                        .getFirstSubchildNamed_ONLYInDirectChilds(
037:                                formalParameterNode, "Type"));
038:                RAWParserTreeNode vidNode = CCTreeUtils
039:                        .getFirstSubchildNamed_ONLYInDirectChilds(
040:                                formalParameterNode, "VariableDeclaratorId");
041:                Token t = CCTreeUtils.getFirstSubchild(vidNode);
042:
043:                String name = CCTreeUtils.getImageOfAllSubElements(vidNode);
044:                // [April2007]: varargs
045:                if (CCTreeUtils.getFirstSubchildNamed_ONLYInDirectChilds(
046:                        formalParameterNode, "...") != null) {
047:                    type += "[]"; // really an array for the usage...
048:                }
049:
050:                Parameter p = new Parameter(type, name);
051:
052:                p.line = t.beginLine;
053:                p.col = t.beginColumn;
054:
055:                return p;
056:            }
057:
058:            public static Parameter parseFromLocalVariableDeclaration(
059:                    RAWParserTreeNode localVariableDeclarationNode) {
060:                String type = CCTreeUtils.getImageOfAllSubElements(CCTreeUtils
061:                        .getFirstSubchildNamed_ONLYInDirectChilds(
062:                                localVariableDeclarationNode, "Type"));
063:                RAWParserTreeNode vidNode = CCTreeUtils
064:                        .getFirstSubchildNamed_ONLYInDirectChilds(
065:                                localVariableDeclarationNode,
066:                                "VariableDeclarator"); // was Id
067:                vidNode = CCTreeUtils.getFirstSubchildNamed_ONLYInDirectChilds(
068:                        vidNode, "VariableDeclaratorId");
069:
070:                Token t = CCTreeUtils.getFirstSubchild(vidNode);
071:
072:                String name = CCTreeUtils.getImageOfAllSubElements(vidNode);
073:                Parameter p = new Parameter(type, name);
074:
075:                p.line = t.beginLine;
076:                p.col = t.beginColumn;
077:
078:                return p;
079:
080:            }
081:
082:            /** occurs in field declarations
083:             */
084:            public static Parameter parseFromFieldDeclaration(
085:                    RAWParserTreeNode fieldDeclarationNode) {
086:                String type = CCTreeUtils.getImageOfAllSubElements(CCTreeUtils
087:                        .getFirstSubchildNamed_ONLYInDirectChilds(
088:                                fieldDeclarationNode, "Type"));
089:                RAWParserTreeNode vidNode = CCTreeUtils
090:                        .getFirstSubchildNamed_ONLYInDirectChilds(
091:                                fieldDeclarationNode, "VariableDeclarator"); // was Id
092:                vidNode = CCTreeUtils.getFirstSubchildNamed_ONLYInDirectChilds(
093:                        vidNode, "VariableDeclaratorId");
094:
095:                Token t = CCTreeUtils.getFirstSubchild(vidNode);
096:
097:                String name = CCTreeUtils.getImageOfAllSubElements(vidNode);
098:                Parameter p = new Parameter(type, name);
099:
100:                p.line = t.beginLine;
101:                p.col = t.beginColumn;
102:
103:                return p;
104:
105:            }
106:
107:            public static Parameter parseFromMethodDeclaration(
108:                    RAWParserTreeNode methodDeclarationNode) {
109:                RAWParserTreeNode rtNode = CCTreeUtils
110:                        .getFirstSubchildNamed_ONLYInDirectChilds(
111:                                methodDeclarationNode, "ResultType");
112:                if (rtNode == null) {
113:                    System.out
114:                            .println("ERROR: No ResultType node for method declaration");
115:                    return null;
116:                }
117:                String type = CCTreeUtils.getImageOfAllSubElements(rtNode);
118:
119:                RAWParserTreeNode mdNode = CCTreeUtils
120:                        .getFirstSubchildNamed_ONLYInDirectChilds(
121:                                methodDeclarationNode, "MethodDeclarator");
122:                if (mdNode == null) {
123:                    System.out
124:                            .println("ERROR: No MethodDeclarator for method declaration");
125:                    return null;
126:                }
127:
128:                String name = "" + mdNode.getChildNodeAt(0);
129:                Parameter p = new Parameter(type, name);
130:                return p;
131:            }
132:
133:            /** occurs in field declarations
134:             * type 1:   for(String s : args)  {}
135:             * type 2:   for(int i=0; i<12; i++) {}
136:             * variant:  for(; i<12; i++) {}    no ForInit
137:             */
138:            public static Parameter parseFromForStatementDeclaration(
139:                    RAWParserTreeNode forDeclarationNode) {
140:                RAWParserTreeNode finitNode = CCTreeUtils
141:                        .getFirstSubchildNamed_ONLYInDirectChilds(
142:                                forDeclarationNode, "ForInit");
143:                if (finitNode != null) {
144:                    // type 2:
145:                    RAWParserTreeNode lvdNode = CCTreeUtils
146:                            .getFirstSubchildNamed_ONLYInDirectChilds(
147:                                    finitNode, "LocalVariableDeclaration");
148:                    if (lvdNode == null) {
149:                        System.out.println("No param2 in for decl found: "
150:                                + forDeclarationNode);
151:                        return null;
152:                    }
153:                    return parseFromLocalVariableDeclaration(lvdNode);
154:                }
155:
156:                // type 1:
157:                RAWParserTreeNode typeNode = CCTreeUtils
158:                        .getFirstSubchildNamed_ONLYInDirectChilds(
159:                                forDeclarationNode, "Type");
160:                if (typeNode == null) {
161:                    System.out.println("No param1 in for decl found: "
162:                            + forDeclarationNode);
163:                    return null;
164:                }
165:                String type = CCTreeUtils.getImageOfAllSubElements(typeNode);
166:
167:                RAWParserTreeNode nameNode = typeNode.getNextSibling();
168:
169:                String name = CCTreeUtils.getImageOfAllSubElements(nameNode);
170:                Parameter p = new Parameter(type, name);
171:
172:                //    p.line = typeNode.beginLine;
173:                //    p.col = typeNode.beginColumn;
174:
175:                return p;
176:
177:            }
178:
179:            /** Collects the paramters.
180:             */
181:            public static List<Parameter> getParameters(
182:                    RAWParserTreeNode formalParametersNode) {
183:                List<Parameter> params = new ArrayList<Parameter>();
184:                for (int i = 0; i < formalParametersNode.getChildCount(); i++) {
185:                    RAWParserTreeNode ci = formalParametersNode
186:                            .getChildNodeAt(i);
187:                    if (ci.toString().equals("FormalParameter")) {
188:                        params.add(Parameter.parseFromFormalParamNode(ci));
189:                    }
190:                }
191:                return params;
192:            }
193:
194:            /** appears in the symplified syntax tree !
195:             */
196:            @Override
197:            public String toString() {
198:                return type + " " + name;
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.