Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipse-dev] Using refactoring code outside of eclipse


You can't get an NPE on said line because that's a call to a static method.

Such questions should be posted to the newsgroups (jdt in this case).
From http://eclipse.org/mail/index.html:
Technical questions and discussions about using eclipse and eclipse-based tools, and developing plug-in tools should be posted to the newsgroups. Mailing lists at eclipse.org are intended for use by developers actually working on or otherwise contributing to day-to-day development.

Markus



Mike Hogan <MHogan@xxxxxxxxxxxxxxxx>
Sent by: eclipse-dev-admin@xxxxxxxxxxx

2004-10-07 19:20

Please respond to
eclipse-dev@xxxxxxxxxxx

To
eclipse-dev@xxxxxxxxxxx
cc
Subject
[eclipse-dev] Using refactoring code outside of eclipse






Hi,


I am trying to get this code working:



import junit.framework.TestCase;

import org.eclipse.jdt.testplugin.JavaProjectHelper;

import org.eclipse.jdt.internal.ui.JavaPlugin;

import org.eclipse.jdt.core.IPackageFragmentRoot;

import org.eclipse.jdt.core.IJavaProject;

import org.eclipse.jdt.core.IPackageFragment;

import org.eclipse.jdt.core.ICompilationUnit;


public class SpikeTestCase extends TestCase {

   private IJavaProject javaTestProject;

   private IPackageFragmentRoot root;

   private static final String CONTAINER = "";

   private IPackageFragment packageP;


   protected void setUp() throws Exception {

               super.setUp();

               JavaProjectHelper.setAutoBuilding(false);

               if (JavaPlugin.getActivePage() != null)

                       JavaPlugin.getActivePage().close();

               javaTestProject= JavaProjectHelper.createJavaProject("TestProject"+System.currentTimeMillis(), "bin");

               JavaProjectHelper.addRTJar(javaTestProject);

               root= JavaProjectHelper.addSourceContainer(javaTestProject, CONTAINER);

               packageP= root.createPackageFragment("p", true, null);

       }


   public void testSimpleRefactoring() throws Exception {

       ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");

   }


   protected ICompilationUnit createCUfromTestFile(IPackageFragment pack, String contents) throws Exception {

               return createCU(pack, "mike" + ".java", contents);

       }


   public static ICompilationUnit createCU(IPackageFragment pack, String name, String contents) throws Exception {

               if (pack.getCompilationUnit(name).exists())

                       return pack.getCompilationUnit(name);

               ICompilationUnit cu= pack.createCompilationUnit(name, contents, true, null);

               cu.save(null, true);

               return cu;

       }


   protected IPackageFragment getPackageP() {

           return packageP;

       }


}


I get a NullPointerException on the second line of the setUp method, the line that reads "JavaProjectHelper.setAutoBuilding(false);"


Does anybody have any idea what I need to do to get this to work?


Thanks,

Mike


Back to the top