1 19 package org.netbeans.modules.apisupport.refactoring; 20 21 import java.io.File ; 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 getFile(File dataDir,String projectName, String fileName) throws FileStateInvalidException { 52 String result = dataDir.getAbsolutePath() +"/" + projectName + "/" + fileName; 53 System.out.println("looking for file: " + result); 54 return new File (result); 55 } 56 57 public static JavaModelPackage getJavaModelPackage(String pattern) { 58 throw new UnsupportedOperationException ("Method is no longer supported. " + 59 "Rewrite your test to new project infrastructure!"); 60 } 61 62 public static FileSystem findFileSystem(String pattern) { 63 throw new UnsupportedOperationException ("Method is no longer supported. " + 64 "Rewrite your test to new project infrastructure!"); 65 } 66 67 public static JavaClass findClass(String 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 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 ("Class " + s + " not found."); 84 } 85 return result; 86 } 87 } 88 | Popular Tags |