|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.test.refactoring; import java.io.*; import java.io.File; import org.netbeans.api.mdr.MDRepository; import org.netbeans.jmi.javamodel.JavaClass; import org.netbeans.jmi.javamodel.Type; import org.netbeans.jmi.javamodel.TypeClass; import org.netbeans.jmi.javamodel.UnresolvedClass; import org.netbeans.modules.javacore.internalapi.JavaMetamodel; import org.netbeans.modules.refactoring.classpath.RefactoringClassPathImplementation; import org.netbeans.spi.java.classpath.ClassPathFactory; public class Utility { public static void beginTrans(boolean writeAccess) { getDefaultRepository().beginTrans(writeAccess); } public static void endTrans(boolean rollback) { getDefaultRepository().endTrans(rollback); } public static void endTrans() { getDefaultRepository().endTrans(); } public static MDRepository getDefaultRepository() { return JavaMetamodel.getDefaultRepository(); } public static void prepareTest() { beginTrans(true); //class path JavaMetamodel.getManager().setClassPath(ClassPathFactory.createClassPath(RefactoringClassPathImplementation.getDefault())); } public static void finishTest() { endTrans(false); } public static File getFile(File classPathDataDir, String fileName) { return new File(classPathDataDir, fileName); } /** * must be called in a transaction */ public static JavaClass findClass(String s) { JavaClass result; int i = 20; do { result = (JavaClass) JavaMetamodel.getManager().getDefaultExtent().getType().resolve(s); if (result instanceof UnresolvedClass) { try { Thread.sleep(1000); } catch (InterruptedException e) { endTrans(); e.printStackTrace(); return null; } } i--; } while ((result instanceof UnresolvedClass) && i > 0); if (result instanceof UnresolvedClass) { throw new IllegalStateException("Class " + s + " not found."); } return result; } /** * must be called in a transaction */ public static Type findType(String s, TypeClass typeProxy) { Type result; int i = 20; do { result = typeProxy.resolve(s); if (result instanceof UnresolvedClass) { try { Thread.sleep(1000); } catch (InterruptedException e) { endTrans(); e.printStackTrace(); return null; } } i--; } while ((result instanceof UnresolvedClass) && i > 0); if (result instanceof UnresolvedClass) { throw new IllegalStateException("Type " + s + " not found."); } return result; } public static void copyFile(File src, File trg) throws Exception { BufferedInputStream bis=new BufferedInputStream(new FileInputStream(src)); BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(trg)); byte[] buffer=new byte[1024]; int length=1; while (length > 0) { length=bis.read(buffer); if (length <= 0) { break; } bos.write(buffer, 0, length); } bis.close(); bos.close(); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.