title: Programmatically get java proposals for eclipse bundle
body: <p>I tried various combinations for my problem but of no use.  </p>
  
  <p><strong>Problem</strong></p>
  
  <p>I am developing one eclipse osgi bundle to correct java source code automatically.  I am able to get java project object and a class object inside it which I want to correct.  Every time I try to collect java code proposals as I put one test file which can be corrected (like duplicate imports)</p>
  
  <p>I always get errors similar to below</p>
  
  <pre><code>java.lang.NullPointerException
      at org.eclipse.jdt.internal.ui.JavaPlugin.getImageDescriptorRegistry(JavaPlugin.java:335)
      at org.eclipse.jdt.ui.text.java.CompletionProposalCollector.&lt;init&gt;(CompletionProposalCollector.java:103)
      at org.eclipse.jdt.ui.text.java.CompletionProposalCollector.&lt;init&gt;(CompletionProposalCollector.java:157)
  </code></pre>
  
  <p>Please tell me what I am doing wrong.  Here is my code snippet:</p>
  
  <pre><code>....
  CompletionProposalCollector collectorPrjTemp= new CompletionProposalCollector(javaProject); // this line throws error
  IJavaCompletionProposal[] prjProposals = collectorPrjTemp.getJavaCompletionProposals();
  System.out.println("prjProposals == "+prjProposals.length);
  ....
  </code></pre>
  
  <p><strong>Edit on 28-Jul</strong></p>
  
  <p>Now when I included dependency of org.eclipse.jdt.ui above NullPointer error goes away.  But now receiving below error</p>
  
  <p>!ENTRY org.eclipse.jdt.ui 4 2 2015-07-28 13:07:37.926
  !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ui".
  !STACK 0</p>
  
  <pre><code>java.lang.IllegalStateException: Workbench has not been created yet.
      at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:93)
      at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.install(ASTProvider.java:236)
      at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.&lt;init&gt;(ASTProvider.java:227)
      at org.eclipse.jdt.internal.ui.JavaPlugin.getASTProvider(JavaPlugin.java:741)
      at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:128)
      at org.eclipse.jdt.internal.ui.text.correction.AssistContext.getASTRoot(AssistContext.java:119)
      at org.eclipse.jdt.internal.ui.text.correction.ReorgCorrectionsSubProcessor.removeImportStatementProposals(ReorgCorrectionsSubProcessor.java:210)
      at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.process(QuickFixProcessor.java:337)
      at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.getCorrections(QuickFixProcessor.java:316)
      at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor$SafeCorrectionCollector.safeRun(JavaCorrectionProcessor.java:378)
      at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor$SafeCorrectionProcessorAccess.run(JavaCorrectionProcessor.java:339)
      at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
      at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor$SafeCorrectionProcessorAccess.process(JavaCorrectionProcessor.java:335)
      at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.collectCorrections(JavaCorrectionProcessor.java:468)
  </code></pre>
  
  <p><strong>Update - 29-Jul</strong></p>
  
  <p>Now I am trying to create workbench object via command</p>
  
  <pre><code>    WorkbenchAdvisor advisor=new WorkbenchAdvisor(){
          public String getInitialWindowPerspectiveId(){
            return "org.eclipse.rap.junit.runtime.emptyPerspective";
          }
        };
      //Display display = Display.getCurrent (); // did not worked, gives null
      //Display display = Display.getDefault (); // did not worked, gives null
      Display display = PlatformUI.getDisplay (); // did not worked, gives null
      PlatformUI.createAndRunWorkbench(display, advisor);
  </code></pre>
  
  <p>When I tried below code</p>
  
  <pre><code>Display display = new Display ();
  </code></pre>
  
  <p>then got below error:</p>
  
  <pre><code>No context available outside of the request processing
  </code></pre>
  
  <p>Please read comments between myself and greg for my tries.  Any help/clue will be appreciated.</p>