KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > refactoring > TestUtility


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.apisupport.refactoring;
20
21 import java.io.File JavaDoc;
22 import org.netbeans.api.mdr.MDRepository;
23 import org.netbeans.junit.NbTestCase;
24 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
25 import org.netbeans.jmi.javamodel.JavaModelPackage;
26 import org.netbeans.jmi.javamodel.JavaClass;
27 import org.netbeans.jmi.javamodel.UnresolvedClass;
28 import org.openide.filesystems.FileStateInvalidException;
29 import org.openide.filesystems.FileSystem;
30 import org.openide.filesystems.Repository;
31
32
33 public class TestUtility {
34
35     public static void beginTrans(boolean writeAccess) {
36         getDefaultRepository().beginTrans(writeAccess);
37     }
38         
39     public static void endTrans(boolean rollback) {
40         getDefaultRepository().endTrans(rollback);
41     }
42         
43     public static void endTrans() {
44         getDefaultRepository().endTrans();
45     }
46         
47     public static MDRepository getDefaultRepository() {
48         return JavaMetamodel.getDefaultRepository();
49     }
50         
51     public static File JavaDoc getFile(File JavaDoc dataDir,String JavaDoc projectName, String JavaDoc fileName) throws FileStateInvalidException {
52         String JavaDoc result = dataDir.getAbsolutePath() +"/" + projectName + "/" + fileName;
53         System.out.println("looking for file: " + result);
54         return new File JavaDoc(result);
55     }
56
57     public static JavaModelPackage getJavaModelPackage(String JavaDoc pattern) {
58         throw new UnsupportedOperationException JavaDoc("Method is no longer supported. " +
59             "Rewrite your test to new project infrastructure!");
60     }
61     
62     public static FileSystem findFileSystem(String JavaDoc pattern) {
63         throw new UnsupportedOperationException JavaDoc("Method is no longer supported. " +
64             "Rewrite your test to new project infrastructure!");
65     }
66     
67     public static JavaClass findClass(String JavaDoc s) {
68         JavaClass result;
69         int i = 20;
70         do {
71             result = (JavaClass) JavaMetamodel.getManager().getDefaultExtent().getType().resolve(s);
72             if (result instanceof UnresolvedClass) {
73                 try {
74                     Thread.sleep(1000);
75                 } catch (InterruptedException JavaDoc e) {
76                     e.printStackTrace();
77                     return null;
78                 }
79             }
80             i--;
81         } while ((result instanceof UnresolvedClass) && i > 0);
82         if (result instanceof UnresolvedClass) {
83             throw new IllegalStateException JavaDoc("Class " + s + " not found.");
84         }
85         return result;
86     }
87 }
88
Popular Tags