Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java')
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java
new file mode 100644
index 00000000000..f4039d9685b
--- /dev/null
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ToEchoWithHeaderAndInlineCodeMiningProvider.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2020, Red Hat Inc.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.eclipse.jface.text.examples.codemining;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
+import org.eclipse.jface.text.codemining.ICodeMining;
+import org.eclipse.jface.text.codemining.ICodeMiningProvider;
+import org.eclipse.jface.text.codemining.LineContentCodeMining;
+
+public class ToEchoWithHeaderAndInlineCodeMiningProvider extends AbstractCodeMiningProvider
+ implements ICodeMiningProvider {
+
+ private final String toEcho;
+
+ public ToEchoWithHeaderAndInlineCodeMiningProvider(String keyword) {
+ this.toEcho = keyword;
+ }
+
+ @Override
+ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
+ IProgressMonitor monitor) {
+ int index = 0;
+ List<ICodeMining> res = new ArrayList<>();
+ while ((index = viewer.getDocument().get().indexOf(toEcho, index)) != -1) {
+ index += toEcho.length();
+ res.add(new LineContentCodeMining(new Position(index, 1), this) {
+ @Override
+ public String getLabel() {
+ return toEcho;
+ }
+
+ @Override
+ public boolean isResolved() {
+ return true;
+ }
+ });
+ };
+ return CompletableFuture.completedFuture(res);
+ }
+
+}

Back to the top