Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelozerr2018-02-02 18:30:05 +0000
committerMickael Istria2018-02-05 14:29:14 +0000
commit907bc9caff4b9a164cb7a02c3ec3cadce90578c1 (patch)
tree66bb1d49c53652777ce3ad435e38c72760af36f3
parent506feabf902d099db8732cfa58f193c93166433e (diff)
downloadeclipse.platform.text-907bc9caff4b9a164cb7a02c3ec3cadce90578c1.tar.gz
eclipse.platform.text-907bc9caff4b9a164cb7a02c3ec3cadce90578c1.tar.xz
eclipse.platform.text-907bc9caff4b9a164cb7a02c3ec3cadce90578c1.zip
Bug 529115 - [CodeMining] CodeMining should support line header/content
annotation type both Change-Id: Ie10a4ae0354df26198f32a0bd3fc65a26a159cd9 Signed-off-by: angelozerr <angelo.zerr@gmail.com>
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/AbstractClassCodeMining.java4
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java187
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java (renamed from org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java)375
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java16
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/ICodeMiningAnnotation.java39
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java28
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineContentCodeMining.java46
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineHeaderCodeMining.java55
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java4
9 files changed, 529 insertions, 225 deletions
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/AbstractClassCodeMining.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/AbstractClassCodeMining.java
index ebfc74bb7f0..531f1af8252 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/AbstractClassCodeMining.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/AbstractClassCodeMining.java
@@ -12,14 +12,14 @@ package org.eclipse.jface.text.examples.codemining;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.codemining.AbstractCodeMining;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
+import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
/**
* Abstract class for class name mining.
*
*/
-public abstract class AbstractClassCodeMining extends AbstractCodeMining {
+public abstract class AbstractClassCodeMining extends LineHeaderCodeMining {
private final String className;
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
new file mode 100644
index 00000000000..efb36ed93ec
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java
@@ -0,0 +1,187 @@
+/**
+ * Copyright (c) 2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
+ */
+package org.eclipse.jface.internal.text.codemining;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.codemining.ICodeMining;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
+
+/**
+ * Code Mining annotation in line content.
+ *
+ * @since 3.13
+ */
+public class CodeMiningLineContentAnnotation extends LineContentAnnotation implements ICodeMiningAnnotation {
+
+ private static final String SEPARATOR= " | "; //$NON-NLS-1$
+
+ /**
+ * List of resolved minings which contains current resolved minings and last resolved minings
+ * and null if mining is not resolved.
+ */
+ private ICodeMining[] fResolvedMinings;
+
+ /**
+ * List of current resolved/unresolved minings
+ */
+ private final List<ICodeMining> fMinings;
+
+ /**
+ * List of bounds minings
+ */
+ private final List<Rectangle> fBounds;
+
+ /**
+ * The current progress monitor
+ */
+ private IProgressMonitor fMonitor;
+
+ /**
+ * Code mining annotation constructor.
+ *
+ * @param position the position
+ * @param viewer the viewer
+ */
+ public CodeMiningLineContentAnnotation(Position position, ISourceViewer viewer) {
+ super(position, viewer);
+ fResolvedMinings= null;
+ fMinings= new ArrayList<>();
+ fBounds= new ArrayList<>();
+ }
+
+ @Override
+ public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
+ 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
+ public void markDeleted(boolean deleted) {
+ super.markDeleted(deleted);
+ if (deleted) {
+ disposeMinings();
+ fResolvedMinings= null;
+ }
+ }
+
+ private void disposeMinings() {
+ fMinings.stream().forEach(ICodeMining::dispose);
+ fMinings.clear();
+ }
+
+ @Override
+ protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
+ List<ICodeMining> minings= new ArrayList<>(fMinings);
+ int nbDraw= 0;
+ int originalX= x;
+ int separatorWidth= -1;
+ boolean redrawn= false;
+ fBounds.clear();
+ for (int i= 0; i < minings.size(); i++) {
+ ICodeMining mining= minings.get(i);
+ if (!mining.isResolved()) {
+ // the mining is not resolved.
+ if (!redrawn) {
+ // redraw the annotation when mining is resolved.
+ redraw();
+ redrawn= true;
+ }
+ // try to get the last resolved mining.
+ if (fResolvedMinings != null) {
+ 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;
+ }
+ // draw the mining
+ if (nbDraw > 0) {
+ initGC(textWidget, color, gc);
+ gc.drawText(SEPARATOR, x, y);
+ if (separatorWidth == -1) {
+ separatorWidth= gc.stringExtent(SEPARATOR).x;
+ }
+ x+= separatorWidth;
+ }
+ initGC(textWidget, color, gc);
+ Point loc= mining.draw(gc, textWidget, color, x, y);
+ fBounds.add(new Rectangle(x, y, loc.x, loc.y));
+ x+= loc.x;
+ nbDraw++;
+ }
+ return x - originalX;
+ }
+
+ /**
+ * 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
+ */
+ private void initGC(StyledText textWidget, Color color, GC gc) {
+ gc.setForeground(color);
+ gc.setBackground(textWidget.getBackground());
+ gc.setFont(textWidget.getFont());
+ }
+
+ @Override
+ public void redraw() {
+ // 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()) {
+ // one of mining is not resolved, resolve it and then redraw the annotation.
+ mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
+ this.redraw();
+ });
+ return;
+ }
+ }
+ // all minings are resolved, redraw the annotation
+ super.redraw();
+ }
+
+ @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;
+ }
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java
index 6c29d01f0ec..69b91874037 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java
@@ -1,190 +1,185 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
- */
-package org.eclipse.jface.internal.text.codemining;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Consumer;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.codemining.ICodeMining;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
-
-/**
- * Code Mining annotation.
- *
- * @since 3.13
- */
-public class CodeMiningAnnotation extends LineHeaderAnnotation {
-
- private static final String SEPARATOR= " | "; //$NON-NLS-1$
-
- /**
- * List of resolved minings which contains current resolved minings and last resolved minings
- * and null if mining is not resolved.
- */
- private ICodeMining[] fResolvedMinings;
-
- /**
- * List of current resolved/unresolved minings
- */
- private final List<ICodeMining> fMinings;
-
- /**
- * List of bounds minings
- */
- private final List<Rectangle> fBounds;
-
- /**
- * The current progress monitor
- */
- private IProgressMonitor fMonitor;
-
- /**
- * Code mining annotation constructor.
- *
- * @param position the position
- * @param viewer the viewer
- */
- public CodeMiningAnnotation(Position position, ISourceViewer viewer) {
- super(position, viewer);
- fResolvedMinings= null;
- fMinings= new ArrayList<>();
- fBounds= new ArrayList<>();
- }
-
- /**
- * Update code minings.
- *
- * @param minings the minings to update.
- * @param monitor the monitor
- */
- public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
- 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
- public void markDeleted(boolean deleted) {
- super.markDeleted(deleted);
- if (deleted) {
- disposeMinings();
- fResolvedMinings= null;
- }
- }
-
- private void disposeMinings() {
- fMinings.stream().forEach(ICodeMining::dispose);
- fMinings.clear();
- }
-
- @Override
- public void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
- List<ICodeMining> minings= new ArrayList<>(fMinings);
- int nbDraw= 0;
- int separatorWidth= -1;
- boolean redrawn= false;
- fBounds.clear();
- for (int i= 0; i < minings.size(); i++) {
- ICodeMining mining= minings.get(i);
- if (!mining.isResolved()) {
- // the mining is not resolved.
- if (!redrawn) {
- // redraw the annotation when mining is resolved.
- redraw();
- redrawn= true;
- }
- // try to get the last resolved mining.
- if (fResolvedMinings != null) {
- 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;
- }
- // draw the mining
- if (nbDraw > 0) {
- initGC(textWidget, color, gc);
- gc.drawText(SEPARATOR, x, y);
- if (separatorWidth == -1) {
- separatorWidth= gc.stringExtent(SEPARATOR).x;
- }
- x+= separatorWidth;
- }
- initGC(textWidget, color, gc);
- Point loc= mining.draw(gc, textWidget, color, x, y);
- fBounds.add(new Rectangle(x, y, loc.x, loc.y));
- x+= loc.x;
- nbDraw++;
- }
- }
-
- /**
- * 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
- */
- private void initGC(StyledText textWidget, Color color, GC gc) {
- gc.setForeground(color);
- gc.setBackground(textWidget.getBackground());
- gc.setFont(textWidget.getFont());
- }
-
- @Override
- public void redraw() {
- // 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()) {
- // one of mining is not resolved, resolve it and then redraw the annotation.
- mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
- this.redraw();
- });
- return;
- }
- }
- // all minings are resolved, redraw the annotation
- super.redraw();
- }
-
- @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;
- }
-}
+/**
+ * Copyright (c) 2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
+ */
+package org.eclipse.jface.internal.text.codemining;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.codemining.ICodeMining;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
+
+/**
+ * Code Mining annotation in line header.
+ *
+ * @since 3.13
+ */
+public class CodeMiningLineHeaderAnnotation extends LineHeaderAnnotation implements ICodeMiningAnnotation {
+
+ private static final String SEPARATOR= " | "; //$NON-NLS-1$
+
+ /**
+ * List of resolved minings which contains current resolved minings and last resolved minings
+ * and null if mining is not resolved.
+ */
+ private ICodeMining[] fResolvedMinings;
+
+ /**
+ * List of current resolved/unresolved minings
+ */
+ private final List<ICodeMining> fMinings;
+
+ /**
+ * List of bounds minings
+ */
+ private final List<Rectangle> fBounds;
+
+ /**
+ * The current progress monitor
+ */
+ private IProgressMonitor fMonitor;
+
+ /**
+ * Code mining annotation constructor.
+ *
+ * @param position the position
+ * @param viewer the viewer
+ */
+ public CodeMiningLineHeaderAnnotation(Position position, ISourceViewer viewer) {
+ super(position, viewer);
+ fResolvedMinings= null;
+ fMinings= new ArrayList<>();
+ fBounds= new ArrayList<>();
+ }
+
+ @Override
+ public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
+ 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
+ public void markDeleted(boolean deleted) {
+ super.markDeleted(deleted);
+ if (deleted) {
+ disposeMinings();
+ fResolvedMinings= null;
+ }
+ }
+
+ private void disposeMinings() {
+ fMinings.stream().forEach(ICodeMining::dispose);
+ fMinings.clear();
+ }
+
+ @Override
+ public void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
+ List<ICodeMining> minings= new ArrayList<>(fMinings);
+ int nbDraw= 0;
+ int separatorWidth= -1;
+ boolean redrawn= false;
+ fBounds.clear();
+ for (int i= 0; i < minings.size(); i++) {
+ ICodeMining mining= minings.get(i);
+ if (!mining.isResolved()) {
+ // the mining is not resolved.
+ if (!redrawn) {
+ // redraw the annotation when mining is resolved.
+ redraw();
+ redrawn= true;
+ }
+ // try to get the last resolved mining.
+ if (fResolvedMinings != null) {
+ 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;
+ }
+ // draw the mining
+ if (nbDraw > 0) {
+ initGC(textWidget, color, gc);
+ gc.drawText(SEPARATOR, x, y);
+ if (separatorWidth == -1) {
+ separatorWidth= gc.stringExtent(SEPARATOR).x;
+ }
+ x+= separatorWidth;
+ }
+ initGC(textWidget, color, gc);
+ Point loc= mining.draw(gc, textWidget, color, x, y);
+ fBounds.add(new Rectangle(x, y, loc.x, loc.y));
+ x+= loc.x;
+ nbDraw++;
+ }
+ }
+
+ /**
+ * 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
+ */
+ private void initGC(StyledText textWidget, Color color, GC gc) {
+ gc.setForeground(color);
+ gc.setBackground(textWidget.getBackground());
+ gc.setFont(textWidget.getFont());
+ }
+
+ @Override
+ public void redraw() {
+ // 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()) {
+ // one of mining is not resolved, resolve it and then redraw the annotation.
+ mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
+ this.redraw();
+ });
+ return;
+ }
+ }
+ // all minings are resolved, redraw the annotation
+ super.redraw();
+ }
+
+ @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;
+ }
+}
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 dfd406f63c7..4989f3ebda7 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
@@ -32,6 +32,7 @@ import org.eclipse.jface.text.JFaceTextUtil;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.codemining.ICodeMining;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
+import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
import org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport;
@@ -143,7 +144,7 @@ public class CodeMiningManager implements Runnable {
* @param ann the codemining annotation
* @return true if the given annotation is in visible lines and false otherwise.
*/
- public boolean isInVisibleLines(CodeMiningAnnotation ann) {
+ public boolean isInVisibleLines(AbstractInlinedAnnotation ann) {
return ann.getPosition().getOffset() >= startOffset && ann.getPosition().getOffset() <= endOffset;
}
}
@@ -292,7 +293,7 @@ public class CodeMiningManager implements Runnable {
// done.
return;
}
- Set<CodeMiningAnnotation> annotationsToRedraw= new HashSet<>();
+ Set<ICodeMiningAnnotation> annotationsToRedraw= new HashSet<>();
Set<AbstractInlinedAnnotation> currentAnnotations= new HashSet<>();
// Loop for grouped code minings
groups.entrySet().stream().forEach(g -> {
@@ -301,16 +302,17 @@ public class CodeMiningManager implements Runnable {
Position pos= new Position(g.getKey().offset, g.getKey().length);
List<ICodeMining> minings= g.getValue();
+ boolean inLineHeader= minings.size() > 0 ? (minings.get(0) instanceof LineHeaderCodeMining) : true;
// Try to find existing annotation
- CodeMiningAnnotation ann= fInlinedAnnotationSupport.findExistingAnnotation(pos);
+ AbstractInlinedAnnotation ann= fInlinedAnnotationSupport.findExistingAnnotation(pos);
if (ann == null) {
// The annotation doesn't exists, create it.
- ann= new CodeMiningAnnotation(pos, viewer);
- } else if (visibleLines.isInVisibleLines(ann)) {
+ ann= inLineHeader ? new CodeMiningLineHeaderAnnotation(pos, viewer) : new CodeMiningLineContentAnnotation(pos, viewer);
+ } else if (visibleLines.isInVisibleLines(ann) && ann instanceof ICodeMiningAnnotation) {
// annotation is in visible lines
- annotationsToRedraw.add(ann);
+ annotationsToRedraw.add((ICodeMiningAnnotation) ann);
}
- ann.update(minings, monitor);
+ ((ICodeMiningAnnotation) ann).update(minings, monitor);
currentAnnotations.add(ann);
});
// check if request was canceled.
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/ICodeMiningAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/ICodeMiningAnnotation.java
new file mode 100644
index 00000000000..db284174eb4
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/ICodeMiningAnnotation.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2018, Angelo ZERR and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] CodeMining should support line header/content annotation type both - Bug 529115
+ */
+package org.eclipse.jface.internal.text.codemining;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.codemining.ICodeMining;
+
+/**
+ * Internal Code Mining annotation API used by the {@link CodeMiningManager}.
+ *
+ * @since 3.13
+ */
+public interface ICodeMiningAnnotation {
+
+ /**
+ * Update code minings.
+ *
+ * @param minings the minings to update.
+ * @param monitor the monitor
+ */
+ void update(List<ICodeMining> minings, IProgressMonitor monitor);
+
+ /**
+ * Redraw the codemining annotation.
+ */
+ void 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 ad02629c3e4..12862f771cd 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
@@ -21,11 +21,8 @@ import org.eclipse.swt.graphics.Point;
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.Position;
-import org.eclipse.jface.text.source.inlined.Positions;
/**
* Abstract class for {@link ICodeMining}.
@@ -60,31 +57,14 @@ public abstract class AbstractCodeMining implements ICodeMining {
private final Consumer<MouseEvent> action;
/**
- * CodeMining constructor to locate the code mining before the given line number.
+ * CodeMining constructor to locate the code mining in a given position.
*
- * @param beforeLineNumber the line number where codemining must be drawn. Use 0 if you wish to
- * locate the code mining before the first line number (1).
- * @param document the document.
- * @param provider the owner codemining provider which creates this mining.
- * @throws BadLocationException when line number doesn't exists
- */
- public AbstractCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider) throws BadLocationException {
- this(beforeLineNumber, document, provider, null);
- }
-
- /**
- * CodeMining constructor to locate the code mining before the given line number.
- *
- * @param beforeLineNumber the line number where codemining must be drawn. Use 0 if you wish to
- * locate the code mining before the first line number (1).
- * @param document the document.
+ * @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.
- * @throws BadLocationException when line number doesn't exists
*/
- public AbstractCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider, Consumer<MouseEvent> action)
- throws BadLocationException {
- this.position= Positions.of(beforeLineNumber, document, true);
+ protected AbstractCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) {
+ this.position= position;
this.provider= provider;
this.action= action;
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineContentCodeMining.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineContentCodeMining.java
new file mode 100644
index 00000000000..8b0b31a00a4
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineContentCodeMining.java
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2018, Angelo ZERR and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] CodeMining should support line header/content annotation type both - Bug 529115
+ */
+package org.eclipse.jface.text.codemining;
+
+import java.util.function.Consumer;
+
+import org.eclipse.swt.events.MouseEvent;
+
+import org.eclipse.jface.text.Position;
+
+/**
+ * Abstract class for line content code mining.
+ *
+ */
+public abstract class LineContentCodeMining extends AbstractCodeMining {
+
+ /**
+ * 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.
+ */
+ public LineContentCodeMining(Position position, ICodeMiningProvider provider) {
+ this(position, provider, null);
+ }
+
+ /**
+ * 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.
+ */
+ public LineContentCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) {
+ super(position, provider, action);
+ }
+
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineHeaderCodeMining.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineHeaderCodeMining.java
new file mode 100644
index 00000000000..f7b4911ffb4
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/LineHeaderCodeMining.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2018, Angelo ZERR and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] CodeMining should support line header/content annotation type both - Bug 529115
+ */
+package org.eclipse.jface.text.codemining;
+
+import java.util.function.Consumer;
+
+import org.eclipse.swt.events.MouseEvent;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.inlined.Positions;
+
+/**
+ * Abstract class for line header code mining.
+ *
+ */
+public abstract class LineHeaderCodeMining extends AbstractCodeMining {
+
+ /**
+ * CodeMining constructor to locate the code mining before the given line number.
+ *
+ * @param beforeLineNumber the line number where codemining must be drawn. Use 0 if you wish to
+ * locate the code mining before the first line number (1).
+ * @param document the document.
+ * @param provider the owner codemining provider which creates this mining.
+ * @throws BadLocationException when line number doesn't exists
+ */
+ public LineHeaderCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider) throws BadLocationException {
+ this(beforeLineNumber, document, provider, null);
+ }
+
+ /**
+ * CodeMining constructor to locate the code mining before the given line number.
+ *
+ * @param beforeLineNumber the line number where codemining must be drawn. Use 0 if you wish to
+ * locate the code mining before the first line number (1).
+ * @param document the document.
+ * @param provider the owner codemining provider which creates this mining.
+ * @param action the action to execute when mining is clicked and null otherwise.
+ * @throws BadLocationException when line number doesn't exists
+ */
+ public LineHeaderCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider, Consumer<MouseEvent> action)
+ throws BadLocationException {
+ super(Positions.of(beforeLineNumber, document, true), provider, action);
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java
index e46bd352e5a..6ceb9a4f357 100644
--- a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java
@@ -18,13 +18,13 @@ 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.AbstractCodeMining;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
+import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
/**
* Project reference mining.
*/
-public class ProjectReferenceCodeMining extends AbstractCodeMining {
+public class ProjectReferenceCodeMining extends LineHeaderCodeMining {
private final String projectName;

Back to the top