diff options
author | azerr | 2018-05-01 13:27:23 +0000 |
---|---|---|
committer | Mickael Istria | 2018-05-03 07:50:40 +0000 |
commit | 945d5eb3c73a66b124940fc8a20c58801a7c7118 (patch) | |
tree | a52a15ffbd8a94fe72ea5ab7af43d263aa970c23 /org.eclipse.jface.text | |
parent | f430604e34b66e51471aa26c0c61053408afeac2 (diff) | |
download | eclipse.platform.text-945d5eb3c73a66b124940fc8a20c58801a7c7118.tar.gz eclipse.platform.text-945d5eb3c73a66b124940fc8a20c58801a7c7118.tar.xz eclipse.platform.text-945d5eb3c73a66b124940fc8a20c58801a7c7118.zip |
Bug 533072 - [code mining] Click on mining doesn't work when previous
mining is not drawn
Change-Id: I7c3a703366f9c42ffd70c0ed5deee6014040b7f5
Signed-off-by: azerr <angelo.zerr@gmail.com>
Diffstat (limited to 'org.eclipse.jface.text')
3 files changed, 74 insertions, 31 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java index 2bd21cad792..d3fb4eece7d 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java @@ -62,7 +62,7 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple * Code mining annotation constructor. * * @param position the position - * @param viewer the viewer + * @param viewer the viewer */ public CodeMiningLineContentAnnotation(Position position, ISourceViewer viewer) { super(position, viewer); @@ -132,7 +132,7 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple // the mining is resolved with error, draw the last resolved mining mining= lastResolvedMining; } - if (mining == null || mining.getLabel() == null || mining.getLabel().isEmpty()) { + if (!CodeMiningManager.isValidMining(mining)) { // ignore the draw of mining continue; } @@ -146,6 +146,7 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple x+= separatorWidth; } initGC(textWidget, color, gc); + @SuppressWarnings("null") Point loc= mining.draw(gc, textWidget, color, x, y); fBounds.add(new Rectangle(x, y, loc.x, loc.y)); x+= loc.x; @@ -158,8 +159,8 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple * Initialize GC with given color and styled text background color and font. * * @param textWidget the text widget - * @param color the color - * @param gc the gc to initialize + * @param color the color + * @param gc the gc to initialize */ private void initGC(StyledText textWidget, Color color, GC gc) { gc.setForeground(color); @@ -186,14 +187,8 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple @Override public Consumer<MouseEvent> getAction(MouseEvent e) { - for (int i= 0; i < fBounds.size(); i++) { - Rectangle bound= fBounds.get(i); - if (bound.contains(e.x, e.y)) { - ICodeMining mining= fMinings.get(i); - return mining.getAction(); - } - } - return null; + ICodeMining mining= CodeMiningManager.getValidCodeMiningAtLocation(fResolvedMinings, fBounds, e.x, e.y); + return mining != null ? mining.getAction() : null; } @Override diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java index 2f1b7e4743b..681b520ba00 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java @@ -12,7 +12,6 @@ package org.eclipse.jface.internal.text.codemining; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.function.Consumer; import java.util.stream.Stream; @@ -89,7 +88,7 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme if (fResolvedMinings == null || fResolvedMinings.length == 0) { return false; } - return Stream.of(fResolvedMinings).anyMatch(m -> Objects.nonNull(m) && !m.getLabel().isEmpty()); + return Stream.of(fResolvedMinings).anyMatch(m -> CodeMiningManager.isValidMining(m)); } @Override @@ -137,7 +136,7 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme // try to get the last resolved mining. ICodeMining lastResolvedMining= (fResolvedMinings != null && fResolvedMinings.length > i) ? fResolvedMinings[i] : null; if (mining.getLabel() != null) { - // mining is resolved with none error, update the resolved mining list + // mining is resolved without error, update the resolved mining list fResolvedMinings[i]= mining; } else if (!mining.isResolved()) { // the mining is not resolved, draw the last resolved mining @@ -151,7 +150,7 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme // the mining is resolved with error, draw the last resolved mining mining= lastResolvedMining; } - if (mining == null || mining.getLabel() == null || mining.getLabel().isEmpty()) { + if (!CodeMiningManager.isValidMining(mining)) { // ignore the draw of mining continue; } @@ -165,6 +164,7 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme x+= separatorWidth; } initGC(textWidget, color, gc); + @SuppressWarnings("null") Point loc= mining.draw(gc, textWidget, color, x, y); fBounds.add(new Rectangle(x, y, loc.x, loc.y)); x+= loc.x; @@ -204,14 +204,8 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme @Override public Consumer<MouseEvent> getAction(MouseEvent e) { - for (int i= 0; i < fBounds.size(); i++) { - Rectangle bound= fBounds.get(i); - if (bound.contains(e.x, e.y)) { - ICodeMining mining= fMinings.get(i); - return mining.getAction(); - } - } - return null; + ICodeMining mining= CodeMiningManager.getValidCodeMiningAtLocation(fResolvedMinings, fBounds, e.x, e.y); + return mining != null ? mining.getAction() : null; } @Override diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java index 54ac75a1f1f..3f11cdfb69b 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java @@ -21,6 +21,8 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function;
import java.util.stream.Collectors;
+import org.eclipse.swt.graphics.Rectangle;
+
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -64,9 +66,9 @@ public class CodeMiningManager implements Runnable { /**
* Constructor of codemining manager with the given arguments.
*
- * @param viewer the source viewer
+ * @param viewer the source viewer
* @param inlinedAnnotationSupport the inlined annotation support used to draw code minings
- * @param codeMiningProviders the array of codemining providers, must not be empty
+ * @param codeMiningProviders the array of codemining providers, must not be empty
*/
public CodeMiningManager(ISourceViewer viewer, InlinedAnnotationSupport inlinedAnnotationSupport,
ICodeMiningProvider[] codeMiningProviders) {
@@ -142,9 +144,9 @@ public class CodeMiningManager implements Runnable { * Return the list of {@link CompletableFuture} which provides the list of {@link ICodeMining}
* for the given <code>viewer</code> by using the given providers.
*
- * @param viewer the text viewer.
+ * @param viewer the text viewer.
* @param providers the CodeMining list providers.
- * @param monitor the progress monitor.
+ * @param monitor the progress monitor.
* @return the list of {@link CompletableFuture} which provides the list of {@link ICodeMining}
* for the given <code>viewer</code> by using the given providers.
*/
@@ -161,7 +163,7 @@ public class CodeMiningManager implements Runnable { * Returns a sorted Map which groups the given code minings by same position line.
*
* @param codeMinings list of code minings to group.
- * @param providers CodeMining providers used to retrieve code minings.
+ * @param providers CodeMining providers used to retrieve code minings.
* @return a sorted Map which groups the given code minings by same position line.
*/
private static Map<Position, List<ICodeMining>> groupByLines(List<? extends ICodeMining> codeMinings,
@@ -187,8 +189,8 @@ public class CodeMiningManager implements Runnable { /**
* Render the codemining grouped by line position.
*
- * @param groups code minings grouped by lines position
- * @param viewer the viewer
+ * @param groups code minings grouped by lines position
+ * @param viewer the viewer
* @param monitor the progress monitor
*/
private void renderCodeMinings(Map<Position, List<ICodeMining>> groups, ISourceViewer viewer,
@@ -230,4 +232,56 @@ public class CodeMiningManager implements Runnable { annotationsToRedraw.stream().forEach(ann -> ann.redraw());
}
+ /**
+ * Returns <code>true</code> if the given mining has a non empty label and <code>false</code>
+ * otherwise.
+ *
+ * @param mining the mining to check
+ * @return <code>true</code> if the given mining has a non empty label and <code>false</code>
+ * otherwise.
+ */
+ static boolean isValidMining(ICodeMining mining) {
+ return mining != null && mining.getLabel() != null && !mining.getLabel().isEmpty();
+ }
+
+ /**
+ * Returns the valid code mining at the given location by using the bounds of codemining
+ * annotations which stores only the valid code mining.
+ *
+ * @param minings the list of mining of the codemining annotation.
+ * @param bounds the bounds of the valid minings of the codemining annotation.
+ * @param x the x location
+ * @param y the y location
+ * @return the valid code mining at the given location by using the bounds of codemining
+ * annotations which stores only the valid code mining.
+ */
+ static ICodeMining getValidCodeMiningAtLocation(ICodeMining[] minings, List<Rectangle> bounds, int x, int y) {
+ for (int i= 0; i < bounds.size(); i++) {
+ Rectangle bound= bounds.get(i);
+ if (bound.contains(x, y)) {
+ return getCodeValidMiningAtIndex(minings, i);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the valid code mining at the given index.
+ *
+ * @param minings the list of minings
+ * @param index the index
+ * @return the valid code mining at the given index.
+ */
+ private static ICodeMining getCodeValidMiningAtIndex(ICodeMining[] minings, int index) {
+ int validIndex= 0;
+ for (ICodeMining mining : minings) {
+ if (isValidMining(mining)) {
+ if (validIndex == index) {
+ return mining;
+ }
+ validIndex++;
+ }
+ }
+ return null;
+ }
}
|