Source Code Cross Referenced for JavaMethod.java in  » XML-UI » JAXX » jaxx » compiler » 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 » XML UI » JAXX » jaxx.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Ethan Nicholas. All rights reserved.
003:         * Use is subject to license terms.
004:         */
005:        package jaxx.compiler;
006:
007:        /** Represents a method in a Java source file being generated for output.  <code>JavaMethods</code> are created
008:         * and added to a {@link JavaFile}, which can then output Java source code.  In addition to normal methods, a 
009:         * <code>JavaMethod</code> can represent a constructor -- constructors should be named after their containing
010:         * classes and have a return type of <code>null</code>.
011:         */
012:        public class JavaMethod {
013:            private int modifiers;
014:            private String returnType;
015:            private String name;
016:            private JavaArgument[] arguments;
017:            private String[] exceptions;
018:            private StringBuffer bodyCode;
019:
020:            /** Constructs a new no-argument <code>JavaMethod</code> which throws no checked exceptions.  The 
021:             * <code>modifiers</code> parameter is a bit mask of the constants from {@link java.lang.reflect.Modifier}, 
022:             * and the <code>returnType</code> of the method should be represented as it would appear in Java source 
023:             * code (<code>null</code> for a constructor).  The method body is initially empty.
024:             *
025:             *@param modifiers the modifier keywords that should appear as part of the method's declaration
026:             *@param returnType the return type of the method as it would appear in Java source code
027:             *@param name the method's name
028:             *@see #appendBodyCode
029:             */
030:            public JavaMethod(int modifiers, String returnType, String name) {
031:                this (modifiers, returnType, name, null);
032:            }
033:
034:            /** Constructs a new <code>JavaMethod</code> which throws no checked exceptions.  The <code>modifiers</code> 
035:             * parameter is a bit mask of the constants from {@link java.lang.reflect.Modifier}, and the 
036:             * <code>returnType</code> of the method should be represented as it would appear in Java source code
037:             * (<code>null</code> for a constructor).  The method body is initially empty.
038:             *
039:             *@param modifiers the modifier keywords that should appear as part of the method's declaration
040:             *@param returnType the return type of the method as it would appear in Java source code
041:             *@param name the method's name
042:             *@param arguments the method's arguments
043:             *@see #appendBodyCode
044:             */
045:            public JavaMethod(int modifiers, String returnType, String name,
046:                    JavaArgument[] arguments) {
047:                this (modifiers, returnType, name, arguments, null);
048:            }
049:
050:            /** Constructs a new <code>JavaMethod</code>.  The <code>modifiers</code> parameter is a bit mask of the 
051:             * constants from {@link java.lang.reflect.Modifier}, and the <code>returnType</code> and <code>exceptions</code>
052:             * of the method should be represented as they would appear in Java source code (<code>null</code> for a 
053:             * constructor).  The method body is initially empty.
054:             *
055:             *@param modifiers the modifier keywords that should appear as part of the method's declaration
056:             *@param returnType the return type of the method as it would appear in Java source code
057:             *@param name the method's name
058:             *@param arguments the method's arguments
059:             *@param exceptions a list of exceptions the methods can throw, as they would be represented in Java source code
060:             *@see #appendBodyCode
061:             */
062:            public JavaMethod(int modifiers, String returnType, String name,
063:                    JavaArgument[] arguments, String[] exceptions) {
064:                this (modifiers, returnType, name, arguments, exceptions, null);
065:            }
066:
067:            /** Constructs a new <code>JavaMethod</code> containing the specified body code.  The <code>modifiers</code> parameter 
068:             * is a bit mask of the  constants from {@link java.lang.reflect.Modifier}, and the <code>returnType</code> and 
069:             * <code>exceptions</code> of the method should be represented as they would appear in Java source code (<code>null</code> 
070:             * for a constructor).  The method body is initially empty.
071:             *
072:             *@param modifiers the modifier keywords that should appear as part of the method's declaration
073:             *@param returnType the return type of the method as it would appear in Java source code
074:             *@param name the method's name
075:             *@param arguments the method's arguments
076:             *@param exceptions a list of exceptions the methods can throw, as they would be represented in Java source code
077:             *@param bodyCode Java source code which should appear in the method body
078:             */
079:            public JavaMethod(int modifiers, String returnType, String name,
080:                    JavaArgument[] arguments, String[] exceptions,
081:                    String bodyCode) {
082:                this .modifiers = modifiers;
083:                this .returnType = returnType;
084:                this .name = name;
085:                this .arguments = arguments;
086:                this .exceptions = exceptions;
087:                this .bodyCode = new StringBuffer(bodyCode != null ? bodyCode
088:                        : "");
089:            }
090:
091:            /** Returns a bit mask describing the modifier keywords which should appear as part of this method's
092:             * declaration.  See <code>java.lang.reflect.Modifier</code> for more information on decoding this
093:             * field.
094:             *
095:             *@return the modifier bit mask
096:             */
097:            public int getModifiers() {
098:                return modifiers;
099:            }
100:
101:            /** Returns the method's return type, as it would be represented in Java source code.
102:             *
103:             *@return the method's return type
104:             */
105:            public String getReturnType() {
106:                return returnType;
107:            }
108:
109:            /** Returns the method's name.
110:             *
111:             *@return the method's name
112:             */
113:            public String getName() {
114:                return name;
115:            }
116:
117:            /** Returns a list of the method's arguments.
118:             *
119:             *@return the method's arguments
120:             */
121:            public JavaArgument[] getArguments() {
122:                return arguments;
123:            }
124:
125:            /** Returns a list of exceptions the method can throw.
126:             *
127:             *@return the method's exceptions
128:             */
129:            public String[] getExceptions() {
130:                return exceptions;
131:            }
132:
133:            /** Returns the Java source code for the method's body.
134:             *
135:             *@return the method's body code
136:             */
137:            public String getBodyCode() {
138:                return bodyCode.toString();
139:            }
140:
141:            /** Appends additional code to the method's body.
142:             *
143:             *@param extraCode Java source code to append to the method's body
144:             */
145:            public void appendBodyCode(String extraCode) {
146:                if (extraCode.length() == 0)
147:                    return;
148:                if (bodyCode.length() > 0
149:                        && !bodyCode.toString().endsWith(
150:                                JAXXCompiler.getLineSeparator()))
151:                    bodyCode.append(JAXXCompiler.getLineSeparator());
152:                bodyCode.append(extraCode);
153:            }
154:
155:            /** Returns the Java source code for this method. 
156:             *
157:             *@return the Java source code for this method
158:             */
159:            public String toString() {
160:                StringBuffer result = new StringBuffer();
161:                result.append(JavaFile.getModifiersText(modifiers));
162:                if (returnType != null) {
163:                    result.append(returnType);
164:                    result.append(' ');
165:                }
166:                result.append(name);
167:                result.append('(');
168:                if (arguments != null) {
169:                    for (int i = 0; i < arguments.length; i++) {
170:                        if (i > 0)
171:                            result.append(", ");
172:                        result.append(arguments[i].toString());
173:                    }
174:                }
175:                result.append(") {");
176:                result.append(JAXXCompiler.getLineSeparator());
177:                if (bodyCode != null) {
178:                    String formattedBodyCode = JavaFile.addIndentation(bodyCode
179:                            .toString().trim(), 4);
180:                    if (formattedBodyCode.length() > 0) {
181:                        result.append(formattedBodyCode);
182:                        result.append(JAXXCompiler.getLineSeparator());
183:                    }
184:                }
185:                result.append("}");
186:                return result.toString();
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.