Source Code Cross Referenced for ChangeNonStaticToStaticTest.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » tests » quickfix » 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.ui.tests.quickfix 
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.ui.tests.quickfix;
011:
012:        import java.util.Hashtable;
013:        import java.util.Map;
014:
015:        import junit.framework.Test;
016:        import junit.framework.TestSuite;
017:
018:        import org.eclipse.core.runtime.CoreException;
019:        import org.eclipse.core.runtime.NullProgressMonitor;
020:        import org.eclipse.core.runtime.Preferences;
021:
022:        import org.eclipse.jface.preference.IPreferenceStore;
023:
024:        import org.eclipse.ltk.core.refactoring.Change;
025:        import org.eclipse.ltk.core.refactoring.CompositeChange;
026:        import org.eclipse.ltk.core.refactoring.TextEditBasedChange;
027:
028:        import org.eclipse.jdt.core.ICompilationUnit;
029:        import org.eclipse.jdt.core.IJavaProject;
030:        import org.eclipse.jdt.core.IPackageFragment;
031:        import org.eclipse.jdt.core.IPackageFragmentRoot;
032:        import org.eclipse.jdt.core.JavaCore;
033:        import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
034:
035:        import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
036:        import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
037:        import org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring;
038:        import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
039:
040:        import org.eclipse.jdt.ui.PreferenceConstants;
041:
042:        import org.eclipse.jdt.internal.ui.JavaPlugin;
043:        import org.eclipse.jdt.internal.ui.fix.CodeStyleCleanUp;
044:        import org.eclipse.jdt.internal.ui.fix.ICleanUp;
045:
046:        import org.eclipse.jdt.testplugin.JavaProjectHelper;
047:        import org.eclipse.jdt.testplugin.TestOptions;
048:
049:        import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
050:
051:        public class ChangeNonStaticToStaticTest extends QuickFixTest {
052:
053:            private static final Class THIS = ChangeNonStaticToStaticTest.class;
054:
055:            private IJavaProject fJProject1;
056:            private IPackageFragmentRoot fSourceFolder;
057:
058:            public ChangeNonStaticToStaticTest(String name) {
059:                super (name);
060:            }
061:
062:            public static Test allTests() {
063:                return new ProjectTestSetup(new TestSuite(THIS));
064:            }
065:
066:            public static Test suite() {
067:                return allTests();
068:            }
069:
070:            public static Test setUpTest(Test test) {
071:                return new ProjectTestSetup(test);
072:            }
073:
074:            protected void setUp() throws Exception {
075:                Hashtable options = TestOptions.getDefaultOptions();
076:                options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR,
077:                        JavaCore.SPACE);
078:                options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE,
079:                        "4");
080:
081:                JavaCore.setOptions(options);
082:
083:                IPreferenceStore store = JavaPlugin.getDefault()
084:                        .getPreferenceStore();
085:                store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
086:                store.setValue(PreferenceConstants.CODEGEN_KEYWORD_THIS, false);
087:
088:                StubUtility.setCodeTemplate(
089:                        CodeTemplateContextType.METHODSTUB_ID,
090:                        "//TODO\n${body_statement}", null);
091:
092:                Preferences corePrefs = JavaCore.getPlugin()
093:                        .getPluginPreferences();
094:                corePrefs.setValue(JavaCore.CODEASSIST_FIELD_PREFIXES, "");
095:                corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES,
096:                        "");
097:                corePrefs.setValue(JavaCore.CODEASSIST_FIELD_SUFFIXES, "");
098:                corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES,
099:                        "");
100:
101:                fJProject1 = ProjectTestSetup.getProject();
102:
103:                fSourceFolder = JavaProjectHelper.addSourceContainer(
104:                        fJProject1, "src");
105:            }
106:
107:            protected void tearDown() throws Exception {
108:                JavaProjectHelper.clear(fJProject1, ProjectTestSetup
109:                        .getDefaultClasspath());
110:            }
111:
112:            private void assertRefactoringResultAsExpected(
113:                    CleanUpRefactoring refactoring, String[] expected)
114:                    throws CoreException {
115:                refactoring.checkAllConditions(new NullProgressMonitor());
116:                CompositeChange change = (CompositeChange) refactoring
117:                        .createChange(null);
118:                Change[] children = change.getChildren();
119:                String[] previews = new String[children.length];
120:                for (int i = 0; i < children.length; i++) {
121:                    previews[i] = ((TextEditBasedChange) children[i])
122:                            .getPreviewContent(null);
123:                }
124:
125:                assertEqualStringsIgnoreOrder(previews, expected);
126:            }
127:
128:            private CodeStyleCleanUp createCleanUp() {
129:                Map options = new Hashtable();
130:                options
131:                        .put(
132:                                CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS,
133:                                CleanUpConstants.TRUE);
134:                options
135:                        .put(
136:                                CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS,
137:                                CleanUpConstants.TRUE);
138:                return new CodeStyleCleanUp(options);
139:            }
140:
141:            public void testNonStaticAccessTest01() throws Exception {
142:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
143:                        "test1", false, null);
144:                StringBuffer buf = new StringBuffer();
145:                buf.append("package test1;\n");
146:                buf.append("public class E1 {\n");
147:                buf.append("    public static int I;\n");
148:                buf.append("    public void foo() {\n");
149:                buf.append("        (new E1()).I= 10;\n");
150:                buf.append("    }\n");
151:                buf.append("}\n");
152:                ICompilationUnit cu = pack1.createCompilationUnit("E1.java",
153:                        buf.toString(), false, null);
154:
155:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
156:                refactoring.addCompilationUnit(cu);
157:
158:                ICleanUp cleanUp = createCleanUp();
159:                refactoring.addCleanUp(cleanUp);
160:
161:                buf = new StringBuffer();
162:                buf.append("package test1;\n");
163:                buf.append("public class E1 {\n");
164:                buf.append("    public static int I;\n");
165:                buf.append("    public void foo() {\n");
166:                buf.append("        E1.I= 10;\n");
167:                buf.append("    }\n");
168:                buf.append("}\n");
169:                String expected1 = buf.toString();
170:
171:                assertRefactoringResultAsExpected(refactoring,
172:                        new String[] { expected1 });
173:            }
174:
175:            public void testNonStaticAccessTest02() throws Exception {
176:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
177:                        "test1", false, null);
178:                StringBuffer buf = new StringBuffer();
179:                buf.append("package test1;\n");
180:                buf.append("public class E1<T> {\n");
181:                buf.append("    public static int I;\n");
182:                buf.append("    public void foo() {\n");
183:                buf.append("        (new E1<String>()).I= 10;\n");
184:                buf.append("    }\n");
185:                buf.append("}\n");
186:                ICompilationUnit cu = pack1.createCompilationUnit("E1.java",
187:                        buf.toString(), false, null);
188:
189:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
190:                refactoring.addCompilationUnit(cu);
191:
192:                ICleanUp cleanUp = createCleanUp();
193:                refactoring.addCleanUp(cleanUp);
194:
195:                buf = new StringBuffer();
196:                buf.append("package test1;\n");
197:                buf.append("public class E1<T> {\n");
198:                buf.append("    public static int I;\n");
199:                buf.append("    public void foo() {\n");
200:                buf.append("        E1.I= 10;\n");
201:                buf.append("    }\n");
202:                buf.append("}\n");
203:                String expected1 = buf.toString();
204:
205:                assertRefactoringResultAsExpected(refactoring,
206:                        new String[] { expected1 });
207:            }
208:
209:            public void testNonStaticAccessTest03() throws Exception {
210:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
211:                        "test1", false, null);
212:                StringBuffer buf = new StringBuffer();
213:                buf.append("package test1;\n");
214:                buf.append("public class E1<T extends String> {\n");
215:                buf.append("    public static int I;\n");
216:                buf.append("    public void foo() {\n");
217:                buf.append("        (new E1<String>()).I= 10;\n");
218:                buf.append("    }\n");
219:                buf.append("}\n");
220:                ICompilationUnit cu = pack1.createCompilationUnit("E1.java",
221:                        buf.toString(), false, null);
222:
223:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
224:                refactoring.addCompilationUnit(cu);
225:
226:                ICleanUp cleanUp = createCleanUp();
227:                refactoring.addCleanUp(cleanUp);
228:
229:                buf = new StringBuffer();
230:                buf.append("package test1;\n");
231:                buf.append("public class E1<T extends String> {\n");
232:                buf.append("    public static int I;\n");
233:                buf.append("    public void foo() {\n");
234:                buf.append("        E1.I= 10;\n");
235:                buf.append("    }\n");
236:                buf.append("}\n");
237:                String expected1 = buf.toString();
238:
239:                assertRefactoringResultAsExpected(refactoring,
240:                        new String[] { expected1 });
241:            }
242:
243:            public void testNonStaticAccessTest04() throws Exception {
244:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
245:                        "test1", false, null);
246:                StringBuffer buf = new StringBuffer();
247:                buf.append("package test1;\n");
248:                buf.append("public class E1 {\n");
249:                buf.append("    public static int I;\n");
250:                buf.append("}\n");
251:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
252:                        null);
253:
254:                buf = new StringBuffer();
255:                buf.append("package test1;\n");
256:                buf.append("public class E2 {\n");
257:                buf.append("    private static class E1 {\n");
258:                buf.append("        public static int N;\n");
259:                buf.append("    }\n");
260:                buf.append("    public void bar() {\n");
261:                buf.append("        test1.E1 e1= new test1.E1();\n");
262:                buf.append("        e1.I= 10;\n");
263:                buf.append("        \n");
264:                buf.append("        E1 e12= new E1();\n");
265:                buf.append("        e12.N= 10;\n");
266:                buf.append("    }\n");
267:                buf.append("}\n");
268:                ICompilationUnit cu = pack1.createCompilationUnit("E2.java",
269:                        buf.toString(), false, null);
270:
271:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
272:                refactoring.addCompilationUnit(cu);
273:
274:                ICleanUp cleanUp = createCleanUp();
275:                refactoring.addCleanUp(cleanUp);
276:
277:                buf = new StringBuffer();
278:                buf.append("package test1;\n");
279:                buf.append("public class E2 {\n");
280:                buf.append("    private static class E1 {\n");
281:                buf.append("        public static int N;\n");
282:                buf.append("    }\n");
283:                buf.append("    public void bar() {\n");
284:                buf.append("        test1.E1 e1= new test1.E1();\n");
285:                buf.append("        test1.E1.I= 10;\n");
286:                buf.append("        \n");
287:                buf.append("        E1 e12= new E1();\n");
288:                buf.append("        E1.N= 10;\n");
289:                buf.append("    }\n");
290:                buf.append("}\n");
291:                String expected1 = buf.toString();
292:
293:                assertRefactoringResultAsExpected(refactoring,
294:                        new String[] { expected1 });
295:            }
296:
297:            public void testNonStaticAccessTest05() throws Exception {
298:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
299:                        "test1", false, null);
300:                StringBuffer buf = new StringBuffer();
301:                buf.append("package test1;\n");
302:                buf.append("public class E1 {\n");
303:                buf.append("    public static int I;\n");
304:                buf.append("}\n");
305:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
306:                        null);
307:
308:                buf = new StringBuffer();
309:                buf.append("package test1;\n");
310:                buf.append("public class E2 extends E1 {}\n");
311:                pack1.createCompilationUnit("E2.java", buf.toString(), false,
312:                        null);
313:
314:                IPackageFragment pack2 = fSourceFolder.createPackageFragment(
315:                        "test2", false, null);
316:                buf = new StringBuffer();
317:                buf.append("package test2;\n");
318:                buf.append("import test1.E2;\n");
319:                buf.append("public class E3  {\n");
320:                buf.append("    private E2 e2;\n");
321:                buf.append("    public void foo() {\n");
322:                buf.append("        e2.I= 10;\n");
323:                buf.append("    }\n");
324:                buf.append("}\n");
325:                ICompilationUnit cu = pack2.createCompilationUnit("E3.java",
326:                        buf.toString(), false, null);
327:
328:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
329:                refactoring.addCompilationUnit(cu);
330:
331:                ICleanUp cleanUp = createCleanUp();
332:                refactoring.addCleanUp(cleanUp);
333:
334:                buf = new StringBuffer();
335:                buf.append("package test2;\n");
336:                buf.append("import test1.E1;\n");
337:                buf.append("import test1.E2;\n");
338:                buf.append("public class E3  {\n");
339:                buf.append("    private E2 e2;\n");
340:                buf.append("    public void foo() {\n");
341:                buf.append("        E1.I= 10;\n");
342:                buf.append("    }\n");
343:                buf.append("}\n");
344:                String expected1 = buf.toString();
345:
346:                assertRefactoringResultAsExpected(refactoring,
347:                        new String[] { expected1 });
348:            }
349:
350:            public void testNonStaticAccessTest06() throws Exception {
351:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
352:                        "test1", false, null);
353:                StringBuffer buf = new StringBuffer();
354:                buf.append("package test1;\n");
355:                buf.append("public class E1<T> {\n");
356:                buf.append("    public static int I;\n");
357:                buf.append("}\n");
358:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
359:                        null);
360:
361:                buf = new StringBuffer();
362:                buf.append("package test1;\n");
363:                buf.append("public class E2<T, G> extends E1<T> {}\n");
364:                pack1.createCompilationUnit("E2.java", buf.toString(), false,
365:                        null);
366:
367:                IPackageFragment pack2 = fSourceFolder.createPackageFragment(
368:                        "test2", false, null);
369:                buf = new StringBuffer();
370:                buf.append("package test2;\n");
371:                buf.append("import test1.E2;\n");
372:                buf.append("public class E3<G>  {\n");
373:                buf.append("    private E2<String, G> e2;\n");
374:                buf.append("    public void foo() {\n");
375:                buf.append("        e2.I= 10;\n");
376:                buf.append("    }\n");
377:                buf.append("}\n");
378:                ICompilationUnit cu = pack2.createCompilationUnit("E3.java",
379:                        buf.toString(), false, null);
380:
381:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
382:                refactoring.addCompilationUnit(cu);
383:
384:                ICleanUp cleanUp = createCleanUp();
385:                refactoring.addCleanUp(cleanUp);
386:
387:                buf = new StringBuffer();
388:                buf.append("package test2;\n");
389:                buf.append("import test1.E1;\n");
390:                buf.append("import test1.E2;\n");
391:                buf.append("public class E3<G>  {\n");
392:                buf.append("    private E2<String, G> e2;\n");
393:                buf.append("    public void foo() {\n");
394:                buf.append("        E1.I= 10;\n");
395:                buf.append("    }\n");
396:                buf.append("}\n");
397:                String expected1 = buf.toString();
398:
399:                assertRefactoringResultAsExpected(refactoring,
400:                        new String[] { expected1 });
401:            }
402:
403:            public void testNonStaticAccessTest07() throws Exception {
404:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
405:                        "test1", false, null);
406:                StringBuffer buf = new StringBuffer();
407:                buf.append("package test1;\n");
408:                buf.append("public class E1<T> {\n");
409:                buf.append("    public static int I;\n");
410:                buf.append("}\n");
411:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
412:                        null);
413:
414:                buf = new StringBuffer();
415:                buf.append("package test1;\n");
416:                buf.append("public class E2<T, G> extends E1<T> {}\n");
417:                pack1.createCompilationUnit("E2.java", buf.toString(), false,
418:                        null);
419:
420:                IPackageFragment pack2 = fSourceFolder.createPackageFragment(
421:                        "test2", false, null);
422:                buf = new StringBuffer();
423:                buf.append("package test2;\n");
424:                buf.append("import test1.E2;\n");
425:                buf.append("public class E3<G>  {\n");
426:                buf.append("    private E2<String, G> e2;\n");
427:                buf.append("    private static class E1<T, G> {}\n");
428:                buf.append("    public void foo() {\n");
429:                buf.append("        e2.I= 10;\n");
430:                buf.append("    }\n");
431:                buf.append("}\n");
432:                ICompilationUnit cu = pack2.createCompilationUnit("E3.java",
433:                        buf.toString(), false, null);
434:
435:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
436:                refactoring.addCompilationUnit(cu);
437:
438:                ICleanUp cleanUp = createCleanUp();
439:                refactoring.addCleanUp(cleanUp);
440:
441:                buf = new StringBuffer();
442:                buf.append("package test2;\n");
443:                buf.append("import test1.E2;\n");
444:                buf.append("public class E3<G>  {\n");
445:                buf.append("    private E2<String, G> e2;\n");
446:                buf.append("    private static class E1<T, G> {}\n");
447:                buf.append("    public void foo() {\n");
448:                buf.append("        test1.E1.I= 10;\n");
449:                buf.append("    }\n");
450:                buf.append("}\n");
451:                String expected1 = buf.toString();
452:
453:                assertRefactoringResultAsExpected(refactoring,
454:                        new String[] { expected1 });
455:            }
456:
457:            public void testNonStaticAccessTest08() throws Exception {
458:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
459:                        "test1", false, null);
460:                StringBuffer buf = new StringBuffer();
461:                buf.append("package test1;\n");
462:                buf.append("public class E1<T> {\n");
463:                buf.append("    public static int I;\n");
464:                buf.append("}\n");
465:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
466:                        null);
467:
468:                buf = new StringBuffer();
469:                buf.append("package test1;\n");
470:                buf.append("public class E2<T, G> extends E1<T> {}\n");
471:                pack1.createCompilationUnit("E2.java", buf.toString(), false,
472:                        null);
473:
474:                IPackageFragment pack2 = fSourceFolder.createPackageFragment(
475:                        "test2", false, null);
476:                buf = new StringBuffer();
477:                buf.append("package test2;\n");
478:                buf.append("import test1.E2;\n");
479:                buf.append("public class E3<G>  {\n");
480:                buf.append("    private E2<String, G> e2;\n");
481:                buf.append("    private class E1<T, G> {\n");
482:                buf.append("        private class C {\n");
483:                buf.append("            public void foo() {\n");
484:                buf.append("                e2.I= 10;\n");
485:                buf.append("            }\n");
486:                buf.append("        }\n");
487:                buf.append("    }\n");
488:                buf.append("}\n");
489:                ICompilationUnit cu = pack2.createCompilationUnit("E3.java",
490:                        buf.toString(), false, null);
491:
492:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
493:                refactoring.addCompilationUnit(cu);
494:
495:                ICleanUp cleanUp = createCleanUp();
496:                refactoring.addCleanUp(cleanUp);
497:
498:                buf = new StringBuffer();
499:                buf.append("package test2;\n");
500:                buf.append("import test1.E2;\n");
501:                buf.append("public class E3<G>  {\n");
502:                buf.append("    private E2<String, G> e2;\n");
503:                buf.append("    private class E1<T, G> {\n");
504:                buf.append("        private class C {\n");
505:                buf.append("            public void foo() {\n");
506:                buf.append("                test1.E1.I= 10;\n");
507:                buf.append("            }\n");
508:                buf.append("        }\n");
509:                buf.append("    }\n");
510:                buf.append("}\n");
511:                String expected1 = buf.toString();
512:
513:                assertRefactoringResultAsExpected(refactoring,
514:                        new String[] { expected1 });
515:            }
516:
517:            public void testNonStaticAccessTest09() throws Exception {
518:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
519:                        "test1", false, null);
520:                StringBuffer buf = new StringBuffer();
521:                buf.append("package test1;\n");
522:                buf.append("public class E1<T> {\n");
523:                buf.append("    public static int I;\n");
524:                buf.append("}\n");
525:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
526:                        null);
527:
528:                buf = new StringBuffer();
529:                buf.append("package test1;\n");
530:                buf.append("public class E2<T, G> extends E1<T> {}\n");
531:                pack1.createCompilationUnit("E2.java", buf.toString(), false,
532:                        null);
533:
534:                IPackageFragment pack2 = fSourceFolder.createPackageFragment(
535:                        "test2", false, null);
536:                buf = new StringBuffer();
537:                buf.append("package test2;\n");
538:                buf.append("import test1.E2;\n");
539:                buf.append("public class E3<G>  {\n");
540:                buf.append("    private E2<String, G> e2;\n");
541:                buf.append("    private class C {\n");
542:                buf.append("        private class E1<T, G> {\n");
543:                buf.append("        }\n");
544:                buf.append("    }\n");
545:                buf.append("    public void foo() {\n");
546:                buf.append("        e2.I= 10;\n");
547:                buf.append("    }\n");
548:                buf.append("}\n");
549:                ICompilationUnit cu = pack2.createCompilationUnit("E3.java",
550:                        buf.toString(), false, null);
551:
552:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
553:                refactoring.addCompilationUnit(cu);
554:
555:                ICleanUp cleanUp = createCleanUp();
556:                refactoring.addCleanUp(cleanUp);
557:
558:                buf = new StringBuffer();
559:                buf.append("package test2;\n");
560:                buf.append("import test1.E1;\n");
561:                buf.append("import test1.E2;\n");
562:                buf.append("public class E3<G>  {\n");
563:                buf.append("    private E2<String, G> e2;\n");
564:                buf.append("    private class C {\n");
565:                buf.append("        private class E1<T, G> {\n");
566:                buf.append("        }\n");
567:                buf.append("    }\n");
568:                buf.append("    public void foo() {\n");
569:                buf.append("        E1.I= 10;\n");
570:                buf.append("    }\n");
571:                buf.append("}\n");
572:                String expected1 = buf.toString();
573:
574:                assertRefactoringResultAsExpected(refactoring,
575:                        new String[] { expected1 });
576:            }
577:
578:            public void testNonStaticAccessTest10() throws Exception {
579:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
580:                        "test1", false, null);
581:                StringBuffer buf = new StringBuffer();
582:                buf.append("package test1;\n");
583:                buf.append("public class E1 {\n");
584:                buf.append("    public static void foo() {};\n");
585:                buf.append("}\n");
586:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
587:                        null);
588:
589:                buf = new StringBuffer();
590:                buf.append("package test1;\n");
591:                buf.append("public class E2 {\n");
592:                buf.append("    private static String E1= \"\";\n");
593:                buf.append("    public void foo() {\n");
594:                buf.append("        test1.E1 e1= new test1.E1();\n");
595:                buf.append("        e1.foo();\n");
596:                buf.append("    }\n");
597:                buf.append("}\n");
598:                ICompilationUnit cu = pack1.createCompilationUnit("E2.java",
599:                        buf.toString(), false, null);
600:
601:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
602:                refactoring.addCompilationUnit(cu);
603:
604:                ICleanUp cleanUp = createCleanUp();
605:                refactoring.addCleanUp(cleanUp);
606:
607:                buf = new StringBuffer();
608:                buf.append("package test1;\n");
609:                buf.append("public class E2 {\n");
610:                buf.append("    private static String E1= \"\";\n");
611:                buf.append("    public void foo() {\n");
612:                buf.append("        test1.E1 e1= new test1.E1();\n");
613:                buf.append("        test1.E1.foo();\n");
614:                buf.append("    }\n");
615:                buf.append("}\n");
616:                String expected1 = buf.toString();
617:
618:                assertRefactoringResultAsExpected(refactoring,
619:                        new String[] { expected1 });
620:            }
621:
622:            public void testNonStaticAccessTest11() throws Exception {
623:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
624:                        "test1", false, null);
625:                StringBuffer buf = new StringBuffer();
626:                buf.append("package test1;\n");
627:                buf.append("public class E1<T> {\n");
628:                buf.append("    public static void foo() {};\n");
629:                buf.append("}\n");
630:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
631:                        null);
632:
633:                buf = new StringBuffer();
634:                buf.append("package test1;\n");
635:                buf.append("public class E2 {\n");
636:                buf.append("    private static String E1= \"\";\n");
637:                buf.append("    public void foo() {\n");
638:                buf
639:                        .append("        test1.E1<String> e1= new test1.E1<String>();\n");
640:                buf.append("        e1.foo();\n");
641:                buf.append("    }\n");
642:                buf.append("}\n");
643:                ICompilationUnit cu = pack1.createCompilationUnit("E2.java",
644:                        buf.toString(), false, null);
645:
646:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
647:                refactoring.addCompilationUnit(cu);
648:
649:                ICleanUp cleanUp = createCleanUp();
650:                refactoring.addCleanUp(cleanUp);
651:
652:                buf = new StringBuffer();
653:                buf.append("package test1;\n");
654:                buf.append("public class E2 {\n");
655:                buf.append("    private static String E1= \"\";\n");
656:                buf.append("    public void foo() {\n");
657:                buf
658:                        .append("        test1.E1<String> e1= new test1.E1<String>();\n");
659:                buf.append("        test1.E1.foo();\n");
660:                buf.append("    }\n");
661:                buf.append("}\n");
662:                String expected1 = buf.toString();
663:
664:                assertRefactoringResultAsExpected(refactoring,
665:                        new String[] { expected1 });
666:            }
667:
668:            public void testNonStaticAccessTest12() throws Exception {
669:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
670:                        "test1", false, null);
671:                StringBuffer buf = new StringBuffer();
672:                buf.append("package test1;\n");
673:                buf.append("public class E1<G> {\n");
674:                buf.append("    public static int I;\n");
675:                buf.append("}\n");
676:                pack1.createCompilationUnit("E1.java", buf.toString(), false,
677:                        null);
678:
679:                buf = new StringBuffer();
680:                buf.append("package test1;\n");
681:                buf.append("import test2.E1;\n");
682:                buf.append("public class E2 {\n");
683:                buf.append("    public void foo() {\n");
684:                buf
685:                        .append("        test1.E1<E1<test1.E1<E2>>> e1= new test1.E1<E1<test1.E1<E2>>>();\n");
686:                buf.append("        e1.I= 10;\n");
687:                buf.append("        E1<E1<E2>> f=null;\n");
688:                buf.append("    }\n");
689:                buf.append("}\n");
690:                ICompilationUnit cu = pack1.createCompilationUnit("E2.java",
691:                        buf.toString(), false, null);
692:
693:                IPackageFragment pack2 = fSourceFolder.createPackageFragment(
694:                        "test2", false, null);
695:                buf = new StringBuffer();
696:                buf.append("package test2;\n");
697:                buf.append("public class E1<G>  {}\n");
698:                pack2.createCompilationUnit("E1.java", buf.toString(), false,
699:                        null);
700:
701:                CleanUpRefactoring refactoring = new CleanUpRefactoring();
702:                refactoring.addCompilationUnit(cu);
703:
704:                ICleanUp cleanUp = createCleanUp();
705:                refactoring.addCleanUp(cleanUp);
706:
707:                buf = new StringBuffer();
708:                buf.append("package test1;\n");
709:                buf.append("import test2.E1;\n");
710:                buf.append("public class E2 {\n");
711:                buf.append("    public void foo() {\n");
712:                buf
713:                        .append("        test1.E1<E1<test1.E1<E2>>> e1= new test1.E1<E1<test1.E1<E2>>>();\n");
714:                buf.append("        test1.E1.I= 10;\n");
715:                buf.append("        E1<E1<E2>> f=null;\n");
716:                buf.append("    }\n");
717:                buf.append("}\n");
718:                String expected1 = buf.toString();
719:
720:                assertRefactoringResultAsExpected(refactoring,
721:                        new String[] { expected1 });
722:            }
723:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.