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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.corext.refactoring.util;
011:
012:        import java.util.Iterator;
013:        import java.util.Map;
014:
015:        import org.eclipse.core.runtime.IProgressMonitor;
016:
017:        import org.eclipse.jdt.core.IClassFile;
018:        import org.eclipse.jdt.core.ICompilationUnit;
019:        import org.eclipse.jdt.core.IJavaElement;
020:        import org.eclipse.jdt.core.IJavaProject;
021:        import org.eclipse.jdt.core.ITypeRoot;
022:        import org.eclipse.jdt.core.JavaCore;
023:        import org.eclipse.jdt.core.WorkingCopyOwner;
024:        import org.eclipse.jdt.core.dom.ASTNode;
025:        import org.eclipse.jdt.core.dom.ASTParser;
026:        import org.eclipse.jdt.core.dom.CompilationUnit;
027:
028:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
029:
030:        import org.eclipse.jdt.ui.SharedASTProvider;
031:
032:        import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
033:
034:        public class RefactoringASTParser {
035:
036:            private ASTParser fParser;
037:
038:            public RefactoringASTParser(int level) {
039:                fParser = ASTParser.newParser(level);
040:            }
041:
042:            public CompilationUnit parse(ITypeRoot typeRoot,
043:                    boolean resolveBindings) {
044:                return parse(typeRoot, resolveBindings, null);
045:            }
046:
047:            public CompilationUnit parse(ITypeRoot typeRoot,
048:                    boolean resolveBindings, IProgressMonitor pm) {
049:                return parse(typeRoot, null, resolveBindings, pm);
050:            }
051:
052:            public CompilationUnit parse(ITypeRoot typeRoot,
053:                    WorkingCopyOwner owner, boolean resolveBindings,
054:                    IProgressMonitor pm) {
055:                return parse(typeRoot, owner, resolveBindings, false, false, pm);
056:            }
057:
058:            public CompilationUnit parse(ITypeRoot typeRoot,
059:                    WorkingCopyOwner owner, boolean resolveBindings,
060:                    boolean statementsRecovery, boolean bindingsRecovery,
061:                    IProgressMonitor pm) {
062:                fParser.setResolveBindings(resolveBindings);
063:                fParser.setStatementsRecovery(statementsRecovery);
064:                fParser.setBindingsRecovery(bindingsRecovery);
065:                fParser.setSource(typeRoot);
066:                if (owner != null)
067:                    fParser.setWorkingCopyOwner(owner);
068:                fParser.setCompilerOptions(getCompilerOptions(typeRoot));
069:                CompilationUnit result = (CompilationUnit) fParser
070:                        .createAST(pm);
071:                return result;
072:            }
073:
074:            /**
075:             * @param newCuSource the source
076:             * @param originalCu the compilation unit to get the name and project from
077:             * @param resolveBindings whether bindings are to be resolved
078:             * @param statementsRecovery whether statements recovery should be enabled
079:             * @param pm an {@link IProgressMonitor}, or <code>null</code>
080:             * @return the parsed CompilationUnit
081:             */
082:            public CompilationUnit parse(String newCuSource,
083:                    ICompilationUnit originalCu, boolean resolveBindings,
084:                    boolean statementsRecovery, IProgressMonitor pm) {
085:                fParser.setResolveBindings(resolveBindings);
086:                fParser.setStatementsRecovery(statementsRecovery);
087:                fParser.setSource(newCuSource.toCharArray());
088:                fParser.setUnitName(originalCu.getElementName());
089:                fParser.setProject(originalCu.getJavaProject());
090:                fParser.setCompilerOptions(getCompilerOptions(originalCu));
091:                CompilationUnit newCUNode = (CompilationUnit) fParser
092:                        .createAST(pm);
093:                return newCUNode;
094:            }
095:
096:            /**
097:             * @param newCfSource the source
098:             * @param originalCf the class file to get the name and project from
099:             * @param resolveBindings whether bindings are to be resolved
100:             * @param statementsRecovery whether statements recovery should be enabled
101:             * @param pm an {@link IProgressMonitor}, or <code>null</code>
102:             * @return the parsed CompilationUnit
103:             */
104:            public CompilationUnit parse(String newCfSource,
105:                    IClassFile originalCf, boolean resolveBindings,
106:                    boolean statementsRecovery, IProgressMonitor pm) {
107:                fParser.setResolveBindings(resolveBindings);
108:                fParser.setStatementsRecovery(statementsRecovery);
109:                fParser.setSource(newCfSource.toCharArray());
110:                String cfName = originalCf.getElementName();
111:                fParser.setUnitName(cfName.substring(0, cfName.length() - 6)
112:                        + JavaModelUtil.DEFAULT_CU_SUFFIX);
113:                fParser.setProject(originalCf.getJavaProject());
114:                fParser.setCompilerOptions(getCompilerOptions(originalCf));
115:                CompilationUnit newCUNode = (CompilationUnit) fParser
116:                        .createAST(pm);
117:                return newCUNode;
118:            }
119:
120:            /**
121:             * Tries to get the shared AST from the ASTProvider.
122:             * If the shared AST is not available, parses the type root with a
123:             * RefactoringASTParser that uses settings similar to the ASTProvider.
124:             * 
125:             * @param typeRoot the type root
126:             * @param resolveBindings TODO
127:             * @param pm an {@link IProgressMonitor}, or <code>null</code>
128:             * @return the parsed CompilationUnit
129:             */
130:            public static CompilationUnit parseWithASTProvider(
131:                    ITypeRoot typeRoot, boolean resolveBindings,
132:                    IProgressMonitor pm) {
133:                CompilationUnit cuNode = SharedASTProvider.getAST(typeRoot,
134:                        SharedASTProvider.WAIT_ACTIVE_ONLY, pm);
135:                if (cuNode != null) {
136:                    return cuNode;
137:                } else {
138:                    return new RefactoringASTParser(
139:                            ASTProvider.SHARED_AST_LEVEL).parse(typeRoot, null,
140:                            resolveBindings,
141:                            ASTProvider.SHARED_AST_STATEMENT_RECOVERY,
142:                            ASTProvider.SHARED_BINDING_RECOVERY, pm);
143:                }
144:            }
145:
146:            public static ICompilationUnit getCompilationUnit(ASTNode node) {
147:                ASTNode root = node.getRoot();
148:                if (root instanceof  CompilationUnit) {
149:                    IJavaElement cu = ((CompilationUnit) root).getJavaElement();
150:                    if (cu instanceof  ICompilationUnit)
151:                        return (ICompilationUnit) cu;
152:                }
153:                return null;
154:            }
155:
156:            public static Map getCompilerOptions(IJavaElement element) {
157:                IJavaProject project = element.getJavaProject();
158:                Map options = project.getOptions(true);
159:                // turn all errors and warnings into ignore. The customizable set of compiler
160:                // options only contains additional Eclipse options. The standard JDK compiler
161:                // options can't be changed anyway.
162:                for (Iterator iter = options.keySet().iterator(); iter
163:                        .hasNext();) {
164:                    String key = (String) iter.next();
165:                    String value = (String) options.get(key);
166:                    if ("error".equals(value) || "warning".equals(value)) { //$NON-NLS-1$//$NON-NLS-2$
167:                        // System.out.println("Ignoring - " + key);
168:                        options.put(key, "ignore"); //$NON-NLS-1$
169:                    }
170:                }
171:                options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$		
172:                return options;
173:            }
174:        }
ww___w._jav___a_2___s_._c___o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.