Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelozerr2018-03-22 14:19:37 -0400
committerangelozerr2018-03-22 14:19:37 -0400
commit3743188767f8cef3a9854b23ff7569f335f53f70 (patch)
tree3dd62047c0066ea1e39b0fe1564fd78fc001d597
parentf0d65841e1d7ecf42e516a003be7ef9a6a99a73e (diff)
downloadeclipse.platform.text-3743188767f8cef3a9854b23ff7569f335f53f70.tar.gz
eclipse.platform.text-3743188767f8cef3a9854b23ff7569f335f53f70.tar.xz
eclipse.platform.text-3743188767f8cef3a9854b23ff7569f335f53f70.zip
Bug 532091 - [CodeMining] Don't draw minings which are cancelled
Change-Id: Ieb3896c28c30116e7ccc30a2169e2bafdd5d4fed Signed-off-by: angelozerr <angelo.zerr@gmail.com>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java41
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java42
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java27
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java15
4 files changed, 98 insertions, 27 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 98f4315e2..9a57f8dbe 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
@@ -73,13 +73,21 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple
@Override
public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
+ if (fResolvedMinings == null || (fResolvedMinings.length != minings.size())) {
+ // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
+ fResolvedMinings= new ICodeMining[minings.size()];
+ }
+ // fill valid resolved minings with old minings.
+ int length= Math.min(fMinings.size(), minings.size());
+ for (int i= 0; i < length; i++) {
+ ICodeMining mining= fMinings.get(i);
+ if (mining.isResolved() && !mining.isResolutionFailed()) {
+ fResolvedMinings[i]= mining;
+ }
+ }
disposeMinings();
fMonitor= monitor;
fMinings.addAll(minings);
- if (fResolvedMinings == null || (fResolvedMinings.length != fMinings.size())) {
- // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
- fResolvedMinings= new ICodeMining[fMinings.size()];
- }
}
@Override
@@ -106,24 +114,31 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple
fBounds.clear();
for (int i= 0; i < minings.size(); i++) {
ICodeMining mining= minings.get(i);
- if (!mining.isResolved()) {
+ if (mining.isResolutionFailed()) {
+ // mining has error, try to get the last resolved mining.
+ if (fResolvedMinings.length > i) {
+ mining= fResolvedMinings[i];
+ }
+ } else if (!mining.isResolved()) {
// the mining is not resolved.
- if (!redrawn) {
+ if (!redrawn && !mining.isResolutionFailed()) {
// redraw the annotation when mining is resolved.
redraw();
redrawn= true;
}
// try to get the last resolved mining.
- if (fResolvedMinings != null) {
+ if (fResolvedMinings.length > i) {
mining= fResolvedMinings[i];
}
- if (mining == null) {
- // the last mining was not resolved, don't draw it.
- continue;
- }
} else {
// mining is resolved, update the resolved mining list
- fResolvedMinings[i]= mining;
+ if (fResolvedMinings.length > i) {
+ fResolvedMinings[i]= mining;
+ }
+ }
+ if (mining == null) {
+ // the last mining was not resolved, don't draw it.
+ continue;
}
// draw the mining
if (nbDraw > 0) {
@@ -161,7 +176,7 @@ public class CodeMiningLineContentAnnotation extends LineContentAnnotation imple
// redraw codemining annotation is done only if all current minings are resolved.
List<ICodeMining> minings= new ArrayList<>(fMinings);
for (ICodeMining mining : minings) {
- if (!mining.isResolved()) {
+ if (!mining.isResolved() && !mining.isResolutionFailed()) {
// one of mining is not resolved, resolve it and then redraw the annotation.
mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
this.redraw();
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 21a67dc6a..b2540dffe 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
@@ -94,13 +94,21 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme
@Override
public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
+ if (fResolvedMinings == null || (fResolvedMinings.length != minings.size())) {
+ // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
+ fResolvedMinings= new ICodeMining[minings.size()];
+ }
+ // fill valid resolved minings with old minings.
+ int length= Math.min(fMinings.size(), minings.size());
+ for (int i= 0; i < length; i++) {
+ ICodeMining mining= fMinings.get(i);
+ if (mining.isResolved() && !mining.isResolutionFailed()) {
+ fResolvedMinings[i]= mining;
+ }
+ }
disposeMinings();
fMonitor= monitor;
fMinings.addAll(minings);
- if (fResolvedMinings == null || (fResolvedMinings.length != fMinings.size())) {
- // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
- fResolvedMinings= new ICodeMining[fMinings.size()];
- }
}
@Override
@@ -126,21 +134,31 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme
fBounds.clear();
for (int i= 0; i < minings.size(); i++) {
ICodeMining mining= minings.get(i);
- if (!mining.isResolved()) {
- if (!redrawn) {
+ if (mining.isResolutionFailed()) {
+ // mining has error, try to get the last resolved mining.
+ if (fResolvedMinings.length > i) {
+ mining= fResolvedMinings[i];
+ }
+ } else if (!mining.isResolved()) {
+ // the mining is not resolved.
+ if (!redrawn && !mining.isResolutionFailed()) {
+ // redraw the annotation when mining is resolved.
redraw();
redrawn= true;
}
// try to get the last resolved mining.
- if (fResolvedMinings != null) {
+ if (fResolvedMinings.length > i) {
mining= fResolvedMinings[i];
}
- if (mining == null) {
- continue;
- }
} else {
// mining is resolved, update the resolved mining list
- fResolvedMinings[i]= mining;
+ if (fResolvedMinings.length > i) {
+ fResolvedMinings[i]= mining;
+ }
+ }
+ if (mining == null) {
+ // the last mining was not resolved, don't draw it.
+ continue;
}
// draw the mining
if (nbDraw > 0) {
@@ -177,7 +195,7 @@ public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation impleme
// redraw codemining annotation is done only if all current minings are resolved.
List<ICodeMining> minings= new ArrayList<>(fMinings);
for (ICodeMining mining : minings) {
- if (!mining.isResolved()) {
+ if (!mining.isResolved() && !mining.isResolutionFailed()) {
// one of mining is not resolved, resolve it and then redraw the annotation.
mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
this.redraw();
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java
index e683c76a9..767dcfac1 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java
@@ -57,11 +57,21 @@ public abstract class AbstractCodeMining implements ICodeMining {
private final Consumer<MouseEvent> action;
/**
+ * The cached resolved state.
+ */
+ private boolean resolved;
+
+ /**
+ * The cached resolution failed state.
+ */
+ private boolean resolutionFailed;
+
+ /**
* CodeMining constructor to locate the code mining in a given position.
*
* @param position the position where the mining must be drawn.
* @param provider the owner codemining provider which creates this mining.
- * @param action the action to execute when mining is clicked and null otherwise.
+ * @param action the action to execute when mining is clicked and null otherwise.
*/
protected AbstractCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) {
this.position= position;
@@ -115,12 +125,25 @@ public abstract class AbstractCodeMining implements ICodeMining {
@Override
public boolean isResolved() {
- return (resolveFuture != null && resolveFuture.isDone());
+ if (resolveFuture != null) {
+ return resolved= resolveFuture.isDone();
+ }
+ return resolved;
+ }
+
+ @Override
+ public boolean isResolutionFailed() {
+ if (resolveFuture != null) {
+ return resolutionFailed= resolveFuture.isCompletedExceptionally();
+ }
+ return resolutionFailed;
}
@Override
public void dispose() {
if (resolveFuture != null) {
+ resolved= resolveFuture.isDone();
+ resolutionFailed= resolveFuture.isCompletedExceptionally();
resolveFuture.cancel(true);
resolveFuture= null;
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java
index 4f8eb6284..9355ea20f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.jface.text.codemining;
+import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
@@ -76,6 +77,11 @@ public interface ICodeMining {
* {{@link #resolve(ITextViewer, IProgressMonitor)}} will be invoked later, triggering the
* future to resolve content.
*
+ * This method returns true if content mining is resolved even if there are some error (like
+ * {@link CancellationException}). Use {{@link #isResolutionFailed()}} to know if mining was
+ * resolved with an error.
+ *
+ * @see #isResolutionFailed()
* @return whether the content mining is resolved. If it is not resolved,
* {{@link #resolve(ITextViewer, IProgressMonitor)}} will be invoked later, triggering
* the future to resolve content.
@@ -83,6 +89,15 @@ public interface ICodeMining {
boolean isResolved();
/**
+ * Returns true if resolved was done with an error (like {@link CancellationException}) and
+ * false otherwise.
+ *
+ * @return true if resolved was done with an error (like {@link CancellationException}) and
+ * false otherwise.
+ */
+ boolean isResolutionFailed();
+
+ /**
* Draw the code mining.
*
* @param gc the graphics context

Back to the top