package bndtools.editor.pages;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.texteditor.ITextEditor;

public class ApplyCompletionProposalAction extends Action {

    private final ICompletionProposal proposal;
    private final ITextEditor textEditor;
    private final FormEditor mainEditor;
    private final String switchToPageId;

    public ApplyCompletionProposalAction(ICompletionProposal proposal, ITextEditor textEditor, FormEditor mainEditor, String switchToPageId) {
        this.proposal = proposal;
        this.textEditor = textEditor;
        this.mainEditor = mainEditor;
        this.switchToPageId = switchToPageId;
    }

    @Override
    public String getText() {
        return proposal.getDisplayString();
    }

    @Override
    public void run() {
        if (mainEditor != null && switchToPageId != null)
            mainEditor.setActivePage(switchToPageId);

        IDocument document = textEditor.getDocumentProvider().getDocument(mainEditor.getEditorInput());
        proposal.apply(document);

        Point selection = proposal.getSelection(document);
        if (selection != null)
            textEditor.selectAndReveal(selection.x, 0);
    }

}

@@ -985,18 +985,94 @@
         
-if
+assert (proposal != null);%0A        assert (textEditor != null);%0A        assert
  (mainEd
@@ -1087,12 +1087,27 @@
 null
- && 
+);%0A        assert (
 swit
@@ -1117,37 +1117,35 @@
 oPageId != null)
-%0A    
+;%0A%0A
         mainEdit
@@ -1474,7 +1474,5 @@
   %7D%0A
-%0A%7D%0A
+%7D

Add asserts