Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2020-04-08 21:16:50 +0000
committerMickael Istria2020-04-11 13:24:30 +0000
commit7c2ce92e127de0823b2898ade7ee9074efde222b (patch)
tree91f3a926e245f3f905e4672322736d64f4bb2b5e
parenta302ab6985ac5b88e4586f835ca115b4b0a5c656 (diff)
downloadeclipse.platform.text-7c2ce92e127de0823b2898ade7ee9074efde222b.tar.gz
eclipse.platform.text-7c2ce92e127de0823b2898ade7ee9074efde222b.tar.xz
eclipse.platform.text-7c2ce92e127de0823b2898ade7ee9074efde222b.zip
Bug 553640 - [code mining] bad char location when mixing headers&inlineI20200415-0200I20200414-1010I20200414-0630I20200413-1800I20200412-1800I20200411-1800
Change-Id: I16dbdcafb0577346fe3494652141d33c3858b9ea Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.jface.text.examples/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jface.text.examples/pom.xml2
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java2
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java56
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java5
5 files changed, 62 insertions, 5 deletions
diff --git a/org.eclipse.jface.text.examples/META-INF/MANIFEST.MF b/org.eclipse.jface.text.examples/META-INF/MANIFEST.MF
index 2b082802a..e4eec1cf9 100644
--- a/org.eclipse.jface.text.examples/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text.examples/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CodeMinig Examples
Bundle-SymbolicName: org.eclipse.jface.text.examples
-Bundle-Version: 1.0.100.qualifier
+Bundle-Version: 1.0.200.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.runtime,
diff --git a/org.eclipse.jface.text.examples/pom.xml b/org.eclipse.jface.text.examples/pom.xml
index 45f45bcb5..d2ff36998 100644
--- a/org.eclipse.jface.text.examples/pom.xml
+++ b/org.eclipse.jface.text.examples/pom.xml
@@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.jface.text.examples</artifactId>
- <version>1.0.100-SNAPSHOT</version>
+ <version>1.0.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java
index 24da65a1a..a1bc647d3 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java
@@ -56,7 +56,7 @@ public class CodeMiningDemo {
addAnnotationPainter(sourceViewer);
// Initialize codemining providers
((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] {
- new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
+ new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider(), new ToEchoWithHeaderAndInlineCodeMiningProvider("class") });
// Execute codemining in a reconciler
MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java
new file mode 100644
index 000000000..f4039d968
--- /dev/null
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2020, Red Hat Inc.
+ *
+ * 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
+ */
+package org.eclipse.jface.text.examples.codemining;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+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.LineContentCodeMining;
+
+public class ToEchoWithHeaderAndInlineCodeMiningProvider extends AbstractCodeMiningProvider
+ implements ICodeMiningProvider {
+
+ private final String toEcho;
+
+ public ToEchoWithHeaderAndInlineCodeMiningProvider(String keyword) {
+ this.toEcho = keyword;
+ }
+
+ @Override
+ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
+ IProgressMonitor monitor) {
+ int index = 0;
+ List<ICodeMining> res = new ArrayList<>();
+ while ((index = viewer.getDocument().get().indexOf(toEcho, index)) != -1) {
+ index += toEcho.length();
+ res.add(new LineContentCodeMining(new Position(index, 1), this) {
+ @Override
+ public String getLabel() {
+ return toEcho;
+ }
+
+ @Override
+ public boolean isResolved() {
+ return true;
+ }
+ });
+ };
+ return CompletableFuture.completedFuture(res);
+ }
+
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java
index ed569af78..e7d10c244 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java
@@ -255,7 +255,8 @@ class InlinedAnnotationDrawingStrategy implements IDrawingStrategy {
Rectangle annotationBounds= new Rectangle(charBounds.x + redrawnCharacterWidth, charBounds.y, annotation.getWidth(), charBounds.height);
// When line text has line header annotation, there is a space on the top, adjust the y by using char height
- annotationBounds.y+= charBounds.height - textWidget.getLineHeight();
+ int verticalDrawingOffset= charBounds.height - textWidget.getLineHeight();
+ annotationBounds.y+= verticalDrawingOffset;
// Draw the line content annotation
annotation.setLocation(annotationBounds.x, annotationBounds.y);
@@ -300,7 +301,7 @@ class InlinedAnnotationDrawingStrategy implements IDrawingStrategy {
gc.setForeground(textWidget.getSelectionForeground());
gc.setBackground(textWidget.getSelectionBackground());
}
- gc.drawString(Character.toString(hostCharacter), charBounds.x, charBounds.y, true);
+ gc.drawString(Character.toString(hostCharacter), charBounds.x, charBounds.y + verticalDrawingOffset, true);
// END TO REMOVE
} else if (style != null && style.metrics != null && style.metrics.width != 0) {
// line content annotation had an , reset it

Back to the top