Bug 8221 NPE in refactoring preview page (Pull up)
1. select TestCase.setUp and invoke 'Pull Up' 2. In the delete tree check all elements, press next 3. Open the 'VectorTest.java' tree and select the node 'Delete....' -> 4 org.eclipse.core.runtime 0 java.lang.NullPointerException java.lang.NullPointerException at org.eclipse.jdt.internal.ui.refactoring.ComparePreviewer$CompareInput.<init> (ComparePreviewer.java:42) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.getCompareInput (PreviewWizardPage.java:211) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.getPreviewer (PreviewWizardPage.java:254) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.showPreview (PreviewWizardPage.java:374) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.access$1 (PreviewWizardPage.java:372) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage$2.selectionChanged (PreviewWizardPage.java:363) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java (Compiled Code)) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:999) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:466) at org.eclipse.jface.viewers.CheckboxTreeViewer.handleSelect (CheckboxTreeViewer.java:233) at org.eclipse.jface.viewers.AbstractTreeViewer$1.widgetSelected (AbstractTreeViewer.java:624) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java (Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java (Compiled Code)) at org.eclipse.jface.window.Window.runEventLoop(Window.java(Compiled Code)) at org.eclipse.jface.window.Window.open(Window.java:523) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate (RefactoringStarter.java:83) at org.eclipse.jdt.internal.ui.refactoring.actions.OpenRefactoringWizardAction.run (OpenRefactoringWizardAction.java:65) at org.eclipse.jface.action.Action.runWithEvent(Action.java:452) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.run(Workbench.java:827) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:878) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:321) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:151) at org.eclipse.core.launcher.Main.run(Main.java:502) at org.eclipse.core.launcher.UIMain.main(UIMain.java:52)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/reorg/PasteInCompilationUnitEdit.java
return new PasteInCompilationUnitEdit(fSource, fType, fCu);
	}
	/* non Java-doc
	 * @see TextEdit#connect
	 */
	public void connect(TextBufferEditor editor) throws CoreException {	
		setText(fSource);
		setTextRange(new TextRange(computeOffset(), 0));	
	}
	
	private int computeOffset() throws JavaModelException{
		switch(fType){
			case IJavaElement.PACKAGE_DECLARATION:
				return computeOffsetForPackageDeclaration();	
			case IJavaElement.IMPORT_CONTAINER:
				return computeOffsetForImportContainer();
			case IJavaElement.IMPORT_DECLARATION:
				return computeOffsetForImportContainer();
			case IJavaElement.TYPE:
				return computeOffsetForType();
			default:
				Assert.isTrue(false);
				return -1; 
		}
	}
	
	private int computeOffsetForPackageDeclaration() throws JavaModelException{
		
		IPackageDeclaration[] declarations= fCu.getPackageDeclarations();
		if (declarations.length == 0)