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


001:        package org.eclipse.jdt.internal.corext.refactoring;
002:
003:        import org.eclipse.core.runtime.IPath;
004:        import org.eclipse.core.runtime.Path;
005:
006:        import org.eclipse.core.resources.IResource;
007:        import org.eclipse.core.resources.IWorkspaceRoot;
008:        import org.eclipse.core.resources.ResourcesPlugin;
009:
010:        import org.eclipse.jdt.core.IJavaElement;
011:        import org.eclipse.jdt.core.IJavaProject;
012:        import org.eclipse.jdt.core.IMethod;
013:        import org.eclipse.jdt.core.JavaCore;
014:        import org.eclipse.jdt.core.WorkingCopyOwner;
015:
016:        public class JavaRefactoringDescriptorUtil {
017:            /* TODO: share implementation with
018:             * org.eclipse.jdt.internal.core.refactoring.descriptors.JavaRefactoringDescriptorUtil
019:             */
020:
021:            private JavaRefactoringDescriptorUtil() {
022:            }
023:
024:            /**
025:             * Predefined argument called <code>element&lt;Number&gt;</code>.
026:             * <p>
027:             * This argument should be used to describe the elements being refactored.
028:             * The value of this argument does not necessarily have to uniquely identify
029:             * the elements. However, it must be possible to uniquely identify the
030:             * elements using the value of this argument in conjunction with the values
031:             * of the other user-defined attributes.
032:             * </p>
033:             * <p>
034:             * The element arguments are simply distinguished by appending a number to
035:             * the argument name, e.g. element1. The indices of this argument are non
036:             * zero-based.
037:             * </p>
038:             */
039:            public static final String ATTRIBUTE_ELEMENT = "element"; //$NON-NLS-1$
040:
041:            /**
042:             * Predefined argument called <code>input</code>.
043:             * <p>
044:             * This argument should be used to describe the element being refactored.
045:             * The value of this argument does not necessarily have to uniquely identify
046:             * the input element. However, it must be possible to uniquely identify the
047:             * input element using the value of this argument in conjunction with the
048:             * values of the other user-defined attributes.
049:             * </p>
050:             */
051:            public static final String ATTRIBUTE_INPUT = "input"; //$NON-NLS-1$
052:
053:            /**
054:             * Predefined argument called <code>name</code>.
055:             * <p>
056:             * This argument should be used to name the element being refactored. The
057:             * value of this argument may be shown in the user interface.
058:             * </p>
059:             */
060:            public static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
061:
062:            /**
063:             * Predefined argument called <code>references</code>.
064:             * <p>
065:             * This argument should be used to describe whether references to the
066:             * elements being refactored should be updated as well.
067:             * </p>
068:             */
069:            public static final String ATTRIBUTE_REFERENCES = "references"; //$NON-NLS-1$
070:
071:            /**
072:             * Predefined argument called <code>selection</code>.
073:             * <p>
074:             * This argument should be used to describe user input selections within a
075:             * text file. The value of this argument has the format "offset length".
076:             * </p>
077:             */
078:            public static final String ATTRIBUTE_SELECTION = "selection"; //$NON-NLS-1$
079:
080:            /**
081:             * Converts the specified element to an input handle.
082:             * 
083:             * @param project
084:             *            the project, or <code>null</code> for the workspace
085:             * @param element
086:             *            the element
087:             * @return a corresponding input handle
088:             *         Note: if the given project is not the element's project, then the full handle is returned 
089:             */
090:            public static String elementToHandle(final String project,
091:                    final IJavaElement element) {
092:                final String handle = element.getHandleIdentifier();
093:                if (project != null && !(element instanceof  IJavaProject)) {
094:                    IJavaProject javaProject = element.getJavaProject();
095:                    if (project.equals(javaProject.getElementName())) {
096:                        final String id = javaProject.getHandleIdentifier();
097:                        return handle.substring(id.length());
098:                    }
099:                }
100:                return handle;
101:            }
102:
103:            /**
104:             * Converts an input handle back to the corresponding java element.
105:             * 
106:             * @param project
107:             *            the project, or <code>null</code> for the workspace
108:             * @param handle
109:             *            the input handle
110:             * @return the corresponding java element, or <code>null</code> if no such
111:             *         element exists
112:             */
113:            public static IJavaElement handleToElement(final String project,
114:                    final String handle) {
115:                return handleToElement(project, handle, true);
116:            }
117:
118:            /**
119:             * Converts an input handle back to the corresponding java element.
120:             * 
121:             * @param project
122:             *            the project, or <code>null</code> for the workspace
123:             * @param handle
124:             *            the input handle
125:             * @param check
126:             *            <code>true</code> to check for existence of the element,
127:             *            <code>false</code> otherwise
128:             * @return the corresponding java element, or <code>null</code> if no such
129:             *         element exists
130:             */
131:            public static IJavaElement handleToElement(final String project,
132:                    final String handle, final boolean check) {
133:                return handleToElement(null, project, handle, check);
134:            }
135:
136:            /**
137:             * Converts an input handle back to the corresponding java element.
138:             * 
139:             * @param owner
140:             *            the working copy owner
141:             * @param project
142:             *            the project, or <code>null</code> for the workspace
143:             * @param handle
144:             *            the input handle
145:             * @param check
146:             *            <code>true</code> to check for existence of the element,
147:             *            <code>false</code> otherwise
148:             * @return the corresponding java element, or <code>null</code> if no such
149:             *         element exists
150:             */
151:            public static IJavaElement handleToElement(
152:                    final WorkingCopyOwner owner, final String project,
153:                    final String handle, final boolean check) {
154:                IJavaElement element = null;
155:                if (owner != null)
156:                    element = JavaCore.create(handle, owner);
157:                else
158:                    element = JavaCore.create(handle);
159:                if (element == null && project != null) {
160:                    final IJavaProject javaProject = JavaCore.create(
161:                            ResourcesPlugin.getWorkspace().getRoot())
162:                            .getJavaProject(project);
163:                    final String identifier = javaProject.getHandleIdentifier();
164:                    if (owner != null)
165:                        element = JavaCore.create(identifier + handle, owner);
166:                    else
167:                        element = JavaCore.create(identifier + handle);
168:                }
169:                if (check && element instanceof  IMethod) {
170:                    /*
171:                     * Resolve the method based on simple names of parameter types
172:                     * (to accommodate for different qualifications when refactoring is e.g.
173:                     * recorded in source but applied on binary method):
174:                     */
175:                    final IMethod method = (IMethod) element;
176:                    final IMethod[] methods = method.getDeclaringType()
177:                            .findMethods(method);
178:                    if (methods != null && methods.length > 0)
179:                        element = methods[0];
180:                }
181:                if (element != null && (!check || element.exists()))
182:                    return element;
183:                return null;
184:            }
185:
186:            /**
187:             * Converts an input handle with the given prefix back to the corresponding
188:             * resource.
189:             * 
190:             * @param project
191:             *            the project, or <code>null</code> for the workspace
192:             * @param handle
193:             *            the input handle
194:             * 
195:             * @return the corresponding resource, or <code>null</code> if no such
196:             *         resource exists.
197:             *         Note: if the given handle is absolute, the project is not used to resolve.
198:             */
199:            public static IResource handleToResource(final String project,
200:                    final String handle) {
201:                final IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
202:                        .getRoot();
203:                if ("".equals(handle)) //$NON-NLS-1$
204:                    return null;
205:                final IPath path = Path.fromPortableString(handle);
206:                if (path == null)
207:                    return null;
208:                if (project != null
209:                        && !"".equals(project) && !path.isAbsolute()) //$NON-NLS-1$
210:                    return root.getProject(project).findMember(path);
211:                return root.findMember(path);
212:            }
213:
214:            /**
215:             * Converts the specified resource to an input handle.
216:             * 
217:             * @param project
218:             *            the project, or <code>null</code> for the workspace
219:             * @param resource
220:             *            the resource
221:             * 
222:             * @return the input handle.
223:             *         Note: if the given project is not the resource's project, then the full handle is returned. 
224:             */
225:            public static String resourceToHandle(final String project,
226:                    final IResource resource) {
227:                if (project != null
228:                        && !"".equals(project) && project.equals(resource.getProject().getName())) //$NON-NLS-1$
229:                    return resource.getProjectRelativePath().toPortableString();
230:                return resource.getFullPath().toPortableString();
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.