diff options
author | Mickael Istria | 2019-04-29 09:56:53 +0000 |
---|---|---|
committer | Roland Grunberg | 2019-04-30 14:35:04 +0000 |
commit | 22e1a5c6ee7dd76d9bc36d0d6f288e045f0407a5 (patch) | |
tree | 432b956a9429b1031fa582bcee3dabc2b839ad88 | |
parent | a072b1ffeec5e0533894c9dde8959f4ed3e9ee84 (diff) | |
download | eclipse.jdt.ui-22e1a5c6ee7dd76d9bc36d0d6f288e045f0407a5.tar.gz eclipse.jdt.ui-22e1a5c6ee7dd76d9bc36d0d6f288e045f0407a5.tar.xz eclipse.jdt.ui-22e1a5c6ee7dd76d9bc36d0d6f288e045f0407a5.zip |
Bug 546706 - [test] Parameter name minings on multi-line invocations
This test reproduces and checks issue reported in the bug, about the
code mining rendering taking place at wrong locations.
Change-Id: I0aadee7ddaa20ecf01b7f636d99b4f1e7cfdd421
Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r-- | org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java index 7fe2b181ed..a2c65730c6 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java @@ -16,8 +16,11 @@ package org.eclipse.jdt.text.tests.codemining; import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.LongSupplier; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -72,6 +75,7 @@ public class ParameterNamesCodeMiningTest extends TestCase { } @Override + @Before protected void setUp() throws Exception { super.setUp(); if(!welcomeClosed) { @@ -85,6 +89,7 @@ public class ParameterNamesCodeMiningTest extends TestCase { } @Override + @After protected void tearDown() throws Exception { super.tearDown(); IWorkbenchPage workbenchPage= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); @@ -115,6 +120,34 @@ public class ParameterNamesCodeMiningTest extends TestCase { assertEquals(2, fParameterNameCodeMiningProvider.provideCodeMinings(viewer, new NullProgressMonitor()).get().size()); } + public void testMultiLines() throws Exception { + String contents = + "class Foo {\n" + + " long n = Math.max(System.currentTimeMillis(\n" + + " ), 0);\n" + + "}"; + ICompilationUnit compilationUnit= fPackage.createCompilationUnit("Foo.java", contents, true, new NullProgressMonitor()); + JavaEditor editor= (JavaEditor) EditorUtility.openInEditor(compilationUnit); + fParameterNameCodeMiningProvider.setContext(editor); + JavaSourceViewer viewer = (JavaSourceViewer)editor.getViewer(); + viewer.setCodeMiningProviders(new ICodeMiningProvider[] { + fParameterNameCodeMiningProvider + }); + assertEquals(2, fParameterNameCodeMiningProvider.provideCodeMinings(viewer, new NullProgressMonitor()).get().size()); + // + StyledText widget = viewer.getTextWidget(); + int charWidth = widget.getTextBounds(0, 1).width; + LongSupplier drawnCodeMiningsCount = () -> Arrays.stream(widget.getStyleRanges()).filter(style -> + style.metrics != null && style.metrics.width > charWidth).count(); + new DisplayHelper() { + @Override + protected boolean condition() { + return drawnCodeMiningsCount.getAsLong() == 2; + } + }.waitForCondition(widget.getDisplay(), 500); + assertEquals(2, drawnCodeMiningsCount.getAsLong()); + } + public void testUnresolvedMethodBinding() throws Exception { String contents= "public class Foo {\n" + " public void mehod() {\n" + |