Skip to content
Commits on Source (3)
eclipse-platform-text (4.11-1) unstable; urgency=medium
* New upstream release
-- Emmanuel Bourg <ebourg@apache.org> Thu, 11 Jul 2019 10:40:14 +0200
eclipse-platform-text (4.10-1) unstable; urgency=medium
* New upstream release
......
......@@ -14,7 +14,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.core</groupId>
......
......@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.filebuffers; singleton:=true
Bundle-Version: 3.6.400.qualifier
Bundle-Version: 3.6.500.qualifier
Bundle-Activator: org.eclipse.core.internal.filebuffers.FileBuffersPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
......
......@@ -14,10 +14,10 @@
<parent>
<artifactId>eclipse.platform.text</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.core.filebuffers</artifactId>
<version>3.6.400-SNAPSHOT</version>
<version>3.6.500-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
......@@ -33,10 +33,11 @@ import org.eclipse.jface.text.IDocument;
* In order to provide backward compatibility for clients of <code>IDocumentSetupParticipant</code>, extension
* interfaces are used to provide a means of evolution. The following extension interfaces
* exist:
* </p>
* <ul>
* <li> {@link IDocumentSetupParticipantExtension} since version 3.4 introducing the
* concept of rewrite sessions. .</li>
* </ul></p>
* </ul>
*
* @since 3.0
* @see org.eclipse.jface.text.IDocumentExtension3
......
......@@ -9,9 +9,9 @@
<h2>Package Specification</h2>
<p>File buffers represent a file that is being edited. Text file buffers are
specific for text files. They represent the content of a text file in form of
an <tt>IDocument</tt> and and associated <tt>IAnnotationModel</tt>. File buffers are managed by
a file buffer manager. The <tt>org.eclipse.core.filebuffers</tt> plug-in provides a default
file buffer manager that can be obtained by calling <tt>FileBuffers.getTextFileBufferManager()</tt>.
The file buffer manager supports listeners, <tt>IFileBufferListener</tt>, that are informed about all relevant
an <code>IDocument</code> and and associated <code>IAnnotationModel</code>. File buffers are managed by
a file buffer manager. The <code>org.eclipse.core.filebuffers</code> plug-in provides a default
file buffer manager that can be obtained by calling <code>FileBuffers.getTextFileBufferManager()</code>.
The file buffer manager supports listeners, <code>IFileBufferListener</code>, that are informed about all relevant
state changes of file buffers as well as their creation and disposal.</p>
</body></html>
\ No newline at end of file
......@@ -29,6 +29,7 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnmappableCharacterException;
import java.nio.charset.UnsupportedCharsetException;
......@@ -93,10 +94,6 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
* Constant for representing the error status. This is considered a value object.
*/
private static final IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.FileBuffer_status_error, null);
/**
* Constant denoting UTF-8 encoding.
*/
private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
/**
* Constant denoting an empty set of properties
......@@ -297,7 +294,6 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
return desc.getContentType();
return null;
}
} catch (IOException x) {
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.FileBuffer_error_queryContentDescription, fFileStore.toString()), x));
}
......@@ -427,7 +423,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fHasBOM && CHARSET_UTF_8.equals(encoding))
if (fHasBOM && StandardCharsets.UTF_8.name().equals(encoding))
stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
......@@ -451,7 +447,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fHasBOM && CHARSET_UTF_8.equals(encoding))
if (fHasBOM && StandardCharsets.UTF_8.name().equals(encoding))
out.write(IContentDescription.BOM_UTF_8);
out.write(bytes, 0, bytesLength);
......@@ -524,7 +520,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (hasBOM && CHARSET_UTF_8.equals(encoding)) {
if (hasBOM && StandardCharsets.UTF_8.name().equals(encoding)) {
int n= 0;
do {
int bytes= contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
......
......@@ -27,6 +27,7 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnmappableCharacterException;
import java.nio.charset.UnsupportedCharsetException;
......@@ -97,20 +98,6 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
* Constant for representing the error status. This is considered a value object.
*/
static final private IStatus STATUS_ERROR= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.FileBuffer_status_error, null);
/**
* Constant denoting UTF-8 encoding.
*/
private static final String CHARSET_UTF_8= "UTF-8"; //$NON-NLS-1$
/**
* Constant denoting UTF-16 encoding.
* @since 3.4
*/
private static final String CHARSET_UTF_16= "UTF-16"; //$NON-NLS-1$
/**
* Constant denoting UTF-16LE encoding.
* @since 3.4
*/
private static final String CHARSET_UTF_16LE= "UTF-16LE"; //$NON-NLS-1$
/**
* Constant denoting an empty set of properties
......@@ -311,8 +298,8 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
String encoding= computeEncoding();
if (fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16.equals(encoding))
encoding= CHARSET_UTF_16LE;
if (fBOM == IContentDescription.BOM_UTF_16LE && StandardCharsets.UTF_16.name().equals(encoding))
encoding= StandardCharsets.UTF_16LE.name();
Charset charset;
try {
......@@ -355,10 +342,10 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fBOM == IContentDescription.BOM_UTF_8 && CHARSET_UTF_8.equals(encoding))
if (fBOM == IContentDescription.BOM_UTF_8 && StandardCharsets.UTF_8.name().equals(encoding))
stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
if (fBOM == IContentDescription.BOM_UTF_16LE && CHARSET_UTF_16LE.equals(encoding))
if (fBOM == IContentDescription.BOM_UTF_16LE && StandardCharsets.UTF_16LE.name().equals(encoding))
stream= new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_16LE), stream);
if (fFile.exists()) {
......@@ -513,7 +500,7 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fBOM != null && CHARSET_UTF_8.equals(encoding)) {
if (fBOM != null && StandardCharsets.UTF_8.name().equals(encoding)) {
int n= 0;
do {
int bytes= contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
......
......@@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.platform.text</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.jface.text.examples</artifactId>
......
......@@ -2,11 +2,12 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.jface.text.tests
Bundle-Version: 3.11.400.qualifier
Bundle-Version: 3.11.500.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package:
org.eclipse.jface.text.tests,
org.eclipse.jface.text.tests.contentassist,
org.eclipse.jface.text.tests.reconciler,
org.eclipse.jface.text.tests.rules,
org.eclipse.jface.text.tests.source,
......@@ -17,7 +18,9 @@ Require-Bundle:
org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
org.junit;bundle-version="4.12.0",
org.eclipse.text.tests;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)"
org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui.workbench.texteditor,
org.eclipse.test.performance;bundle-version="3.13.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-BundleShape: dir
Automatic-Module-Name: org.eclipse.jface.text.tests
......@@ -14,12 +14,12 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.jface</groupId>
<artifactId>org.eclipse.jface.text.tests</artifactId>
<version>3.11.400-SNAPSHOT</version>
<version>3.11.500-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
......
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.jface.text.tests;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.util.Util;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.AnnotationPainter;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.tests.util.DisplayHelper;
public class CodeMiningTest {
private SourceViewer fViewer;
private Shell fShell;
@Rule public ScreenshotOnFailureRule rule = new ScreenshotOnFailureRule();
@Before
public void setUp() {
fShell= new Shell(Display.getDefault());
fShell.setSize(500, 200);
fShell.setLayout(new FillLayout());
fViewer= new SourceViewer(fShell, null, SWT.NONE);
final StyledText textWidget= fViewer.getTextWidget();
MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
@Override
public void setDocument(IDocument document) {
fViewer.updateCodeMinings();
}
@Override
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
// nothing to do
}
@Override
public void reconcile(IRegion partition) {
fViewer.updateCodeMinings();
}
}, false);
reconciler.install(fViewer);
fViewer.setDocument(new Document(), new AnnotationModel());
fViewer.setCodeMiningProviders(new ICodeMiningProvider[] { new DelayedEchoCodeMiningProvider() });
AnnotationPainter annotationPainter = new AnnotationPainter(fViewer, null);
fViewer.setCodeMiningAnnotationPainter(annotationPainter);
fViewer.addPainter(annotationPainter);
// this currently needs to be repeated
fViewer.setCodeMiningProviders(new ICodeMiningProvider[] { new DelayedEchoCodeMiningProvider() });
final Display display = textWidget.getDisplay();
fShell.open();
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return fViewer.getTextWidget().isVisible();
}
}.waitForCondition(display, 3000));
DisplayHelper.sleep(textWidget.getDisplay(), 1000);
}
@After
public void tearDown() {
fShell.dispose();
fViewer = null;
}
@Test
public void testCodeMiningFirstLine() {
fViewer.getDocument().set("echo");
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return fViewer.getTextWidget().getLineVerticalIndent(0) > 0;
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
}
@Test
public void testCodeMiningCtrlHome() throws BadLocationException {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
DelayedEchoCodeMiningProvider.DELAY = 500;
fViewer.getDocument().set(TextViewerTest.generate5000Lines());
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return fViewer.getTextWidget().getText().length() > 5000;
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
TextViewerTest.ctrlEnd(fViewer);
final int lastLine = fViewer.getDocument().getNumberOfLines() - 1;
final int lastLineOffset = fViewer.getDocument().getLineOffset(lastLine);
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return lastLineOffset >= fViewer.getVisibleRegion().getOffset() && lastLineOffset <= fViewer.getVisibleRegion().getOffset() + fViewer.getVisibleRegion().getLength();
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
DisplayHelper.sleep(fViewer.getControl().getDisplay(), 500);
AtomicInteger events = new AtomicInteger();
fViewer.addViewportListener(offset ->
events.incrementAndGet());
TextViewerTest.ctrlHome(fViewer);
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return events.get() > 0;
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
Assert.assertEquals(0, fViewer.getVisibleRegion().getOffset());
// wait for codemining to style line
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return fViewer.getTextWidget().getLineVerticalIndent(0) > 0;
}
}.waitForCondition(fViewer.getControl().getDisplay(), 300000));
}
@Test
public void testCodeMiningCtrlEnd() throws BadLocationException {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
fViewer.getDocument().set(TextViewerTest.generate5000Lines());
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return fViewer.getTextWidget().getText().length() > 5000 && fViewer.getTextWidget().getLineVerticalIndent(0) > 0;
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
DisplayHelper.sleep(fViewer.getTextWidget().getDisplay(), 500);
TextViewerTest.ctrlEnd(fViewer);
final int lastLine = fViewer.getDocument().getNumberOfLines() - 1;
final int lastLineOffset = fViewer.getDocument().getLineOffset(lastLine);
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return lastLineOffset >= fViewer.getVisibleRegion().getOffset() && lastLineOffset <= fViewer.getVisibleRegion().getOffset() + fViewer.getVisibleRegion().getLength();
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return fViewer.getTextWidget().getLineVerticalIndent(lastLine) > 0;
}
}.waitForCondition(fViewer.getControl().getDisplay(), 3000));
}
}
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.jface.text.tests;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
import org.eclipse.jface.text.codemining.ICodeMining;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
public class DelayedEchoCodeMiningProvider extends AbstractCodeMiningProvider implements ICodeMiningProvider {
public static int DELAY = 0;
@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) {
return CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(DELAY);
} catch (InterruptedException e1) {
e1.printStackTrace();
return null;
}
IDocument document = viewer.getDocument();
List<ICodeMining> res = new ArrayList<>();
for (int lineNumber = 0; lineNumber < document.getNumberOfLines(); lineNumber++) {
try {
String lineContent = document.get(document.getLineOffset(lineNumber), document.getLineLength(lineNumber));
if (!lineContent.trim().isEmpty()) {
LineHeaderCodeMining mining = new LineHeaderCodeMining(lineNumber, document, DelayedEchoCodeMiningProvider.this) {
// Nothing in particular
};
mining.setLabel(lineContent);
res.add(mining);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
return res;
});
}
}
......@@ -17,6 +17,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.eclipse.jface.text.tests.contentassist.AsyncContentAssistTest;
import org.eclipse.jface.text.tests.reconciler.AbstractReconcilerTest;
import org.eclipse.jface.text.tests.rules.DefaultPartitionerTest;
import org.eclipse.jface.text.tests.rules.DefaultPartitionerZeroLengthTest;
......@@ -43,6 +44,7 @@ import org.eclipse.jface.text.tests.templates.persistence.TemplatePersistenceDat
TextViewerUndoManagerTest.class,
DefaultPairMatcherTest.class,
DefaultPairMatcherTest2.class,
AsyncContentAssistTest.class,
AbstractReconcilerTest.class,
......@@ -53,6 +55,7 @@ import org.eclipse.jface.text.tests.templates.persistence.TemplatePersistenceDat
WordRuleTest.class,
TemplatePersistenceDataTest.class,
CodeMiningTest.class
})
public class JFaceTextTestSuite {
// see @SuiteClasses
......
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.jface.text.tests;
import org.junit.rules.TestWatcher;
import org.eclipse.test.Screenshots;
final class ScreenshotOnFailureRule extends TestWatcher {
@Override
protected void failed(Throwable e, org.junit.runner.Description description) {
Screenshots.takeScreenshot(description.getTestClass(), description.getMethodName());
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2014 Google, Inc and others.
* Copyright (c) 2014-2019 Google, Inc and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -9,26 +9,44 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
* - Sergey Prigogin (Google) - initial API and implementation
* - Mickael Istria (Red Hat Inc.) - [Bug 544708] Ctrl+Home
*******************************************************************************/
package org.eclipse.jface.text.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.util.Util;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.tests.util.DisplayHelper;
/**
* Basic tests for TextViewer.
*/
public class TextViewerTest {
@Rule public ScreenshotOnFailureRule screenshotRule = new ScreenshotOnFailureRule();
@Test
public void testSetRedraw_Bug441827() throws Exception {
Shell shell= new Shell();
......@@ -52,4 +70,94 @@ public class TextViewerTest {
shell.dispose();
}
}
@Test
public void testCtrlHomeViewportListener() {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
Shell shell= new Shell();
try {
shell.setLayout(new FillLayout());
shell.setSize(500, 200);
SourceViewer textViewer= new SourceViewer(shell, null, SWT.NONE);
textViewer.setDocument(new Document(generate5000Lines()));
shell.open();
textViewer.revealRange(4000, 1);
AtomicBoolean notifyHomeReached = new AtomicBoolean();
ctrlEnd(textViewer);
DisplayHelper.sleep(textViewer.getTextWidget().getDisplay(), 1000);
textViewer.addViewportListener(offset -> notifyHomeReached.set(offset == 0));
ctrlHome(textViewer);
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return notifyHomeReached.get();
}
}.waitForCondition(textViewer.getTextWidget().getDisplay(), 3000));
} finally {
shell.dispose();
}
}
@Test
public void testCtrlEndViewportListener() {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
Shell shell= new Shell();
try {
shell.setLayout(new FillLayout());
shell.setSize(500, 200);
SourceViewer textViewer= new SourceViewer(shell, null, SWT.NONE);
Document document= new Document(generate5000Lines());
textViewer.setDocument(document);
shell.open();
AtomicBoolean notifyEndReached = new AtomicBoolean();
textViewer.addViewportListener(offset ->
notifyEndReached.set(offset > 4000));
ctrlEnd(textViewer);
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return notifyEndReached.get();
}
}.waitForCondition(textViewer.getControl().getDisplay(), 3000));
} finally {
shell.dispose();
}
}
public static void ctrlEnd(ITextViewer viewer) {
postKeyEvent(viewer.getTextWidget(), SWT.END, SWT.CTRL, SWT.KeyDown);
}
public static void ctrlHome(ITextViewer viewer) {
postKeyEvent(viewer.getTextWidget(), SWT.HOME, SWT.CTRL, SWT.KeyDown);
}
private static void postKeyEvent(Control widget, int keyCode, int stateMask, int type) {
Display display= widget.getDisplay();
widget.setFocus();
DisplayHelper.driveEventQueue(display);
Event event = new Event();
event.widget = widget;
event.keyCode = keyCode;
event.stateMask = stateMask;
event.type = type;
event.doit = true;
// display.post(event) seem not always work, see bug 541415
Listener[] listeners= widget.getListeners(type);
for (Listener listener : listeners) {
listener.handleEvent(event);
}
DisplayHelper.driveEventQueue(display);
}
public static String generate5000Lines() {
StringBuilder b = new StringBuilder("start");
for (int i = 0; i < 5000; i++) {
b.append('\n');
}
b.append("end");
return b.toString();
}
}
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.jface.text.tests.contentassist;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.tests.util.DisplayHelper;
public class AsyncContentAssistTest {
private ILogListener listener;
private IStatus errorStatus;
@Before
public void setUp() {
listener= (status, plugin) -> {
if(status.getSeverity() == IStatus.ERROR && "org.eclipse.jface.text".equals(status.getPlugin())) {
errorStatus = status;
}
};
Platform.addLogListener(listener);
}
@After
public void tearDown() {
Platform.removeLogListener(listener);
}
@Test
public void testAsyncFailureStackOverflow() {
Shell shell = new Shell();
SourceViewer viewer = new SourceViewer(shell, null, SWT.NONE);
Document document = new Document("a");
viewer.setDocument(document);
ContentAssistant contentAssistant = new ContentAssistant(true);
contentAssistant.addContentAssistProcessor(new DelayedErrorContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.addContentAssistProcessor(new ImmediateContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.install(viewer);
contentAssistant.showPossibleCompletions();
document.set("ab"); // Simulate user typing a key when popup visible
DisplayHelper.sleep(shell.getDisplay(), 2000);
assertNotNull(errorStatus);
}
@Test
public void testSyncFailureNPE() {
Shell shell = new Shell();
SourceViewer viewer = new SourceViewer(shell, null, SWT.NONE);
Document document = new Document("a");
viewer.setDocument(document);
ContentAssistant contentAssistant = new ContentAssistant(true);
contentAssistant.addContentAssistProcessor(new ImmediateContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.addContentAssistProcessor(new ImmediateNullContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.install(viewer);
contentAssistant.showPossibleCompletions();
document.set("ab"); // Simulate user typing a key when popup visible
DisplayHelper.sleep(shell.getDisplay(), 1000);
assertNull(errorStatus);
}
}
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.jface.text.tests.contentassist;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
public class DelayedErrorContentAssistProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
try {
Thread.sleep(100); // long enough to make async
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
throw new RuntimeException();
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return null;
}
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
}
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.jface.text.tests.contentassist;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
public class ImmediateContentAssistProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
return new ICompletionProposal[] { };
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return null;
}
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
}
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Mickael Istria (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.jface.text.tests.contentassist;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
public class ImmediateNullContentAssistProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
return null;
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return null;
}
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
}