|
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.jmi.javamodel.codegen; import java.io.File; import java.io.IOException; import javax.swing.text.StyledDocument; import org.netbeans.api.mdr.MDRepository; import org.netbeans.jmi.javamodel.*; import org.netbeans.modules.javacore.internalapi.JavaMetamodel; import org.openide.LifecycleManager; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileSystem; import org.openide.loaders.DataObject; 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 File getFile(File dataDir, String fileName) throws FileStateInvalidException { String result = dataDir.getAbsolutePath() + "/projects/default/src/" + fileName; System.out.println("looking for file: " + result); return new File(result); } public static JavaModelPackage getJavaModelPackage(String pattern) { throw new UnsupportedOperationException("Method is no longer supported. " + "Rewrite your test to new project infrastructure!"); } public static FileSystem findFileSystem(String pattern) { throw new UnsupportedOperationException("Method is no longer supported. " + "Rewrite your test to new project infrastructure!"); } 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) { e.printStackTrace(); return null; } } i--; } while ((result instanceof UnresolvedClass) && i > 0); if (result instanceof UnresolvedClass) { throw new IllegalStateException("Class " + s + " not found."); } return result; } public static StyledDocument getDocument(Element element) { try { Resource res = element.getResource(); DataObject dob = JavaMetamodel.getManager().getDataObject(res); EditorCookie ec = (EditorCookie) dob.getCookie(EditorCookie.class); return ec.openDocument(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } public static void saveAll() { LifecycleManager.getDefault().saveAll(); } public static void addModified(Element el) { JavaMetamodel.getManager().addModified(JavaMetamodel.getManager().getDataObject(el.getResource())); } } |
... 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.