Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-05-18 20:45:17 +0000
committerPaul Pazderski2019-05-18 21:47:36 +0000
commit9e7f66919496659795478f8cd80804da71498fff (patch)
treeced476eaaaa4e1cb0d65f56c3b7852a908eee1f8 /org.eclipse.jface.text/src/org/eclipse/jface
parent51ef424212f4bf315ddbedade152ae861d836fd8 (diff)
downloadeclipse.platform.text-9e7f66919496659795478f8cd80804da71498fff.tar.gz
eclipse.platform.text-9e7f66919496659795478f8cd80804da71498fff.tar.xz
eclipse.platform.text-9e7f66919496659795478f8cd80804da71498fff.zip
Bug 547304 - [cleanup] Fix wrong line delimiters
This updates all Java files with wrong or mixed line delimiters to use Unix style delimiters. The change includes only whitespace formatting and no code changes. Change-Id: I970d212a3e4edb8a85c58901336551190dfd2164
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CancellationExceptionMonitor.java68
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java650
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMining.java302
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMiningProvider.java130
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningReconciler.java88
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningStrategy.java144
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java238
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMiningProvider.java90
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java308
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineHeaderAnnotation.java110
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/Positions.java124
11 files changed, 1126 insertions, 1126 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CancellationExceptionMonitor.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CancellationExceptionMonitor.java
index 41715bafdc1..0abbc752306 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CancellationExceptionMonitor.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CancellationExceptionMonitor.java
@@ -1,37 +1,37 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * 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.concurrent.CancellationException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-
-/**
- * {@link IProgressMonitor} which throws a {@link CancellationException} when
- * {@link IProgressMonitor#isCanceled()} returns true.
- *
- * @since 3.13
- */
-class CancellationExceptionMonitor extends NullProgressMonitor {
-
- @Override
- public boolean isCanceled() {
- boolean canceled= super.isCanceled();
- if (canceled) {
- throw new CancellationException();
- }
- return canceled;
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * 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.concurrent.CancellationException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+/**
+ * {@link IProgressMonitor} which throws a {@link CancellationException} when
+ * {@link IProgressMonitor#isCanceled()} returns true.
+ *
+ * @since 3.13
+ */
+class CancellationExceptionMonitor extends NullProgressMonitor {
+
+ @Override
+ public boolean isCanceled() {
+ boolean canceled= super.isCanceled();
+ if (canceled) {
+ throw new CancellationException();
+ }
+ return canceled;
+ }
+}
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 34e86434d7a..697a3a38765 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
@@ -1,325 +1,325 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
- *
- * 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
- *
- * 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.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-import org.osgi.framework.Bundle;
-
-import org.eclipse.swt.graphics.Rectangle;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-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;
-
-/**
- * Code Mining manager implementation.
- *
- * @since 3.13
- */
-public class CodeMiningManager implements Runnable {
-
- /**
- * The source viewer
- */
- private final ISourceViewer fViewer;
-
- /**
- * The inlined annotation support used to draw CodeMining in the line spacing.
- */
- private final InlinedAnnotationSupport fInlinedAnnotationSupport;
-
- /**
- * The list of codemining providers.
- */
- private List<ICodeMiningProvider> fCodeMiningProviders;
-
- /**
- * The current progress monitor.
- */
- private IProgressMonitor fMonitor;
-
- /**
- * Constructor of codemining manager with the given arguments.
- *
- * @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
- */
- public CodeMiningManager(ISourceViewer viewer, InlinedAnnotationSupport inlinedAnnotationSupport,
- ICodeMiningProvider[] codeMiningProviders) {
- Assert.isNotNull(viewer);
- Assert.isNotNull(inlinedAnnotationSupport);
- Assert.isNotNull(codeMiningProviders);
- fViewer= viewer;
- fInlinedAnnotationSupport= inlinedAnnotationSupport;
- setCodeMiningProviders(codeMiningProviders);
- }
-
- /**
- * Set the codemining providers.
- *
- * @param codeMiningProviders the codemining providers.
- */
- public void setCodeMiningProviders(ICodeMiningProvider[] codeMiningProviders) {
- cancel();
- if (fCodeMiningProviders != null) {
- fCodeMiningProviders.stream().forEach(ICodeMiningProvider::dispose);
- }
- fCodeMiningProviders= Arrays.asList(codeMiningProviders);
- }
-
- /**
- * Uninstalls this codemining manager.
- */
- public void uninstall() {
- cancel();
- if (fInlinedAnnotationSupport != null) {
- fInlinedAnnotationSupport.updateAnnotations(Collections.emptySet());
- }
- }
-
- /**
- * Collect, resolve and render the code minings of the viewer.
- */
- @Override
- public void run() {
- if (fViewer == null || fInlinedAnnotationSupport == null || fCodeMiningProviders == null
- || fCodeMiningProviders.size() == 0 || fViewer.getAnnotationModel() == null) {
- return;
- }
- // Cancel the last progress monitor to cancel last resolve and render of code
- // minings
- cancel();
- // Update the code minings
- updateCodeMinings();
- }
-
- /**
- * Update the code minings.
- */
- private void updateCodeMinings() {
- // Refresh the code minings by using the new progress monitor.
- fMonitor= new CancellationExceptionMonitor();
- IProgressMonitor monitor= fMonitor;
- // Collect the code minings for the viewer
- getCodeMinings(fViewer, fCodeMiningProviders, monitor).thenAccept(symbols -> {
- // check if request was canceled.
- monitor.isCanceled();
- // then group code minings by lines position
- Map<Position, List<ICodeMining>> groups= groupByLines(symbols, fCodeMiningProviders);
- // resolve and render code minings
- renderCodeMinings(groups, fViewer, monitor);
- });
- }
-
- /**
- * Cancel the codemining process.
- */
- private void cancel() {
- // Cancel the last progress monitor.
- if (fMonitor != null) {
- fMonitor.setCanceled(true);
- }
- }
-
- private static void logCodeMiningProviderException(Throwable e) {
- if (e != null && (e instanceof CancellationException || (e.getCause() != null && e.getCause() instanceof CancellationException))) {
- return;
- }
- String PLUGIN_ID= "org.eclipse.jface.text"; //$NON-NLS-1$
- Bundle plugin= Platform.getBundle(PLUGIN_ID);
- if (plugin != null) {
- // In OSGi context, uses Platform Text log
- ILog log= Platform.getLog(plugin);
- log.log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getMessage(), e));
- } else {
- // In java main context, print stack trace
- System.err.println("Error while code mining process: " + e.getMessage()); //$NON-NLS-1$
- }
- }
-
- /**
- * 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 providers the CodeMining list providers.
- * @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.
- */
- private static CompletableFuture<List<? extends ICodeMining>> getCodeMinings(ITextViewer viewer,
- List<ICodeMiningProvider> providers, IProgressMonitor monitor) {
- List<CompletableFuture<List<? extends ICodeMining>>> com= providers.stream()
- .map(provider -> provider.provideCodeMinings(viewer, monitor))
- .filter(c -> c != null)
- .map(future -> future.exceptionally(e -> {
- logCodeMiningProviderException(e);
- return Collections.emptyList();
- }))
- .collect(Collectors.toList());
- return CompletableFuture.allOf(com.toArray(new CompletableFuture[com.size()])).thenApply(
- v -> com.stream().map(CompletableFuture::join).flatMap(l -> l.stream()).collect(Collectors.toList()));
- }
-
- /**
- * 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.
- * @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,
- List<ICodeMiningProvider> providers) {
- // sort code minings by lineNumber and provider-rank if
- Collections.sort(codeMinings, (a, b) -> {
- if (a.getPosition().offset < b.getPosition().offset) {
- return -1;
- } else if (a.getPosition().offset > b.getPosition().offset) {
- return 1;
- } else if (providers.indexOf(a.getProvider()) < providers.indexOf(b.getProvider())) {
- return -1;
- } else if (providers.indexOf(a.getProvider()) > providers.indexOf(b.getProvider())) {
- return 1;
- } else {
- return 0;
- }
- });
- return codeMinings.stream().collect(Collectors.groupingBy(ICodeMining::getPosition, LinkedHashMap::new,
- Collectors.mapping(Function.identity(), Collectors.toList())));
- }
-
- /**
- * Render the codemining grouped by line position.
- *
- * @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,
- IProgressMonitor monitor) {
- // check if request was canceled.
- monitor.isCanceled();
- IDocument document= viewer != null ? viewer.getDocument() : null;
- if (document == null) {
- // this case comes from when editor is closed before codemining rendered is
- // done.
- return;
- }
- Set<ICodeMiningAnnotation> annotationsToRedraw= new HashSet<>();
- Set<AbstractInlinedAnnotation> currentAnnotations= new HashSet<>();
- // Loop for grouped code minings
- groups.entrySet().stream().forEach(g -> {
- // check if request was canceled.
- monitor.isCanceled();
-
- 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
- AbstractInlinedAnnotation ann= fInlinedAnnotationSupport.findExistingAnnotation(pos);
- if (ann == null) {
- // The annotation doesn't exists, create it.
- ann= inLineHeader ? new CodeMiningLineHeaderAnnotation(pos, viewer) : new CodeMiningLineContentAnnotation(pos, viewer);
- } else if (ann instanceof ICodeMiningAnnotation && ((ICodeMiningAnnotation) ann).isInVisibleLines()) {
- // annotation is in visible lines
- annotationsToRedraw.add((ICodeMiningAnnotation) ann);
- }
- ((ICodeMiningAnnotation) ann).update(minings, monitor);
- currentAnnotations.add(ann);
- });
- // check if request was canceled.
- monitor.isCanceled();
- fInlinedAnnotationSupport.updateAnnotations(currentAnnotations);
- // redraw the existing codemining annotations since their content can change
- 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;
- }
-}
+/**
+ * Copyright (c) 2017 Angelo ZERR.
+ *
+ * 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
+ *
+ * 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.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import org.osgi.framework.Bundle;
+
+import org.eclipse.swt.graphics.Rectangle;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+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;
+
+/**
+ * Code Mining manager implementation.
+ *
+ * @since 3.13
+ */
+public class CodeMiningManager implements Runnable {
+
+ /**
+ * The source viewer
+ */
+ private final ISourceViewer fViewer;
+
+ /**
+ * The inlined annotation support used to draw CodeMining in the line spacing.
+ */
+ private final InlinedAnnotationSupport fInlinedAnnotationSupport;
+
+ /**
+ * The list of codemining providers.
+ */
+ private List<ICodeMiningProvider> fCodeMiningProviders;
+
+ /**
+ * The current progress monitor.
+ */
+ private IProgressMonitor fMonitor;
+
+ /**
+ * Constructor of codemining manager with the given arguments.
+ *
+ * @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
+ */
+ public CodeMiningManager(ISourceViewer viewer, InlinedAnnotationSupport inlinedAnnotationSupport,
+ ICodeMiningProvider[] codeMiningProviders) {
+ Assert.isNotNull(viewer);
+ Assert.isNotNull(inlinedAnnotationSupport);
+ Assert.isNotNull(codeMiningProviders);
+ fViewer= viewer;
+ fInlinedAnnotationSupport= inlinedAnnotationSupport;
+ setCodeMiningProviders(codeMiningProviders);
+ }
+
+ /**
+ * Set the codemining providers.
+ *
+ * @param codeMiningProviders the codemining providers.
+ */
+ public void setCodeMiningProviders(ICodeMiningProvider[] codeMiningProviders) {
+ cancel();
+ if (fCodeMiningProviders != null) {
+ fCodeMiningProviders.stream().forEach(ICodeMiningProvider::dispose);
+ }
+ fCodeMiningProviders= Arrays.asList(codeMiningProviders);
+ }
+
+ /**
+ * Uninstalls this codemining manager.
+ */
+ public void uninstall() {
+ cancel();
+ if (fInlinedAnnotationSupport != null) {
+ fInlinedAnnotationSupport.updateAnnotations(Collections.emptySet());
+ }
+ }
+
+ /**
+ * Collect, resolve and render the code minings of the viewer.
+ */
+ @Override
+ public void run() {
+ if (fViewer == null || fInlinedAnnotationSupport == null || fCodeMiningProviders == null
+ || fCodeMiningProviders.size() == 0 || fViewer.getAnnotationModel() == null) {
+ return;
+ }
+ // Cancel the last progress monitor to cancel last resolve and render of code
+ // minings
+ cancel();
+ // Update the code minings
+ updateCodeMinings();
+ }
+
+ /**
+ * Update the code minings.
+ */
+ private void updateCodeMinings() {
+ // Refresh the code minings by using the new progress monitor.
+ fMonitor= new CancellationExceptionMonitor();
+ IProgressMonitor monitor= fMonitor;
+ // Collect the code minings for the viewer
+ getCodeMinings(fViewer, fCodeMiningProviders, monitor).thenAccept(symbols -> {
+ // check if request was canceled.
+ monitor.isCanceled();
+ // then group code minings by lines position
+ Map<Position, List<ICodeMining>> groups= groupByLines(symbols, fCodeMiningProviders);
+ // resolve and render code minings
+ renderCodeMinings(groups, fViewer, monitor);
+ });
+ }
+
+ /**
+ * Cancel the codemining process.
+ */
+ private void cancel() {
+ // Cancel the last progress monitor.
+ if (fMonitor != null) {
+ fMonitor.setCanceled(true);
+ }
+ }
+
+ private static void logCodeMiningProviderException(Throwable e) {
+ if (e != null && (e instanceof CancellationException || (e.getCause() != null && e.getCause() instanceof CancellationException))) {
+ return;
+ }
+ String PLUGIN_ID= "org.eclipse.jface.text"; //$NON-NLS-1$
+ Bundle plugin= Platform.getBundle(PLUGIN_ID);
+ if (plugin != null) {
+ // In OSGi context, uses Platform Text log
+ ILog log= Platform.getLog(plugin);
+ log.log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getMessage(), e));
+ } else {
+ // In java main context, print stack trace
+ System.err.println("Error while code mining process: " + e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * 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 providers the CodeMining list providers.
+ * @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.
+ */
+ private static CompletableFuture<List<? extends ICodeMining>> getCodeMinings(ITextViewer viewer,
+ List<ICodeMiningProvider> providers, IProgressMonitor monitor) {
+ List<CompletableFuture<List<? extends ICodeMining>>> com= providers.stream()
+ .map(provider -> provider.provideCodeMinings(viewer, monitor))
+ .filter(c -> c != null)
+ .map(future -> future.exceptionally(e -> {
+ logCodeMiningProviderException(e);
+ return Collections.emptyList();
+ }))
+ .collect(Collectors.toList());
+ return CompletableFuture.allOf(com.toArray(new CompletableFuture[com.size()])).thenApply(
+ v -> com.stream().map(CompletableFuture::join).flatMap(l -> l.stream()).collect(Collectors.toList()));
+ }
+
+ /**
+ * 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.
+ * @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,
+ List<ICodeMiningProvider> providers) {
+ // sort code minings by lineNumber and provider-rank if
+ Collections.sort(codeMinings, (a, b) -> {
+ if (a.getPosition().offset < b.getPosition().offset) {
+ return -1;
+ } else if (a.getPosition().offset > b.getPosition().offset) {
+ return 1;
+ } else if (providers.indexOf(a.getProvider()) < providers.indexOf(b.getProvider())) {
+ return -1;
+ } else if (providers.indexOf(a.getProvider()) > providers.indexOf(b.getProvider())) {
+ return 1;
+ } else {
+ return 0;
+ }
+ });
+ return codeMinings.stream().collect(Collectors.groupingBy(ICodeMining::getPosition, LinkedHashMap::new,
+ Collectors.mapping(Function.identity(), Collectors.toList())));
+ }
+
+ /**
+ * Render the codemining grouped by line position.
+ *
+ * @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,
+ IProgressMonitor monitor) {
+ // check if request was canceled.
+ monitor.isCanceled();
+ IDocument document= viewer != null ? viewer.getDocument() : null;
+ if (document == null) {
+ // this case comes from when editor is closed before codemining rendered is
+ // done.
+ return;
+ }
+ Set<ICodeMiningAnnotation> annotationsToRedraw= new HashSet<>();
+ Set<AbstractInlinedAnnotation> currentAnnotations= new HashSet<>();
+ // Loop for grouped code minings
+ groups.entrySet().stream().forEach(g -> {
+ // check if request was canceled.
+ monitor.isCanceled();
+
+ 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
+ AbstractInlinedAnnotation ann= fInlinedAnnotationSupport.findExistingAnnotation(pos);
+ if (ann == null) {
+ // The annotation doesn't exists, create it.
+ ann= inLineHeader ? new CodeMiningLineHeaderAnnotation(pos, viewer) : new CodeMiningLineContentAnnotation(pos, viewer);
+ } else if (ann instanceof ICodeMiningAnnotation && ((ICodeMiningAnnotation) ann).isInVisibleLines()) {
+ // annotation is in visible lines
+ annotationsToRedraw.add((ICodeMiningAnnotation) ann);
+ }
+ ((ICodeMiningAnnotation) ann).update(minings, monitor);
+ currentAnnotations.add(ann);
+ });
+ // check if request was canceled.
+ monitor.isCanceled();
+ fInlinedAnnotationSupport.updateAnnotations(currentAnnotations);
+ // redraw the existing codemining annotations since their content can change
+ 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;
+ }
+}
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 da4ede56fb2..337824fbc18 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
@@ -1,154 +1,154 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
- */
-package org.eclipse.jface.text.codemining;
-
-import java.util.concurrent.CompletableFuture;
-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.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-
-/**
- * Abstract class for {@link ICodeMining}.
- *
- * @since 3.13
- */
-public abstract class AbstractCodeMining implements ICodeMining {
-
- /**
- * The position where codemining must be drawn
- */
- private final Position position;
-
- /**
- * The owner codemining provider which creates this mining.
- */
- private final ICodeMiningProvider provider;
-
- /**
- * The future used to resolve mining.
- */
- private CompletableFuture<Void> resolveFuture;
-
- /**
- * The label of the resolved codemining.
- */
- private String label;
-
- /**
- * The action to execute when mining is clicked and null otherwise.
- */
- private final Consumer<MouseEvent> action;
-
- /**
- * 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.
- */
- protected AbstractCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) {
- this.position= position;
- this.provider= provider;
- this.action= action;
- }
-
- @Override
- public Position getPosition() {
- return position;
- }
-
- @Override
- public ICodeMiningProvider getProvider() {
- return provider;
- }
-
- @Override
- public String getLabel() {
- return label;
- }
-
- /**
- * Set the label mining.
- *
- * @param label the label mining.
- */
- public void setLabel(String label) {
- this.label= label;
- }
-
- @Override
- public final CompletableFuture<Void> resolve(ITextViewer viewer, IProgressMonitor monitor) {
- if (resolveFuture == null) {
- resolveFuture= doResolve(viewer, monitor);
- }
- return resolveFuture;
- }
-
- /**
- * Returns the future which resolved the content of mining and null otherwise. By default, the
- * resolve do nothing.
- *
- * @param viewer the viewer
- * @param monitor the monitor
- * @return the future which resolved the content of mining and null otherwise.
- */
- protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
- return CompletableFuture.completedFuture(null);
- }
-
- @Override
- public boolean isResolved() {
- return (resolveFuture != null && resolveFuture.isDone());
- }
-
- @Override
- public void dispose() {
- if (resolveFuture != null) {
- resolveFuture.cancel(true);
- resolveFuture= null;
- }
- }
-
- /**
- * Draw the {@link #getLabel()} of mining with gray color. User can override this method to draw
- * anything.
- *
- * @param gc the graphics context
- * @param textWidget the text widget to draw on
- * @param color the color of the line
- * @param x the x position of the annotation
- * @param y the y position of the annotation
- * @return the size of the draw of mining.
- */
- @Override
- public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
- String title= getLabel() != null ? getLabel() : "no command"; //$NON-NLS-1$
- gc.drawString(title, x, y, true);
- return gc.stringExtent(title);
- }
-
- @Override
- public Consumer<MouseEvent> getAction() {
- return action;
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
+ */
+package org.eclipse.jface.text.codemining;
+
+import java.util.concurrent.CompletableFuture;
+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.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+
+/**
+ * Abstract class for {@link ICodeMining}.
+ *
+ * @since 3.13
+ */
+public abstract class AbstractCodeMining implements ICodeMining {
+
+ /**
+ * The position where codemining must be drawn
+ */
+ private final Position position;
+
+ /**
+ * The owner codemining provider which creates this mining.
+ */
+ private final ICodeMiningProvider provider;
+
+ /**
+ * The future used to resolve mining.
+ */
+ private CompletableFuture<Void> resolveFuture;
+
+ /**
+ * The label of the resolved codemining.
+ */
+ private String label;
+
+ /**
+ * The action to execute when mining is clicked and null otherwise.
+ */
+ private final Consumer<MouseEvent> action;
+
+ /**
+ * 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.
+ */
+ protected AbstractCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) {
+ this.position= position;
+ this.provider= provider;
+ this.action= action;
+ }
+
+ @Override
+ public Position getPosition() {
+ return position;
+ }
+
+ @Override
+ public ICodeMiningProvider getProvider() {
+ return provider;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * Set the label mining.
+ *
+ * @param label the label mining.
+ */
+ public void setLabel(String label) {
+ this.label= label;
+ }
+
+ @Override
+ public final CompletableFuture<Void> resolve(ITextViewer viewer, IProgressMonitor monitor) {
+ if (resolveFuture == null) {
+ resolveFuture= doResolve(viewer, monitor);
+ }
+ return resolveFuture;
+ }
+
+ /**
+ * Returns the future which resolved the content of mining and null otherwise. By default, the
+ * resolve do nothing.
+ *
+ * @param viewer the viewer
+ * @param monitor the monitor
+ * @return the future which resolved the content of mining and null otherwise.
+ */
+ protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
+ return CompletableFuture.completedFuture(null);
+ }
+
+ @Override
+ public boolean isResolved() {
+ return (resolveFuture != null && resolveFuture.isDone());
+ }
+
+ @Override
+ public void dispose() {
+ if (resolveFuture != null) {
+ resolveFuture.cancel(true);
+ resolveFuture= null;
+ }
+ }
+
+ /**
+ * Draw the {@link #getLabel()} of mining with gray color. User can override this method to draw
+ * anything.
+ *
+ * @param gc the graphics context
+ * @param textWidget the text widget to draw on
+ * @param color the color of the line
+ * @param x the x position of the annotation
+ * @param y the y position of the annotation
+ * @return the size of the draw of mining.
+ */
+ @Override
+ public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
+ String title= getLabel() != null ? getLabel() : "no command"; //$NON-NLS-1$
+ gc.drawString(title, x, y, true);
+ return gc.stringExtent(title);
+ }
+
+ @Override
+ public Consumer<MouseEvent> getAction() {
+ return action;
+ }
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMiningProvider.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMiningProvider.java
index b95b39a0f1d..87cd90d9239 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMiningProvider.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/AbstractCodeMiningProvider.java
@@ -1,68 +1,68 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
- */
-package org.eclipse.jface.text.codemining;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-
-/**
- * A codemining provider that can provide adapters through a context that can be set by the creator
- * of this codemining provider.
- * <p>
- * Clients may subclass.
- * </p>
- *
- * @since 3.13
- */
-public abstract class AbstractCodeMiningProvider implements ICodeMiningProvider {
-
- /**
- * The context of this codemining provider.
- */
- private IAdaptable context;
-
- /**
- * Sets this codemining provider's context which is responsible to provide the adapters.
- *
- * @param context the context for this codemining provider
- * @throws IllegalArgumentException if the context is <code>null</code>
- * @throws IllegalStateException if this method is called more than once
- */
- public final void setContext(IAdaptable context) throws IllegalStateException, IllegalArgumentException {
- Assert.isLegal(context != null);
- if (this.context != null)
- throw new IllegalStateException();
- this.context= context;
- }
-
- @Override
- public void dispose() {
- context= null;
- }
-
- /**
- * Returns an object which is an instance of the given class and provides additional context for
- * this codemining provider.
- *
- * @param adapterClass the adapter class to look up
- * @return an instance that can be cast to the given class, or <code>null</code> if this object
- * does not have an adapter for the given class
- */
- protected final <T> T getAdapter(Class<T> adapterClass) {
- Assert.isLegal(adapterClass != null);
- if (context != null)
- return context.getAdapter(adapterClass);
- return null;
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
+ */
+package org.eclipse.jface.text.codemining;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * A codemining provider that can provide adapters through a context that can be set by the creator
+ * of this codemining provider.
+ * <p>
+ * Clients may subclass.
+ * </p>
+ *
+ * @since 3.13
+ */
+public abstract class AbstractCodeMiningProvider implements ICodeMiningProvider {
+
+ /**
+ * The context of this codemining provider.
+ */
+ private IAdaptable context;
+
+ /**
+ * Sets this codemining provider's context which is responsible to provide the adapters.
+ *
+ * @param context the context for this codemining provider
+ * @throws IllegalArgumentException if the context is <code>null</code>
+ * @throws IllegalStateException if this method is called more than once
+ */
+ public final void setContext(IAdaptable context) throws IllegalStateException, IllegalArgumentException {
+ Assert.isLegal(context != null);
+ if (this.context != null)
+ throw new IllegalStateException();
+ this.context= context;
+ }
+
+ @Override
+ public void dispose() {
+ context= null;
+ }
+
+ /**
+ * Returns an object which is an instance of the given class and provides additional context for
+ * this codemining provider.
+ *
+ * @param adapterClass the adapter class to look up
+ * @return an instance that can be cast to the given class, or <code>null</code> if this object
+ * does not have an adapter for the given class
+ */
+ protected final <T> T getAdapter(Class<T> adapterClass) {
+ Assert.isLegal(adapterClass != null);
+ if (context != null)
+ return context.getAdapter(adapterClass);
+ return null;
+ }
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningReconciler.java
index c83a2f8a1f7..afe0799b3b3 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningReconciler.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningReconciler.java
@@ -1,47 +1,47 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide extension point for CodeMining - Bug 528419
- */
-package org.eclipse.jface.text.codemining;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.reconciler.Reconciler;
-
-/**
- * A reconciler which update code minings.
- *
- * @since 3.13
- */
-public class CodeMiningReconciler extends Reconciler {
-
- private CodeMiningStrategy fStrategy;
-
- public CodeMiningReconciler() {
- super.setIsIncrementalReconciler(false);
- fStrategy= new CodeMiningStrategy();
- this.setReconcilingStrategy(fStrategy, IDocument.DEFAULT_CONTENT_TYPE);
- }
-
- @Override
- public void install(ITextViewer textViewer) {
- super.install(textViewer);
- fStrategy.install(textViewer);
- }
-
- @Override
- public void uninstall() {
- super.uninstall();
- fStrategy.uninstall();
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide extension point for CodeMining - Bug 528419
+ */
+package org.eclipse.jface.text.codemining;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.reconciler.Reconciler;
+
+/**
+ * A reconciler which update code minings.
+ *
+ * @since 3.13
+ */
+public class CodeMiningReconciler extends Reconciler {
+
+ private CodeMiningStrategy fStrategy;
+
+ public CodeMiningReconciler() {
+ super.setIsIncrementalReconciler(false);
+ fStrategy= new CodeMiningStrategy();
+ this.setReconcilingStrategy(fStrategy, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+
+ @Override
+ public void install(ITextViewer textViewer) {
+ super.install(textViewer);
+ fStrategy.install(textViewer);
+ }
+
+ @Override
+ public void uninstall() {
+ super.uninstall();
+ fStrategy.uninstall();
+ }
+
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningStrategy.java
index 2a36d76a243..50290aa106f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningStrategy.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/CodeMiningStrategy.java
@@ -1,75 +1,75 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide extension point for CodeMining - Bug 528419
- */
-package org.eclipse.jface.text.codemining;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.reconciler.DirtyRegion;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
-import org.eclipse.jface.text.source.ISourceViewerExtension5;
-
-/**
- * A reconciling strategy which updates code minings.
- *
- * @since 3.13
- */
-class CodeMiningStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
-
- private ISourceViewerExtension5 fViewer;
-
- public void install(ITextViewer viewer) {
- if (viewer instanceof ISourceViewerExtension5) {
- fViewer= (ISourceViewerExtension5) viewer;
- }
- }
-
- @Override
- public void initialReconcile() {
- // Do nothing
- // Initial reconcilation will happen when the SourceViewer
- // has initialized the code mining provider
- // see SourceViewer#ensureCodeMiningManagerInstalled
- }
-
- @Override
- public void reconcile(IRegion partition) {
- if (fViewer != null) {
- fViewer.updateCodeMinings();
- }
- }
-
- public void uninstall() {
- fViewer= null;
- }
-
- @Override
- public void setProgressMonitor(IProgressMonitor monitor) {
- // Do nothing
- }
-
- @Override
- public void setDocument(IDocument document) {
- // Do nothing
- }
-
- @Override
- public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
- // Do nothing
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide extension point for CodeMining - Bug 528419
+ */
+package org.eclipse.jface.text.codemining;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+import org.eclipse.jface.text.source.ISourceViewerExtension5;
+
+/**
+ * A reconciling strategy which updates code minings.
+ *
+ * @since 3.13
+ */
+class CodeMiningStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
+
+ private ISourceViewerExtension5 fViewer;
+
+ public void install(ITextViewer viewer) {
+ if (viewer instanceof ISourceViewerExtension5) {
+ fViewer= (ISourceViewerExtension5) viewer;
+ }
+ }
+
+ @Override
+ public void initialReconcile() {
+ // Do nothing
+ // Initial reconcilation will happen when the SourceViewer
+ // has initialized the code mining provider
+ // see SourceViewer#ensureCodeMiningManagerInstalled
+ }
+
+ @Override
+ public void reconcile(IRegion partition) {
+ if (fViewer != null) {
+ fViewer.updateCodeMinings();
+ }
+ }
+
+ public void uninstall() {
+ fViewer= null;
+ }
+
+ @Override
+ public void setProgressMonitor(IProgressMonitor monitor) {
+ // Do nothing
+ }
+
+ @Override
+ public void setDocument(IDocument document) {
+ // Do nothing
+ }
+
+ @Override
+ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+ // Do nothing
+ }
+
+}
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 c3b1ead49ce..540c6e29538 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
@@ -1,122 +1,122 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
- */
-package org.eclipse.jface.text.codemining;
-
-import java.util.concurrent.CompletableFuture;
-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.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-
-/**
- * A code mining represents a content (ex: label, icons) that should be shown along with source
- * text, like the number of references, a way to run tests (with run/debug icons), etc.
- *
- * A code mining is unresolved when no content (ex: label, icons) is associated to it. For
- * performance reasons the creation of a code mining and resolving should be done to two stages.
- *
- * @since 3.13
- */
-public interface ICodeMining {
-
- /**
- * Returns the line position where code mining must be displayed in the line spacing area.
- *
- * @return the line position where code mining must be displayed in the line spacing area.
- */
- Position getPosition();
-
- /**
- * Returns the owner provider which has created this mining.
- *
- * @return the owner provider which has created this mining.
- */
- ICodeMiningProvider getProvider();
-
- /**
- * Returns the label may be set early in the class lifecycle, or upon completion of the future
- * provided by {@link #resolve(ITextViewer, IProgressMonitor)} operation.
- *
- * <p>
- * The returned label can have several values:
- * <ul>
- * <li><code>null</code> when mining is not resolved</li>
- * <li><code>null</code> when mining is resolved means that mining was resolved with an error and it will not
- * be displayed.</li>
- * <li>empty when mining is resolved means that mining will not be displayed</li>
- * <li>non empty when mining must be displayed</li>
- * </ul>
- * </p>
- *
- * @return the label may be set early in the class lifecycle, or upon completion of the future
- * provided by {@link #resolve(ITextViewer, IProgressMonitor)} operation.
- */
- String getLabel();
-
- /**
- * Returns the future to resolve the content of mining, or
- * {@link CompletableFuture#completedFuture(Object)} if no such resolution is necessary (in
- * which case {#isResolved()} is expected to return <code>true</code>).
- *
- * @param viewer the viewer.
- * @param monitor the monitor.
- * @return the future to resolve the content of mining, or
- * {@link CompletableFuture#completedFuture(Object)} if no such resolution is necessary
- * (in which case {#isResolved()} is expected to return <code>true</code>).
- */
- CompletableFuture<Void> resolve(ITextViewer viewer, IProgressMonitor monitor);
-
- /**
- * Returns 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.
- *
- * @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.
- */
- boolean isResolved();
-
- /**
- * Draw the code mining.
- *
- * @param gc the graphics context
- * @param textWidget the text widget to draw on
- * @param color the color of the line
- * @param x the x position of the annotation
- * @param y the y position of the annotation
- * @return the size of the draw of mining.
- */
- Point draw(GC gc, StyledText textWidget, Color color, int x, int y);
-
- /**
- * Returns the action to execute when mining is clicked and null otherwise.
- *
- * @return the action to execute when mining is clicked and null otherwise.
- */
- Consumer<MouseEvent> getAction();
-
- /**
- * Dispose the mining. Typically shuts down or cancels all related asynchronous operations.
- */
- void dispose();
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
+ */
+package org.eclipse.jface.text.codemining;
+
+import java.util.concurrent.CompletableFuture;
+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.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+
+/**
+ * A code mining represents a content (ex: label, icons) that should be shown along with source
+ * text, like the number of references, a way to run tests (with run/debug icons), etc.
+ *
+ * A code mining is unresolved when no content (ex: label, icons) is associated to it. For
+ * performance reasons the creation of a code mining and resolving should be done to two stages.
+ *
+ * @since 3.13
+ */
+public interface ICodeMining {
+
+ /**
+ * Returns the line position where code mining must be displayed in the line spacing area.
+ *
+ * @return the line position where code mining must be displayed in the line spacing area.
+ */
+ Position getPosition();
+
+ /**
+ * Returns the owner provider which has created this mining.
+ *
+ * @return the owner provider which has created this mining.
+ */
+ ICodeMiningProvider getProvider();
+
+ /**
+ * Returns the label may be set early in the class lifecycle, or upon completion of the future
+ * provided by {@link #resolve(ITextViewer, IProgressMonitor)} operation.
+ *
+ * <p>
+ * The returned label can have several values:
+ * <ul>
+ * <li><code>null</code> when mining is not resolved</li>
+ * <li><code>null</code> when mining is resolved means that mining was resolved with an error and it will not
+ * be displayed.</li>
+ * <li>empty when mining is resolved means that mining will not be displayed</li>
+ * <li>non empty when mining must be displayed</li>
+ * </ul>
+ * </p>
+ *
+ * @return the label may be set early in the class lifecycle, or upon completion of the future
+ * provided by {@link #resolve(ITextViewer, IProgressMonitor)} operation.
+ */
+ String getLabel();
+
+ /**
+ * Returns the future to resolve the content of mining, or
+ * {@link CompletableFuture#completedFuture(Object)} if no such resolution is necessary (in
+ * which case {#isResolved()} is expected to return <code>true</code>).
+ *
+ * @param viewer the viewer.
+ * @param monitor the monitor.
+ * @return the future to resolve the content of mining, or
+ * {@link CompletableFuture#completedFuture(Object)} if no such resolution is necessary
+ * (in which case {#isResolved()} is expected to return <code>true</code>).
+ */
+ CompletableFuture<Void> resolve(ITextViewer viewer, IProgressMonitor monitor);
+
+ /**
+ * Returns 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.
+ *
+ * @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.
+ */
+ boolean isResolved();
+
+ /**
+ * Draw the code mining.
+ *
+ * @param gc the graphics context
+ * @param textWidget the text widget to draw on
+ * @param color the color of the line
+ * @param x the x position of the annotation
+ * @param y the y position of the annotation
+ * @return the size of the draw of mining.
+ */
+ Point draw(GC gc, StyledText textWidget, Color color, int x, int y);
+
+ /**
+ * Returns the action to execute when mining is clicked and null otherwise.
+ *
+ * @return the action to execute when mining is clicked and null otherwise.
+ */
+ Consumer<MouseEvent> getAction();
+
+ /**
+ * Dispose the mining. Typically shuts down or cancels all related asynchronous operations.
+ */
+ void dispose();
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMiningProvider.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMiningProvider.java
index 987d1223665..ef91c0c8943 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMiningProvider.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMiningProvider.java
@@ -1,48 +1,48 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
- */
-package org.eclipse.jface.text.codemining;
-
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.ITextViewer;
-
-/**
- * A code mining provider adds minings {@link ICodeMining} to source text. The mining will be shown
- * as dedicated horizontal lines in between the source text.
- *
- * @since 3.13
- */
-public interface ICodeMiningProvider {
-
- /**
- * Compute a list of code minings {@link ICodeMining}. This call should return as fast as
- * possible and if computing the content of {@link ICodeMining} is expensive implementors should
- * only return code mining objects with the position and implement resolve
- * {@link ICodeMining#resolve(ITextViewer, IProgressMonitor)}.
- *
- * @param viewer the viewer in which the command was invoked.
- * @param monitor A progress monitor.
- * @return An array of future of code minings that resolves to such. The lack of a result can be
- * signaled by returning null, or an empty array.
- */
- CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor);
-
- /**
- * Dispose code mining provider.
- */
- void dispose();
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide CodeMining support with CodeMiningManager - Bug 527720
+ */
+package org.eclipse.jface.text.codemining;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.jface.text.ITextViewer;
+
+/**
+ * A code mining provider adds minings {@link ICodeMining} to source text. The mining will be shown
+ * as dedicated horizontal lines in between the source text.
+ *
+ * @since 3.13
+ */
+public interface ICodeMiningProvider {
+
+ /**
+ * Compute a list of code minings {@link ICodeMining}. This call should return as fast as
+ * possible and if computing the content of {@link ICodeMining} is expensive implementors should
+ * only return code mining objects with the position and implement resolve
+ * {@link ICodeMining#resolve(ITextViewer, IProgressMonitor)}.
+ *
+ * @param viewer the viewer in which the command was invoked.
+ * @param monitor A progress monitor.
+ * @return An array of future of code minings that resolves to such. The lack of a result can be
+ * signaled by returning null, or an empty array.
+ */
+ CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor);
+
+ /**
+ * Dispose code mining provider.
+ */
+ void dispose();
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java
index a7a898b7de9..6ec1ca33d2e 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java
@@ -1,157 +1,157 @@
-/**
- * Copyright (c) 2017, 2018 Angelo ZERR.
+/**
+ * Copyright (c) 2017, 2018 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
- */
-package org.eclipse.jface.text.source.inlined;
-
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.GlyphMetrics;
-
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-/**
- * Inlined annotation which is drawn in the line content and which takes some place with a given
- * width.
- *
- * @since 3.13
- */
-public class LineContentAnnotation extends AbstractInlinedAnnotation {
-
- /**
- * The annotation width
- */
- private int width;
-
- private int redrawnCharacterWidth;
-
- /**
- * Line content annotation constructor.
- *
- * @param position the position where the annotation must be drawn.
- * @param viewer the {@link ISourceViewer} where the annotation must be drawn.
- */
- public LineContentAnnotation(Position position, ISourceViewer viewer) {
- super(position, viewer);
- }
-
- /**
- * Returns the annotation width. By default it computes the well width for the text annotation.
- *
- * @return the annotation width.
- */
- public final int getWidth() {
- return width;
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * After drawn, compute the text width and update it.
- * </p>
- */
- @Override
- public final void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
- width= drawAndComputeWidth(gc, textWidget, offset, length, color, x, y);
- }
-
- /**
- * Draw the inlined annotation. By default it draws the text of the annotation with gray color.
- * User can override this method to draw anything.
- *
- * @param gc the graphics context
- * @param textWidget the text widget to draw on
- * @param offset the offset of the line
- * @param length the length of the line
- * @param color the color of the line
- * @param x the x position of the annotation
- * @param y the y position of the annotation
- * @return the text width.
- */
- protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
- // Draw the text annotation and returns the width
- super.draw(gc, textWidget, offset, length, color, x, y);
- return (int) (gc.stringExtent(getText()).x + 2 * gc.getFontMetrics().getAverageCharacterWidth());
- }
-
- int getRedrawnCharacterWidth() {
- return redrawnCharacterWidth;
- }
-
- void setRedrawnCharacterWidth(int redrawnCharacterWidth) {
- this.redrawnCharacterWidth= redrawnCharacterWidth;
- }
-
- @Override
- boolean contains(int x, int y) {
- return (x >= this.fX && x <= this.fX + width && y >= this.fY && y <= this.fY + getTextWidget().getLineHeight());
- }
-
- /**
- * Returns the style to apply with GlyphMetrics width only if needed.
- *
- * As it's using Widget position, the results can be passed directly to
- * {@link StyledText#setStyleRange(StyleRange)} and family. However, in case of a Viewer
- * providing project/folder with {@link ITextViewerExtension5}, the range must be transformed to
- * model position before passing it to a {@link TextPresentation}.
- *
- * @param style the current style and null otherwise.
- * @return the style to apply with GlyphMetrics width only if needed. It uses widget position,
- * not model position.
- */
- StyleRange updateStyle(StyleRange style) {
- Position widgetPosition= computeWidgetPosition();
- boolean usePreviousChar= drawRightToPreviousChar(widgetPosition.getOffset());
- if (width == 0 || getRedrawnCharacterWidth() == 0) {
- return null;
- }
- int fullWidth= width + getRedrawnCharacterWidth();
- if (style == null) {
- style= new StyleRange();
- style.start= widgetPosition.getOffset();
- if (usePreviousChar) {
- style.start--;
- }
- style.length= 1;
- }
- GlyphMetrics metrics= style.metrics;
- if (!isMarkedDeleted()) {
- if (metrics == null) {
- metrics= new GlyphMetrics(0, 0, fullWidth);
- } else {
- if (metrics.width == fullWidth) {
- return null;
- }
- /**
- * We must create a new GlyphMetrics instance because comparison with similarTo used
- * later in StyledText#setStyleRange will compare the same (modified) and won't
- * realize an update happened.
- */
- metrics= new GlyphMetrics(0, 0, fullWidth);
- }
- } else {
- metrics= null;
- }
- style.metrics= metrics;
- return style;
- }
-
- boolean drawRightToPreviousChar(int widgetOffset) {
- return widgetOffset > 0 && getTextWidget().getLineAtOffset(widgetOffset) == getTextWidget().getLineAtOffset(widgetOffset - 1);
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
+ */
+package org.eclipse.jface.text.source.inlined;
+
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.GlyphMetrics;
+
+import org.eclipse.jface.text.ITextViewerExtension5;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * Inlined annotation which is drawn in the line content and which takes some place with a given
+ * width.
+ *
+ * @since 3.13
+ */
+public class LineContentAnnotation extends AbstractInlinedAnnotation {
+
+ /**
+ * The annotation width
+ */
+ private int width;
+
+ private int redrawnCharacterWidth;
+
+ /**
+ * Line content annotation constructor.
+ *
+ * @param position the position where the annotation must be drawn.
+ * @param viewer the {@link ISourceViewer} where the annotation must be drawn.
+ */
+ public LineContentAnnotation(Position position, ISourceViewer viewer) {
+ super(position, viewer);
+ }
+
+ /**
+ * Returns the annotation width. By default it computes the well width for the text annotation.
+ *
+ * @return the annotation width.
+ */
+ public final int getWidth() {
+ return width;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * After drawn, compute the text width and update it.
+ * </p>
+ */
+ @Override
+ public final void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
+ width= drawAndComputeWidth(gc, textWidget, offset, length, color, x, y);
+ }
+
+ /**
+ * Draw the inlined annotation. By default it draws the text of the annotation with gray color.
+ * User can override this method to draw anything.
+ *
+ * @param gc the graphics context
+ * @param textWidget the text widget to draw on
+ * @param offset the offset of the line
+ * @param length the length of the line
+ * @param color the color of the line
+ * @param x the x position of the annotation
+ * @param y the y position of the annotation
+ * @return the text width.
+ */
+ protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
+ // Draw the text annotation and returns the width
+ super.draw(gc, textWidget, offset, length, color, x, y);
+ return (int) (gc.stringExtent(getText()).x + 2 * gc.getFontMetrics().getAverageCharacterWidth());
+ }
+
+ int getRedrawnCharacterWidth() {
+ return redrawnCharacterWidth;
+ }
+
+ void setRedrawnCharacterWidth(int redrawnCharacterWidth) {
+ this.redrawnCharacterWidth= redrawnCharacterWidth;
+ }
+
+ @Override
+ boolean contains(int x, int y) {
+ return (x >= this.fX && x <= this.fX + width && y >= this.fY && y <= this.fY + getTextWidget().getLineHeight());
+ }
+
+ /**
+ * Returns the style to apply with GlyphMetrics width only if needed.
+ *
+ * As it's using Widget position, the results can be passed directly to
+ * {@link StyledText#setStyleRange(StyleRange)} and family. However, in case of a Viewer
+ * providing project/folder with {@link ITextViewerExtension5}, the range must be transformed to
+ * model position before passing it to a {@link TextPresentation}.
+ *
+ * @param style the current style and null otherwise.
+ * @return the style to apply with GlyphMetrics width only if needed. It uses widget position,
+ * not model position.
+ */
+ StyleRange updateStyle(StyleRange style) {
+ Position widgetPosition= computeWidgetPosition();
+ boolean usePreviousChar= drawRightToPreviousChar(widgetPosition.getOffset());
+ if (width == 0 || getRedrawnCharacterWidth() == 0) {
+ return null;
+ }
+ int fullWidth= width + getRedrawnCharacterWidth();
+ if (style == null) {
+ style= new StyleRange();
+ style.start= widgetPosition.getOffset();
+ if (usePreviousChar) {
+ style.start--;
+ }
+ style.length= 1;
+ }
+ GlyphMetrics metrics= style.metrics;
+ if (!isMarkedDeleted()) {
+ if (metrics == null) {
+ metrics= new GlyphMetrics(0, 0, fullWidth);
+ } else {
+ if (metrics.width == fullWidth) {
+ return null;
+ }
+ /**
+ * We must create a new GlyphMetrics instance because comparison with similarTo used
+ * later in StyledText#setStyleRange will compare the same (modified) and won't
+ * realize an update happened.
+ */
+ metrics= new GlyphMetrics(0, 0, fullWidth);
+ }
+ } else {
+ metrics= null;
+ }
+ style.metrics= metrics;
+ return style;
+ }
+
+ boolean drawRightToPreviousChar(int widgetOffset) {
+ return widgetOffset > 0 && getTextWidget().getLineAtOffset(widgetOffset) == getTextWidget().getLineAtOffset(widgetOffset - 1);
+ }
+
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineHeaderAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineHeaderAnnotation.java
index 51cf13ec607..6f8d699d3b0 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineHeaderAnnotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineHeaderAnnotation.java
@@ -1,55 +1,55 @@
-/**
- * Copyright (c) 2017, 2018 Angelo ZERR.
- *
- * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
- */
-package org.eclipse.jface.text.source.inlined;
-
-import org.eclipse.swt.custom.StyledText;
-
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-/**
- * Inlined annotation which is drawn before a line and which takes some place with a given height.
- *
- * @since 3.13
- */
-public class LineHeaderAnnotation extends AbstractInlinedAnnotation {
-
- int oldLine;
-
- /**
- * Line header annotation constructor.
- *
- * @param position the position where the annotation must be drawn.
- * @param viewer the {@link ISourceViewer} where the annotation must be drawn.
- */
- public LineHeaderAnnotation(Position position, ISourceViewer viewer) {
- super(position, viewer);
- oldLine= -1;
- }
-
- /**
- * Returns the annotation height. By default, returns the {@link StyledText#getLineHeight()}.
- *
- * @return the annotation height.
- */
- public int getHeight() {
- StyledText styledText= super.getTextWidget();
- return styledText.getLineHeight();
- }
-
- @Override
- boolean contains(int x, int y) {
- return (x >= this.fX && y >= this.fY && y <= this.fY + getHeight());
- }
-}
+/**
+ * Copyright (c) 2017, 2018 Angelo ZERR.
+ *
+ * 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
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
+ */
+package org.eclipse.jface.text.source.inlined;
+
+import org.eclipse.swt.custom.StyledText;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * Inlined annotation which is drawn before a line and which takes some place with a given height.
+ *
+ * @since 3.13
+ */
+public class LineHeaderAnnotation extends AbstractInlinedAnnotation {
+
+ int oldLine;
+
+ /**
+ * Line header annotation constructor.
+ *
+ * @param position the position where the annotation must be drawn.
+ * @param viewer the {@link ISourceViewer} where the annotation must be drawn.
+ */
+ public LineHeaderAnnotation(Position position, ISourceViewer viewer) {
+ super(position, viewer);
+ oldLine= -1;
+ }
+
+ /**
+ * Returns the annotation height. By default, returns the {@link StyledText#getLineHeight()}.
+ *
+ * @return the annotation height.
+ */
+ public int getHeight() {
+ StyledText styledText= super.getTextWidget();
+ return styledText.getLineHeight();
+ }
+
+ @Override
+ boolean contains(int x, int y) {
+ return (x >= this.fX && y >= this.fY && y <= this.fY + getHeight());
+ }
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/Positions.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/Positions.java
index e3bf8dc6b18..a9bd09f2ca5 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/Positions.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/Positions.java
@@ -1,65 +1,65 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * 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
+ * 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
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
- */
-package org.eclipse.jface.text.source.inlined;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-
-/**
- * Utilities class to retrieve position.
- *
- * @since 3.13
- */
-public class Positions {
-
- /**
- * Returns the line position by taking care or not of of leading spaces.
- *
- * @param lineIndex the line index
- * @param document the document
- * @param leadingSpaces true if line spacing must take care of and not otherwise.
- * @return the line position by taking care of leading spaces.
- * @throws BadLocationException if the line number is invalid in this document
- */
- public static Position of(int lineIndex, IDocument document, boolean leadingSpaces) throws BadLocationException {
- int offset= document.getLineOffset(lineIndex);
- int lineLength= document.getLineLength(lineIndex);
- String line= document.get(offset, lineLength);
- if (leadingSpaces) {
- offset+= getLeadingSpaces(line);
- }
- return new Position(offset, 1);
- }
-
- /**
- * Returns the leading spaces of the given line text.
- *
- * @param line the line text.
- * @return the leading spaces of the given line text.
- */
- private static int getLeadingSpaces(String line) {
- int counter= 0;
- char[] chars= line.toCharArray();
- for (char c : chars) {
- if (c == '\t')
- counter++;
- else if (c == ' ')
- counter++;
- else
- break;
- }
- return counter;
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
+ */
+package org.eclipse.jface.text.source.inlined;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+
+/**
+ * Utilities class to retrieve position.
+ *
+ * @since 3.13
+ */
+public class Positions {
+
+ /**
+ * Returns the line position by taking care or not of of leading spaces.
+ *
+ * @param lineIndex the line index
+ * @param document the document
+ * @param leadingSpaces true if line spacing must take care of and not otherwise.
+ * @return the line position by taking care of leading spaces.
+ * @throws BadLocationException if the line number is invalid in this document
+ */
+ public static Position of(int lineIndex, IDocument document, boolean leadingSpaces) throws BadLocationException {
+ int offset= document.getLineOffset(lineIndex);
+ int lineLength= document.getLineLength(lineIndex);
+ String line= document.get(offset, lineLength);
+ if (leadingSpaces) {
+ offset+= getLeadingSpaces(line);
+ }
+ return new Position(offset, 1);
+ }
+
+ /**
+ * Returns the leading spaces of the given line text.
+ *
+ * @param line the line text.
+ * @return the leading spaces of the given line text.
+ */
+ private static int getLeadingSpaces(String line) {
+ int counter= 0;
+ char[] chars= line.toCharArray();
+ for (char c : chars) {
+ if (c == '\t')
+ counter++;
+ else if (c == ' ')
+ counter++;
+ else
+ break;
+ }
+ return counter;
+ }
+}

Back to the top