diff options
author | Lucas Bullen | 2017-07-12 18:08:58 +0000 |
---|---|---|
committer | Lucas Bullen | 2017-07-20 14:41:35 +0000 |
commit | 798ba99e71d97835741ac91d068afc2130c66bcc (patch) | |
tree | d69af12998dbb3279b999d63c71c05432c0acc45 /org.eclipse.ui.genericeditor.tests | |
parent | 8773dabab911ce83b5a7a4d9a5661e932a3fea4d (diff) | |
download | eclipse.platform.text-798ba99e71d97835741ac91d068afc2130c66bcc.tar.gz eclipse.platform.text-798ba99e71d97835741ac91d068afc2130c66bcc.tar.xz eclipse.platform.text-798ba99e71d97835741ac91d068afc2130c66bcc.zip |
Bug 508829 - [Generic Editor] provide a way to customize reconcilerI20170723-2000I20170722-2000I20170722-0045I20170721-2000I20170720-2000
- Extension point for reconcilers added
- Example of use with folding
Change-Id: I966e0fa4e5711fb85aa792361184fd7ddbcf0620
Signed-off-by: Lucas Bullen <lbullen@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
5 files changed, 165 insertions, 2 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml index 4f199ed08d8..a6b4124536f 100644 --- a/org.eclipse.ui.genericeditor.tests/plugin.xml +++ b/org.eclipse.ui.genericeditor.tests/plugin.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <!-- ====================================================================== --> -<!-- Copyright (c) 2016 Red Hat Inc. and others. --> +<!-- Copyright (c) 2016, 2017 Red Hat Inc. and others. --> <!-- All rights reserved. This program and the accompanying materials --> <!-- are made available under the terms of the Eclipse Public License v1.0 --> <!-- which accompanies this distribution, and is available at --> @@ -9,6 +9,7 @@ <!-- --> <!-- Contributors: --> <!-- Sopot Cela & Mickael Istria (Red Hat Inc). -initial implementation --> +<!-- Lucas Bullen (Red Hat Inc.) - Bug 508829 custom reconciler support --> <!-- ====================================================================== --> <plugin> <extension @@ -29,6 +30,13 @@ contentType="org.eclipse.ui.genericeditor.tests.content-type"> </hoverProvider> </extension> + <extension + point="org.eclipse.ui.genericeditor.reconcilers"> + <reconciler + class="org.eclipse.ui.genericeditor.tests.contributions.TheReconciler" + contentType="org.eclipse.ui.genericeditor.tests.content-type"> + </reconciler> + </extension> <extension point="org.eclipse.ui.genericeditor.presentationReconcilers"> <presentationReconciler diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java index 96361db40d1..bf987dcca97 100644 --- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java @@ -20,7 +20,8 @@ import org.junit.runners.Suite.SuiteClasses; StylingTest.class, HoverTest.class, EditorTest.class, - AutoEditTest.class + AutoEditTest.class, + ReconcilerTest.class }) public class GenericEditorTestSuite { // see @SuiteClasses diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java new file mode 100644 index 00000000000..294ba6831ac --- /dev/null +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial implementation + *******************************************************************************/ +package org.eclipse.ui.genericeditor.tests; + +import java.io.ByteArrayInputStream; + +import org.junit.Assert; +import org.junit.Test; + +import org.eclipse.swt.widgets.Display; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.tests.util.DisplayHelper; + +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor; +import org.eclipse.ui.part.FileEditorInput; + +import org.eclipse.ui.texteditor.IDocumentProvider; + +public class ReconcilerTest extends AbstratGenericEditorTest { + + protected ExtensionBasedTextEditor secondEditor; + + @Test + public void testReconciler() throws Exception { + performTestOnEditor(); + } + + @Test + public void testMultipleEditors() throws Exception { + IProject secondProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis()); + secondProject.create(null); + secondProject.open(null); + IFile secondFile = secondProject.getFile("foo.txt"); + secondFile.create(new ByteArrayInputStream("bar 'bar'".getBytes()), true, null); + secondEditor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage().openEditor(new FileEditorInput(secondFile), "org.eclipse.ui.genericeditor.GenericEditor"); + performTestOnEditor(); + } + + private void performTestOnEditor() throws Exception { + IDocumentProvider dp = editor.getDocumentProvider(); + IDocument doc = dp.getDocument(editor.getEditorInput()); + + doc.set("foo"); + + new DisplayHelper() { + @Override + protected boolean condition() { + try { + return !doc.get(0, doc.getLineLength(0)).contains("foo"); + } catch (BadLocationException e) { + return false; + } + } + }.waitForCondition(Display.getDefault().getActiveShell().getDisplay(), 2000); + Assert.assertTrue("file was not affected by reconciler", doc.get().contains("BAR")); + } + +} diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ReconcilerStrategy.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ReconcilerStrategy.java new file mode 100644 index 00000000000..dcb531448a6 --- /dev/null +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ReconcilerStrategy.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial implementation + *******************************************************************************/ +package org.eclipse.ui.genericeditor.tests.contributions; + +import org.eclipse.swt.widgets.Display; + +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.reconciler.DirtyRegion; +import org.eclipse.jface.text.reconciler.IReconcilingStrategy; +import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension; + +public class ReconcilerStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension{ + + IDocument document; + static final String SEARCH_TERM = "foo"; + static final String REPLACEMENT = "BAR"; + + @Override + public void setDocument(IDocument document) { + this.document = document; + } + + @Override + public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { + initialReconcile(); + } + + @Override + public void reconcile(IRegion partition) { + initialReconcile(); + } + + @Override + public void setProgressMonitor(IProgressMonitor monitor) { + // no progress monitor in use + } + + @Override + public void initialReconcile() { + String doc = document.get(); + if(doc.contains(SEARCH_TERM)) { + Display.getDefault().asyncExec(() -> { + document.set(document.get().replaceAll(SEARCH_TERM, REPLACEMENT)); + }); + } + } + +} diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheReconciler.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheReconciler.java new file mode 100644 index 00000000000..1e051433f7f --- /dev/null +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheReconciler.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Lucas Bullen (Red Hat Inc.) - initial implementation + *******************************************************************************/ +package org.eclipse.ui.genericeditor.tests.contributions; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.reconciler.Reconciler; + +public class TheReconciler extends Reconciler{ + public TheReconciler() { + ReconcilerStrategy signStrategy = new ReconcilerStrategy(); + this.setReconcilingStrategy(signStrategy, IDocument.DEFAULT_CONTENT_TYPE); + } +} |