Source Code Cross Referenced for CreateFieldOperation.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » core » 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 Eclipse » jdt » org.eclipse.jdt.internal.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.core;
011:
012:        import java.util.Iterator;
013:
014:        import org.eclipse.jdt.core.ICompilationUnit;
015:        import org.eclipse.jdt.core.IField;
016:        import org.eclipse.jdt.core.IJavaElement;
017:        import org.eclipse.jdt.core.IJavaModelStatus;
018:        import org.eclipse.jdt.core.IJavaModelStatusConstants;
019:        import org.eclipse.jdt.core.IType;
020:        import org.eclipse.jdt.core.JavaModelException;
021:        import org.eclipse.jdt.core.dom.ASTNode;
022:        import org.eclipse.jdt.core.dom.FieldDeclaration;
023:        import org.eclipse.jdt.core.dom.SimpleName;
024:        import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
025:        import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
026:        import org.eclipse.jdt.internal.core.util.Messages;
027:        import org.eclipse.jface.text.IDocument;
028:
029:        /**
030:         * <p>This operation creates a field declaration in a type.
031:         *
032:         * <p>Required Attributes:<ul>
033:         *  <li>Containing Type
034:         *  <li>The source code for the declaration. No verification of the source is
035:         *      performed.
036:         * </ul>
037:         */
038:        public class CreateFieldOperation extends CreateTypeMemberOperation {
039:            /**
040:             * When executed, this operation will create a field with the given name
041:             * in the given type with the specified source.
042:             *
043:             * <p>By default the new field is positioned after the last existing field
044:             * declaration, or as the first member in the type if there are no
045:             * field declarations.
046:             */
047:            public CreateFieldOperation(IType parentElement, String source,
048:                    boolean force) {
049:                super (parentElement, source, force);
050:            }
051:
052:            protected ASTNode generateElementAST(ASTRewrite rewriter,
053:                    IDocument document, ICompilationUnit cu)
054:                    throws JavaModelException {
055:                ASTNode node = super .generateElementAST(rewriter, document, cu);
056:                if (node.getNodeType() != ASTNode.FIELD_DECLARATION)
057:                    throw new JavaModelException(new JavaModelStatus(
058:                            IJavaModelStatusConstants.INVALID_CONTENTS));
059:                return node;
060:            }
061:
062:            /**
063:             * @see CreateElementInCUOperation#generateResultHandle
064:             */
065:            protected IJavaElement generateResultHandle() {
066:                return getType().getField(getASTNodeName());
067:            }
068:
069:            /**
070:             * @see CreateElementInCUOperation#getMainTaskName()
071:             */
072:            public String getMainTaskName() {
073:                return Messages.operation_createFieldProgress;
074:            }
075:
076:            private VariableDeclarationFragment getFragment(ASTNode node) {
077:                Iterator fragments = ((FieldDeclaration) node).fragments()
078:                        .iterator();
079:                if (this .anchorElement != null) {
080:                    VariableDeclarationFragment fragment = null;
081:                    String fragmentName = this .anchorElement.getElementName();
082:                    while (fragments.hasNext()) {
083:                        fragment = (VariableDeclarationFragment) fragments
084:                                .next();
085:                        if (fragment.getName().getIdentifier().equals(
086:                                fragmentName)) {
087:                            return fragment;
088:                        }
089:                    }
090:                    return fragment;
091:                } else {
092:                    return (VariableDeclarationFragment) fragments.next();
093:                }
094:            }
095:
096:            /**
097:             * By default the new field is positioned after the last existing field
098:             * declaration, or as the first member in the type if there are no
099:             * field declarations.
100:             */
101:            protected void initializeDefaultPosition() {
102:                IType parentElement = getType();
103:                try {
104:                    IField[] fields = parentElement.getFields();
105:                    if (fields != null && fields.length > 0) {
106:                        final IField lastField = fields[fields.length - 1];
107:                        if (parentElement.isEnum()) {
108:                            IField field = lastField;
109:                            if (!field.isEnumConstant()) {
110:                                createAfter(lastField);
111:                            }
112:                        } else {
113:                            createAfter(lastField);
114:                        }
115:                    } else {
116:                        IJavaElement[] elements = parentElement.getChildren();
117:                        if (elements != null && elements.length > 0) {
118:                            createBefore(elements[0]);
119:                        }
120:                    }
121:                } catch (JavaModelException e) {
122:                    // type doesn't exist: ignore
123:                }
124:            }
125:
126:            /**
127:             * @see CreateTypeMemberOperation#verifyNameCollision
128:             */
129:            protected IJavaModelStatus verifyNameCollision() {
130:                if (this .createdNode != null) {
131:                    IType type = getType();
132:                    String fieldName = getASTNodeName();
133:                    if (type.getField(fieldName).exists()) {
134:                        return new JavaModelStatus(
135:                                IJavaModelStatusConstants.NAME_COLLISION,
136:                                Messages.bind(Messages.status_nameCollision,
137:                                        fieldName));
138:                    }
139:                }
140:                return JavaModelStatus.VERIFIED_OK;
141:            }
142:
143:            private String getASTNodeName() {
144:                if (this .alteredName != null)
145:                    return this .alteredName;
146:                return getFragment(this .createdNode).getName().getIdentifier();
147:            }
148:
149:            protected SimpleName rename(ASTNode node, SimpleName newName) {
150:                VariableDeclarationFragment fragment = getFragment(node);
151:                SimpleName oldName = fragment.getName();
152:                fragment.setName(newName);
153:                return oldName;
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.