Search in sources :

Example 6 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class HoverTest method triggerCompletionAndRetrieveInformationControlManager.

private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() {
    this.editor.selectAndReveal(2, 0);
    final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == 2;
        }
    }.waitForCondition(editorTextWidget.getDisplay(), 1000);
    // sending event to trigger hover computation
    editorTextWidget.getShell().forceActive();
    editorTextWidget.getShell().setActive();
    editorTextWidget.getShell().setFocus();
    editorTextWidget.getShell().getDisplay().wake();
    Event hoverEvent = new Event();
    hoverEvent.widget = editorTextWidget;
    hoverEvent.type = SWT.MouseHover;
    hoverEvent.x = editorTextWidget.getClientArea().x + 5;
    hoverEvent.y = editorTextWidget.getClientArea().y + 5;
    hoverEvent.display = editorTextWidget.getDisplay();
    hoverEvent.doit = true;
    editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y));
    editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
    // Events need to be processed for hover listener to work correctly
    DisplayHelper.sleep(editorTextWidget.getDisplay(), 1000);
    // retrieving hover content
    ITextViewer viewer = (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
    AbstractInformationControlManager textHoverManager = (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager");
    return textHoverManager;
}
Also used : AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) AbstractInformationControlManager(org.eclipse.jface.text.AbstractInformationControlManager) Event(org.eclipse.swt.widgets.Event) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) Accessor(org.eclipse.text.tests.Accessor) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 7 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class AbstractReconcilerTest method setUp.

@Before
public void setUp() {
    fBarrier = new Barrier();
    fCallLog = Collections.synchronizedList(new ArrayList<String>());
    fReconciler = new AbstractReconciler() {

        @Override
        protected void initialProcess() {
            fCallLog.add("initialProcess");
            fBarrier.await();
        }

        @Override
        protected void process(DirtyRegion dirtyRegion) {
            fCallLog.add("process");
            fBarrier.await();
        }

        @Override
        protected void reconcilerDocumentChanged(IDocument newDocument) {
            fCallLog.add("reconcilerDocumentChanged");
        }

        @Override
        protected void aboutToBeReconciled() {
            fCallLog.add("aboutToBeReconciled");
        }

        @Override
        protected void reconcilerReset() {
            fCallLog.add("reconcilerReset");
        }

        @Override
        public IReconcilingStrategy getReconcilingStrategy(String contentType) {
            return null;
        }
    };
    fReconciler.setIsIncrementalReconciler(false);
    // make tests run faster
    fReconciler.setDelay(50);
    fProgressMonitor = new NullProgressMonitor();
    fReconciler.setProgressMonitor(fProgressMonitor);
    fViewer = new TestTextViewer();
    fReconciler.install(fViewer);
    fAccessor = new Accessor(fReconciler, AbstractReconciler.class);
    Object object = fAccessor.get("fThread");
    fAccessor = new Accessor(object, object.getClass());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) TestTextViewer(org.eclipse.jface.text.tests.TestTextViewer) ArrayList(java.util.ArrayList) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) Accessor(org.eclipse.text.tests.Accessor) IDocument(org.eclipse.jface.text.IDocument) AbstractReconciler(org.eclipse.jface.text.reconciler.AbstractReconciler) Before(org.junit.Before)

Example 8 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class HippieCompletionTest method testCompletionState.

/*
	 * Getting completions lazily
	 */
