Source Code Cross Referenced for FieldFactory.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.Field;
021:        import java.util.Set;
022:
023:        import spoon.reflect.Factory;
024:        import spoon.reflect.code.CtExpression;
025:        import spoon.reflect.declaration.CtField;
026:        import spoon.reflect.declaration.CtSimpleType;
027:        import spoon.reflect.declaration.CtType;
028:        import spoon.reflect.declaration.ModifierKind;
029:        import spoon.reflect.reference.CtFieldReference;
030:        import spoon.reflect.reference.CtTypeReference;
031:
032:        /**
033:         * The {@link CtField} sub-factory.
034:         */
035:        public class FieldFactory extends SubFactory {
036:
037:            private static final long serialVersionUID = 1L;
038:
039:            /**
040:             * Creates a new field sub-factory.
041:             * 
042:             * @param factory
043:             *            the parent factory
044:             */
045:            public FieldFactory(Factory factory) {
046:                super (factory);
047:            }
048:
049:            /**
050:             * Creates a field.
051:             * 
052:             * @param target
053:             *            the target type to which the field is added
054:             * @param modifiers
055:             *            the modifiers
056:             * @param type
057:             *            the field's type
058:             * @param name
059:             *            the field's name
060:             */
061:            public <T> CtField<T> create(CtSimpleType<?> target,
062:                    Set<ModifierKind> modifiers, CtTypeReference<T> type,
063:                    String name) {
064:                CtField<T> field = factory.Core().createField();
065:                field.setModifiers(modifiers);
066:                field.setType(type);
067:                field.setSimpleName(name);
068:                field.setParent(target);
069:                if (target != null)
070:                    target.getFields().add(field);
071:                return field;
072:            }
073:
074:            /**
075:             * Creates a field.
076:             * 
077:             * @param target
078:             *            the target type to which the field is added
079:             * @param modifiers
080:             *            the modifiers
081:             * @param type
082:             *            the field's type
083:             * @param name
084:             *            the field's name
085:             * @param defaultExpression
086:             *            the initializing expression
087:             */
088:            public <T> CtField<T> create(CtSimpleType<?> target,
089:                    Set<ModifierKind> modifiers, CtTypeReference<T> type,
090:                    String name, CtExpression<T> defaultExpression) {
091:                CtField<T> field = create(target, modifiers, type, name);
092:                field.setDefaultExpression(defaultExpression);
093:                return field;
094:            }
095:
096:            /**
097:             * Creates a field by copying an existing field.
098:             * 
099:             * @param <T>
100:             *            the type of the field
101:             * @param target
102:             *            the target type where the new field has to be inserted to
103:             * @param source
104:             *            the source field to be copied
105:             * @return the newly created field
106:             */
107:            public <T> CtField<T> create(CtType<?> target, CtField<T> source) {
108:                CtField<T> newField = factory.Core().clone(source);
109:                if (target != null)
110:                    target.getFields().add(newField);
111:                newField.setParent(target);
112:                return newField;
113:            }
114:
115:            /**
116:             * Creates a field reference from an existing field.
117:             */
118:            public <T> CtFieldReference<T> createReference(CtField<T> field) {
119:                return createReference(factory.Type().createReference(
120:                        field.getDeclaringType()), field.getType(), field
121:                        .getSimpleName());
122:            }
123:
124:            /**
125:             * Creates a field reference.
126:             */
127:            public <T> CtFieldReference<T> createReference(
128:                    CtTypeReference<?> declaringType, CtTypeReference<T> type,
129:                    String fieldName) {
130:                CtFieldReference<T> fieldRef = factory.Core()
131:                        .createFieldReference();
132:                fieldRef.setSimpleName(fieldName);
133:                fieldRef.setDeclaringType(declaringType);
134:                fieldRef.setType(type);
135:                return fieldRef;
136:            }
137:
138:            /**
139:             * Creates a field reference from a <code>java.lang.reflect</code> field.
140:             */
141:            @SuppressWarnings("unchecked")
142:            public <T> CtFieldReference<T> createReference(Field field) {
143:                CtFieldReference fieldRef = factory.Core()
144:                        .createFieldReference();
145:                fieldRef.setSimpleName(field.getName());
146:                fieldRef.setDeclaringType(factory.Type().createReference(
147:                        field.getDeclaringClass()));
148:                fieldRef.setType(factory.Type()
149:                        .createReference(field.getType()));
150:                return fieldRef;
151:            }
152:
153:            /**
154:             * Creates a field reference from its signature, as defined by the field
155:             * reference's toString.
156:             */
157:            public <T> CtFieldReference<T> createReference(String signature) {
158:                CtFieldReference<T> fieldRef = factory.Core()
159:                        .createFieldReference();
160:                String type = signature.substring(0, signature.indexOf(" "));
161:                String declaringType = signature.substring(signature
162:                        .indexOf(" ") + 1, signature
163:                        .indexOf(CtField.FIELD_SEPARATOR));
164:                String fieldName = signature.substring(signature
165:                        .indexOf(CtField.FIELD_SEPARATOR) + 1);
166:                fieldRef.setSimpleName(fieldName);
167:                fieldRef.setDeclaringType(factory.Type().createReference(
168:                        declaringType));
169:                CtTypeReference<T> typeRef = factory.Type().createReference(
170:                        type);
171:                fieldRef.setType(typeRef);
172:                return fieldRef;
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.