Source Code Cross Referenced for ASTGenTest.java in  » IDE-Netbeans » refactoring.api » org » netbeans » modules » refactoring » ast » 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 Netbeans » refactoring.api » org.netbeans.modules.refactoring.ast 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * Portions Copyrighted 2007 Sun Microsystems, Inc.
027:         */
028:        package org.netbeans.modules.refactoring.ast;
029:
030:        import java.io.BufferedReader;
031:        import java.io.File;
032:        import java.io.FileReader;
033:        import java.io.FileWriter;
034:        import java.io.IOException;
035:        import java.io.PrintWriter;
036:        import org.netbeans.api.project.Project;
037:        import org.netbeans.api.project.ProjectManager;
038:        import org.netbeans.api.project.ui.OpenProjects;
039:        import org.netbeans.junit.MockServices;
040:        import org.netbeans.junit.NbTestCase;
041:        import org.netbeans.modules.java.source.usages.RepositoryUpdater;
042:        import org.netbeans.modules.refactoring.api.AbstractRefactoring;
043:        import org.netbeans.modules.refactoring.api.Problem;
044:        import org.netbeans.modules.refactoring.api.RefactoringSession;
045:        import org.netbeans.modules.refactoring.api.RenameRefactoring;
046:        import org.netbeans.modules.refactoring.java.ParameterSetter;
047:        import org.openide.filesystems.FileObject;
048:        import org.openide.filesystems.FileUtil;
049:        import org.openide.util.lookup.Lookups;
050:
051:        /**
052:         *
053:         * @author Jiri Prox
054:         */
055:        public class ASTGenTest extends NbTestCase {
056:
057:            protected PrintWriter ref = null;
058:
059:            protected PrintWriter log = null;
060:
061:            public static File sourceDir = null;
062:
063:            public static File resultDir = null;
064:
065:            public static FileObject openedProject = null;
066:
067:            public ASTGenTest(String name) {
068:                super (name);
069:            }
070:
071:            @Override
072:            @SuppressWarnings("deprecation")
073:            protected void setUp() throws Exception {
074:                super .setUp();
075:                clearWorkDir();
076:                MockServices.setServices();
077:                FileUtil.setMIMEType("java", "text/x-java");
078:                File cacheFolder = new File(getWorkDir(), "var/cache/index");
079:                cacheFolder.mkdirs();
080:                System.setProperty("netbeans.user", cacheFolder.getPath());
081:                if (System.getProperty("source.dir") != null) {
082:                    String sourceDirPath = System.getProperty("source.dir");
083:                    File directory = new File(sourceDirPath);
084:                    if (directory.isAbsolute())
085:                        sourceDir = directory;
086:                    else
087:                        sourceDir = new File(getDataDir(), sourceDirPath);
088:                } else {
089:                    sourceDir = getDataDir();
090:                }
091:
092:                if (System.getProperty("result.dir") != null) {
093:                    String resultDirPath = System.getProperty("result.dir");
094:                    File directory = new File(resultDirPath);
095:                    if (directory.isAbsolute())
096:                        resultDir = directory;
097:                    else
098:                        resultDir = new File(getDataDir(), resultDirPath);
099:                } else {
100:                    resultDir = getWorkDir();
101:                }
102:                System.out.println("#### " + getName() + " ####");
103:                ref = new PrintWriter(new File(resultDir, getName() + ".ref"));
104:                log = new PrintWriter(new File(resultDir, getName() + ".log"));
105:                ref.println("#### " + getName() + " ####");
106:                log.println("#### " + getName() + " ####");
107:            }
108:
109:            @Override
110:            protected void tearDown() throws Exception {
111:                log.close();
112:                ref.close();
113:                super .tearDown();
114:            }
115:
116:            public void testRename() throws IOException, InterruptedException {
117:                File[] projects = sourceDir.listFiles();
118:                for (int i = 0; i < projects.length; i++) {
119:                    File project = projects[i];
120:                    if (project.isFile())
121:                        continue; //only directories
122:                    FileObject srcRoot = FileUtil.toFileObject(new File(
123:                            project, "src"));
124:                    RepositoryUpdater.getDefault().scheduleCompilationAndWait(
125:                            srcRoot, srcRoot).await();
126:                    openedProject = openProject(project);
127:                    String testClass = "A";
128:                    if (System.getProperty("test.class") != null) {
129:                        testClass = System.getProperty("test.class");
130:                    }
131:                    final String newName;
132:                    if (System.getProperty("new.name") != null) {
133:                        newName = System.getProperty("new.name");
134:                    } else {
135:                        newName = "NewName";
136:                    }
137:                    FileObject test = openedProject.getFileObject("src/"
138:                            + testClass.replace('.', '/') + ".java");
139:                    final RenameRefactoring renameRefactoring = new RenameRefactoring(
140:                            Lookups.singleton(test));
141:                    performASTGenRerfactoring(renameRefactoring,
142:                            new ParameterSetter() {
143:                                public void setParameters() {
144:                                    renameRefactoring.setNewName(newName);
145:                                }
146:                            }, project);
147:                }
148:            }
149:
150:            public FileObject openProject(File project) throws IOException {
151:                FileObject projectFO = FileUtil.toFileObject(project);
152:                Project p = ProjectManager.getDefault().findProject(projectFO);
153:                OpenProjects.getDefault().open(new Project[] { p }, false);
154:                assertNotNull("Project is not opened", p);
155:                log.println("Project " + project.getName() + " opened");
156:                return projectFO;
157:            }
158:
159:            public boolean performASTGenRerfactoring(
160:                    AbstractRefactoring absRefactoring,
161:                    ParameterSetter parameterSetter, File project) {
162:                Problem problem = absRefactoring.preCheck();
163:                boolean fatal = false;
164:                while (problem != null) {
165:                    ref.print(problem.getMessage());
166:                    fatal = fatal || problem.isFatal();
167:                    problem = problem.getNext();
168:                }
169:                if (fatal) {
170:                    return false;
171:                }
172:                parameterSetter.setParameters();
173:                problem = absRefactoring.fastCheckParameters();
174:                while (problem != null) {
175:                    ref.print(problem.getMessage());
176:                    fatal = fatal || problem.isFatal();
177:                    problem = problem.getNext();
178:                }
179:                if (fatal) {
180:                    return false;
181:                }
182:                problem = absRefactoring.checkParameters();
183:                while (problem != null) {
184:                    ref.print(problem.getMessage());
185:                    fatal = fatal || problem.isFatal();
186:                    problem = problem.getNext();
187:                }
188:                if (fatal) {
189:                    return false;
190:                }
191:                RefactoringSession rs = RefactoringSession.create("Session");
192:                absRefactoring.prepare(rs);
193:                rs.doRefactoring(true);
194:                writeResult(project);
195:                return true;
196:            }
197:
198:            private void writeResult(File project) {
199:                File srcRoot = new File(sourceDir, project.getName() + "/src");
200:                copyDir(srcRoot, new File(resultDir, project.getName()), true);
201:            }
202:
203:            public void copyDir(File srcDir, File destDir, boolean recursive) {
204:                if (!destDir.exists())
205:                    destDir.mkdirs();
206:                File[] files = srcDir.listFiles();
207:                for (int i = 0; i < files.length; i++) {
208:                    File file = files[i];
209:                    if (file.getName().startsWith("."))
210:                        continue; //skip hidden
211:                    if (file.isDirectory()) {
212:                        if (recursive)
213:                            copyDir(file, new File(destDir, file.getName()),
214:                                    true);
215:                    } else {
216:                        copyFile(file, new File(destDir, file.getName()));
217:                    }
218:                }
219:            }
220:
221:            public void copyFile(File src, File dst) {
222:                BufferedReader br = null;
223:                FileWriter fw = null;
224:                try {
225:                    br = new BufferedReader(new FileReader(src));
226:                    fw = new FileWriter(dst);
227:                    String buff;
228:                    while ((buff = br.readLine()) != null)
229:                        fw.write(buff + "\n");
230:                    fw.close();
231:                    br.close();
232:                } catch (IOException ioexception) {
233:                    ioexception.printStackTrace(log);
234:                    fail("Error while storing results");
235:                } finally {
236:                    try {
237:                        if (fw != null)
238:                            fw.close();
239:                        if (br != null)
240:                            br.close();
241:                    } catch (IOException ioexception) {
242:                        ioexception.printStackTrace(log);
243:                        fail("Error while storing results");
244:                    }
245:                }
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.