@Test
public void testCompletionState() throws Exception {
    ArrayList<String> list = new ArrayList<>();
    Accessor state = null;
    try {
        state = createAccessor(list.iterator(), 0);
        fail("Having no items is not valid (at least the empty completion must be there)");
    } catch (AssertionFailedException ex) {
    }
    list.add("");
    state = createAccessor(list.iterator(), 0);
    assertTrue(state.getBoolean("hasOnly1EmptySuggestion"));
    for (int i = 0; i < 3; i++) {
        assertEquals("", next(state));
    }
    list.add("");
    state = createAccessor(list.iterator(), 0);
    assertTrue(state.getBoolean("hasOnly1EmptySuggestion"));
    for (int i = 0; i < 3; i++) {
        assertEquals("", next(state));
    }
    // only empty and aaaa
    list.add(0, "aaaa");
    state = createAccessor(list.iterator(), 0);
    assertFalse(state.getBoolean("hasOnly1EmptySuggestion"));
    for (int i = 0; i < 3; i++) {
        assertEquals("aaaa", next(state));
        assertEquals("", next(state));
    }
    // empty, aaaa and bbbb
    list.add(1, "bbbb");
    state = createAccessor(list.iterator(), 0);
    assertFalse(state.getBoolean("hasOnly1EmptySuggestion"));
    for (int i = 0; i < 3; i++) {
        assertEquals("aaaa", next(state));
        assertEquals("bbbb", next(state));
        assertEquals("", next(state));
    }
    // empty, aaaa and 2 from 'bbbb' (should make unique)
    list.add(2, "bbbb");
    state = createAccessor(list.iterator(), 0);
    assertFalse(state.getBoolean("hasOnly1EmptySuggestion"));
    for (int i = 0; i < 3; i++) {
        assertEquals("aaaa", next(state));
        assertEquals("bbbb", next(state));
        assertEquals("", next(state));
    }
}
Also used : ArrayList(java.util.ArrayList) Accessor(org.eclipse.text.tests.Accessor) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) Test(org.junit.Test)

Example 9 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class HoverTest method getHoverShell.

private Shell getHoverShell(AbstractInformationControlManager manager) {
    AbstractInformationControl[] control = { null };
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            control[0] = (AbstractInformationControl) new Accessor(manager, AbstractInformationControlManager.class).get("fInformationControl");
            return control[0] != null;
        }
    }.waitForCondition(this.editor.getSite().getShell().getDisplay(), 5000);
    if (control[0] == null) {
        ScreenshotTest.takeScreenshot(getClass(), testName.getMethodName(), System.out);
        fail();
    }
    Shell shell = (Shell) new Accessor(control[0], AbstractInformationControl.class).get("fShell");
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            return shell.isVisible();
        }
    }.waitForCondition(this.editor.getSite().getShell().getDisplay(), 2000);
    assertTrue(shell.isVisible());
    return shell;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) Accessor(org.eclipse.text.tests.Accessor)

Example 10 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class FindReplaceDialogTest method openFindReplaceDialog.

private void openFindReplaceDialog() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    fFindReplaceDialog = new Accessor("org.eclipse.ui.texteditor.FindReplaceDialog", getClass().getClassLoader(), new Object[] { shell });
    fFindReplaceDialog.invoke("create", null);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Accessor(org.eclipse.text.tests.Accessor)

Aggregations

Accessor (org.eclipse.text.tests.Accessor)11 Test (org.junit.Test)5 Shell (org.eclipse.swt.widgets.Shell)4 IWorkbench (org.eclipse.ui.IWorkbench)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 PartInitException (org.eclipse.ui.PartInitException)4 CoreException (org.eclipse.core.runtime.CoreException)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)3 StyledText (org.eclipse.swt.custom.StyledText)3 DefaultEncodingSupport (org.eclipse.ui.editors.text.DefaultEncodingSupport)3 IEncodingSupport (org.eclipse.ui.editors.text.IEncodingSupport)3 TextEditor (org.eclipse.ui.editors.text.TextEditor)3 StatusTextEditor (org.eclipse.ui.texteditor.StatusTextEditor)3 ArrayList (java.util.ArrayList)2 AbstractInformationControl (org.eclipse.jface.text.AbstractInformationControl)2 IDocument (org.eclipse.jface.text.IDocument)2 DisplayHelper (org.eclipse.jface.text.tests.util.DisplayHelper)2 Control (org.eclipse.swt.widgets.Control)2 ResourceBundle (java.util.ResourceBundle)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1