Source Code Cross Referenced for ConstructorFactory.java in  » Code-Analyzer » Spoon » spoon » reflect » factory » 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 » Spoon » spoon.reflect.factory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Spoon - http://spoon.gforge.inria.fr/
003:         * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004:         *
005:         * This software is governed by the CeCILL-C License under French law and
006:         * abiding by the rules of distribution of free software. You can use, modify
007:         * and/or redistribute the software under the terms of the CeCILL-C license as
008:         * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009:         *
010:         * This program is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013:         *
014:         * The fact that you are presently reading this means that you have had
015:         * knowledge of the CeCILL-C license and that you accept its terms.
016:         */
017:
018:        package spoon.reflect.factory;
019:
020:        import java.lang.reflect.Constructor;
021:        import java.util.Arrays;
022:        import java.util.List;
023:        import java.util.Set;
024:
025:        import spoon.reflect.Factory;
026:        import spoon.reflect.code.CtBlock;
027:        import spoon.reflect.declaration.CtClass;
028:        import spoon.reflect.declaration.CtConstructor;
029:        import spoon.reflect.declaration.CtMethod;
030:        import spoon.reflect.declaration.CtParameter;
031:        import spoon.reflect.declaration.ModifierKind;
032:        import spoon.reflect.reference.CtExecutableReference;
033:        import spoon.reflect.reference.CtTypeReference;
034:
035:        /**
036:         * The {@link CtConstructor} sub-factory.
037:         */
038:        public class ConstructorFactory extends ExecutableFactory {
039:
040:            private static final long serialVersionUID = 1L;
041:
042:            /**
043:             * Creates a new constructor sub-factory.
044:             *
045:             * @param factory
046:             *            the parent factory
047:             */
048:            public ConstructorFactory(Factory factory) {
049:                super (factory);
050:            }
051:
052:            /**
053:             * Copies a constructor into a target class.
054:             *
055:             * @param target
056:             *            the target class
057:             * @param source
058:             *            the constructor to be copied
059:             * @return the new constructor
060:             */
061:            @SuppressWarnings("unchecked")
062:            public <T> CtConstructor<T> create(CtClass<T> target,
063:                    CtConstructor<?> source) {
064:                CtConstructor<T> newConstructor = factory.Core().clone(
065:                        (CtConstructor<T>) source);
066:                target.getConstructors().add(newConstructor);
067:                newConstructor.setParent(target);
068:                return newConstructor;
069:            }
070:
071:            /**
072:             * Creates a constructor into a target class by copying it from a source
073:             * method.
074:             *
075:             * @param target
076:             *            the target class
077:             * @param source
078:             *            the method to be copied
079:             * @return the new constructor
080:             */
081:            @SuppressWarnings("unchecked")
082:            public <T> CtConstructor<T> create(CtClass<T> target,
083:                    CtMethod<?> source) {
084:                CtMethod<T> method = factory.Core().clone((CtMethod<T>) source);
085:                CtConstructor<T> newConstructor = factory.Core()
086:                        .createConstructor();
087:                newConstructor.setAnnotations(method.getAnnotations());
088:                newConstructor.setBody(method.getBody());
089:                newConstructor.setDocComment(method.getDocComment());
090:                newConstructor.setFormalTypeParameters(method
091:                        .getFormalTypeParameters());
092:                newConstructor.setModifiers(method.getModifiers());
093:                newConstructor.setParameters(method.getParameters());
094:                setParent(newConstructor, method.getAnnotations(), method
095:                        .getBody(), method.getParameters(), method
096:                        .getFormalTypeParameters());
097:                target.getConstructors().add(newConstructor);
098:                newConstructor.setParent(target);
099:                return newConstructor;
100:            }
101:
102:            /**
103:             * Creates an empty constructor.
104:             *
105:             * @param modifiers
106:             *            the modifiers
107:             * @param parameters
108:             *            the parameters
109:             * @param thrownTypes
110:             *            the thrown types
111:             */
112:            public <T> CtConstructor<T> create(CtClass<T> target,
113:                    Set<ModifierKind> modifiers,
114:                    List<CtParameter<?>> parameters,
115:                    Set<CtTypeReference<? extends Throwable>> thrownTypes) {
116:                CtConstructor<T> constructor = factory.Core()
117:                        .createConstructor();
118:                constructor.setModifiers(modifiers);
119:                constructor.setParent(target);
120:                constructor.setParameters(parameters);
121:                constructor.setThrownTypes(thrownTypes);
122:                setParent(constructor, parameters);
123:                target.getConstructors().add(constructor);
124:                return constructor;
125:            }
126:
127:            /**
128:             * Creates a constructor.
129:             *
130:             * @param modifiers
131:             *            the modifiers
132:             * @param parameters
133:             *            the parameters
134:             * @param thrownTypes
135:             *            the thrown types
136:             * @param body
137:             *            the body
138:             */
139:            public <T> CtConstructor<T> create(CtClass<T> target,
140:                    Set<ModifierKind> modifiers,
141:                    List<CtParameter<?>> parameters,
142:                    Set<CtTypeReference<? extends Throwable>> thrownTypes,
143:                    CtBlock<T> body) {
144:                CtConstructor<T> constructor = create(target, modifiers,
145:                        parameters, thrownTypes);
146:                constructor.setBody(body);
147:                body.setParent(constructor);
148:                return constructor;
149:            }
150:
151:            /**
152:             * Creates a constructor reference from an existing constructor.
153:             */
154:            public <T> CtExecutableReference<T> createReference(
155:                    CtConstructor<T> c) {
156:                return factory.Executable().createReference(c);
157:            }
158:
159:            /**
160:             * Creates a constructor reference from an actual constructor.
161:             */
162:            @SuppressWarnings("unchecked")
163:            public <T> CtExecutableReference<T> createReference(
164:                    Constructor constructor) {
165:                return createReference(factory.Type().createReference(
166:                        constructor.getDeclaringClass()), null, constructor
167:                        .getName(), factory.Type().createReferences(
168:                        (List) Arrays.asList(constructor.getParameterTypes())));
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.