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.examples
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.examples')
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/AbstractClassCodeMining.java94
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationCodeMining.java98
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationsCodeMiningProvider.java132
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMining.java142
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMiningProvider.java114
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java218
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorAnnotation.java254
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorStatusAnnotation.java62
-rw-r--r--org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java572
9 files changed, 843 insertions, 843 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 733a27c44b9..2d8a485fa39 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
@@ -1,50 +1,50 @@
-/**
- * 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] Add CodeMining support in SourceViewer - Bug 527515
- */
-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.ICodeMiningProvider;
-import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
-
-/**
- * Abstract class for class name mining.
- *
- */
-public abstract class AbstractClassCodeMining extends LineHeaderCodeMining {
-
- private final String className;
-
- public AbstractClassCodeMining(String className, int afterLineNumber, IDocument document,
- ICodeMiningProvider resolver) throws BadLocationException {
- super(afterLineNumber, document, resolver);
- this.className = className;
- }
-
- public String getClassName() {
- return className;
- }
-
- public static String getLineText(IDocument document, int line) {
- try {
- int lo = document.getLineOffset(line);
- int ll = document.getLineLength(line);
- return document.get(lo, ll);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
+ */
+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.ICodeMiningProvider;
+import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
+
+/**
+ * Abstract class for class name mining.
+ *
+ */
+public abstract class AbstractClassCodeMining extends LineHeaderCodeMining {
+
+ private final String className;
+
+ public AbstractClassCodeMining(String className, int afterLineNumber, IDocument document,
+ ICodeMiningProvider resolver) throws BadLocationException {
+ super(afterLineNumber, document, resolver);
+ this.className = className;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public static String getLineText(IDocument document, int line) {
+ try {
+ int lo = document.getLineOffset(line);
+ int ll = document.getLineLength(line);
+ return document.get(lo, ll);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationCodeMining.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationCodeMining.java
index 33614e469c1..3da9467362a 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationCodeMining.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationCodeMining.java
@@ -1,52 +1,52 @@
-/**
- * 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] Add CodeMining support in SourceViewer - Bug 527515
- */
-package org.eclipse.jface.text.examples.codemining;
-
-import java.util.concurrent.CompletableFuture;
-
-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.ICodeMiningProvider;
-
-/**
- * Class implementation mining.
- *
- */
-public class ClassImplementationCodeMining extends AbstractClassCodeMining {
-
- public ClassImplementationCodeMining(String className, int afterLineNumber, IDocument document,
- ICodeMiningProvider provider) throws BadLocationException {
- super(className, afterLineNumber, document, provider);
- }
-
- @Override
- protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
- return CompletableFuture.runAsync(() -> {
- IDocument document = viewer.getDocument();
- String className = super.getClassName();
- int refCount = 0;
- int lineCount = document.getNumberOfLines();
- for (int i = 0; i < lineCount; i++) {
- // check if request was canceled.
- monitor.isCanceled();
- String line = getLineText(document, i);
- refCount += line.contains("implements " + className) ? 1 : 0;
- }
- super.setLabel(refCount + " implementation");
- });
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
+ */
+package org.eclipse.jface.text.examples.codemining;
+
+import java.util.concurrent.CompletableFuture;
+
+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.ICodeMiningProvider;
+
+/**
+ * Class implementation mining.
+ *
+ */
+public class ClassImplementationCodeMining extends AbstractClassCodeMining {
+
+ public ClassImplementationCodeMining(String className, int afterLineNumber, IDocument document,
+ ICodeMiningProvider provider) throws BadLocationException {
+ super(className, afterLineNumber, document, provider);
+ }
+
+ @Override
+ protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
+ return CompletableFuture.runAsync(() -> {
+ IDocument document = viewer.getDocument();
+ String className = super.getClassName();
+ int refCount = 0;
+ int lineCount = document.getNumberOfLines();
+ for (int i = 0; i < lineCount; i++) {
+ // check if request was canceled.
+ monitor.isCanceled();
+ String line = getLineText(document, i);
+ refCount += line.contains("implements " + className) ? 1 : 0;
+ }
+ super.setLabel(refCount + " implementation");
+ });
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationsCodeMiningProvider.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationsCodeMiningProvider.java
index a313659cf16..065dc22beaf 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationsCodeMiningProvider.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassImplementationsCodeMiningProvider.java
@@ -1,69 +1,69 @@
-/**
- * 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] Add CodeMining support in SourceViewer - Bug 527515
- */
-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.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
-import org.eclipse.jface.text.codemining.ICodeMining;
-
-/**
- * Class implementation mining provider.
- *
- */
-public class ClassImplementationsCodeMiningProvider extends AbstractCodeMiningProvider {
-
- @Override
- public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
- IProgressMonitor monitor) {
- return CompletableFuture.supplyAsync(() -> {
- IDocument document = viewer.getDocument();
- List<ICodeMining> lenses = new ArrayList<>();
- int lineCount = document.getNumberOfLines();
- for (int i = 0; i < lineCount; i++) {
- // check if request was canceled.
- monitor.isCanceled();
- updateContentMining(i, document, "class ", lenses);
- updateContentMining(i, document, "interface ", lenses);
- }
- return lenses;
- });
- }
-
- private void updateContentMining(int lineIndex, IDocument document, String token, List<ICodeMining> lenses) {
- String line = AbstractClassCodeMining.getLineText(document, lineIndex).trim();
- int index = line.indexOf(token);
- if (index == 0) {
- String className = line.substring(index + token.length(), line.length());
- index = className.indexOf(" ");
- if (index != -1) {
- className = className.substring(0, index);
- }
- if (className.length() > 0) {
- try {
- lenses.add(new ClassImplementationCodeMining(className, lineIndex, document, this));
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
+ */
+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.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
+import org.eclipse.jface.text.codemining.ICodeMining;
+
+/**
+ * Class implementation mining provider.
+ *
+ */
+public class ClassImplementationsCodeMiningProvider extends AbstractCodeMiningProvider {
+
+ @Override
+ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
+ IProgressMonitor monitor) {
+ return CompletableFuture.supplyAsync(() -> {
+ IDocument document = viewer.getDocument();
+ List<ICodeMining> lenses = new ArrayList<>();
+ int lineCount = document.getNumberOfLines();
+ for (int i = 0; i < lineCount; i++) {
+ // check if request was canceled.
+ monitor.isCanceled();
+ updateContentMining(i, document, "class ", lenses);
+ updateContentMining(i, document, "interface ", lenses);
+ }
+ return lenses;
+ });
+ }
+
+ private void updateContentMining(int lineIndex, IDocument document, String token, List<ICodeMining> lenses) {
+ String line = AbstractClassCodeMining.getLineText(document, lineIndex).trim();
+ int index = line.indexOf(token);
+ if (index == 0) {
+ String className = line.substring(index + token.length(), line.length());
+ index = className.indexOf(" ");
+ if (index != -1) {
+ className = className.substring(0, index);
+ }
+ if (className.length() > 0) {
+ try {
+ lenses.add(new ClassImplementationCodeMining(className, lineIndex, document, this));
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMining.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMining.java
index c4a82ba1a2d..29151731d1c 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMining.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMining.java
@@ -1,74 +1,74 @@
-/**
- * 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] Add CodeMining support in SourceViewer - Bug 527515
- */
-package org.eclipse.jface.text.examples.codemining;
-
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
-
-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.ICodeMiningProvider;
-
-/**
- * Class reference mining.
- *
- */
-public class ClassReferenceCodeMining extends AbstractClassCodeMining {
-
- private Object lock = new Object();
-
- public ClassReferenceCodeMining(String className, int afterLineNumber, IDocument document, ICodeMiningProvider provider)
- throws BadLocationException {
- super(className, afterLineNumber, document, provider);
- }
-
- @Override
- protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
- return CompletableFuture.runAsync(() -> {
- IDocument document = viewer.getDocument();
- String className = super.getClassName();
- try {
- int wait = Integer.parseInt(className);
- try {
- for (int i = 0; i < wait; i++) {
- monitor.isCanceled();
- synchronized (lock) {
- lock.wait(1000);
- }
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- } catch (NumberFormatException e) {
-
- } catch (CancellationException e) {
- e.printStackTrace();
- throw e;
- }
-
- int refCount = 0;
- int lineCount = document.getNumberOfLines();
- for (int i = 0; i < lineCount; i++) {
- // check if request was canceled.
- monitor.isCanceled();
- String line = getLineText(document, i);
- refCount += line.contains("new " + className) ? 1 : 0;
- }
- super.setLabel(refCount + " references");
- });
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
+ */
+package org.eclipse.jface.text.examples.codemining;
+
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletableFuture;
+
+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.ICodeMiningProvider;
+
+/**
+ * Class reference mining.
+ *
+ */
+public class ClassReferenceCodeMining extends AbstractClassCodeMining {
+
+ private Object lock = new Object();
+
+ public ClassReferenceCodeMining(String className, int afterLineNumber, IDocument document, ICodeMiningProvider provider)
+ throws BadLocationException {
+ super(className, afterLineNumber, document, provider);
+ }
+
+ @Override
+ protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
+ return CompletableFuture.runAsync(() -> {
+ IDocument document = viewer.getDocument();
+ String className = super.getClassName();
+ try {
+ int wait = Integer.parseInt(className);
+ try {
+ for (int i = 0; i < wait; i++) {
+ monitor.isCanceled();
+ synchronized (lock) {
+ lock.wait(1000);
+ }
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (NumberFormatException e) {
+
+ } catch (CancellationException e) {
+ e.printStackTrace();
+ throw e;
+ }
+
+ int refCount = 0;
+ int lineCount = document.getNumberOfLines();
+ for (int i = 0; i < lineCount; i++) {
+ // check if request was canceled.
+ monitor.isCanceled();
+ String line = getLineText(document, i);
+ refCount += line.contains("new " + className) ? 1 : 0;
+ }
+ super.setLabel(refCount + " references");
+ });
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMiningProvider.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMiningProvider.java
index 5bfc12234cc..203c0a54728 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMiningProvider.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/ClassReferenceCodeMiningProvider.java
@@ -1,60 +1,60 @@
-/**
- * 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] Add CodeMining support in SourceViewer - Bug 527515
- */
-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.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
-import org.eclipse.jface.text.codemining.ICodeMining;
-
-/**
- * Class reference mining provider.
- *
- */
-public class ClassReferenceCodeMiningProvider extends AbstractCodeMiningProvider {
-
- @Override
- public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
- IProgressMonitor monitor) {
- return CompletableFuture.supplyAsync(() -> {
- IDocument document = viewer.getDocument();
- List<ICodeMining> lenses = new ArrayList<>();
- int lineCount = document.getNumberOfLines();
- for (int i = 0; i < lineCount; i++) {
- // check if request was canceled.
- monitor.isCanceled();
- String line = AbstractClassCodeMining.getLineText(document, i).trim();
- int index = line.indexOf("class ");
- if (index == 0) {
- String className = line.substring(index + "class ".length(), line.length()).trim();
- if (className.length() > 0) {
- try {
- lenses.add(new ClassReferenceCodeMining(className, i, document, this));
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return lenses;
- });
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
+ */
+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.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
+import org.eclipse.jface.text.codemining.ICodeMining;
+
+/**
+ * Class reference mining provider.
+ *
+ */
+public class ClassReferenceCodeMiningProvider extends AbstractCodeMiningProvider {
+
+ @Override
+ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
+ IProgressMonitor monitor) {
+ return CompletableFuture.supplyAsync(() -> {
+ IDocument document = viewer.getDocument();
+ List<ICodeMining> lenses = new ArrayList<>();
+ int lineCount = document.getNumberOfLines();
+ for (int i = 0; i < lineCount; i++) {
+ // check if request was canceled.
+ monitor.isCanceled();
+ String line = AbstractClassCodeMining.getLineText(document, i).trim();
+ int index = line.indexOf("class ");
+ if (index == 0) {
+ String className = line.substring(index + "class ".length(), line.length()).trim();
+ if (className.length() > 0) {
+ try {
+ lenses.add(new ClassReferenceCodeMining(className, i, document, this));
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ return lenses;
+ });
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java
index 86b8d4f11e5..24da65a1a55 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/codemining/CodeMiningDemo.java
@@ -1,112 +1,112 @@
-/**
- * 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] Add CodeMining support in SourceViewer - Bug 527515
- */
-package org.eclipse.jface.text.examples.codemining;
-
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.codemining.ICodeMiningProvider;
-import org.eclipse.jface.text.reconciler.DirtyRegion;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
-import org.eclipse.jface.text.reconciler.MonoReconciler;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationModel;
-import org.eclipse.jface.text.source.AnnotationPainter;
-import org.eclipse.jface.text.source.IAnnotationAccess;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.ISourceViewerExtension5;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * A Code Mining demo with class references and implementations minings.
- *
- */
-public class CodeMiningDemo {
-
- public static void main(String[] args) throws Exception {
-
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- shell.setText("Code Mining demo");
-
- ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
- sourceViewer.setDocument(
- new Document("// Type class & new keyword and see references CodeMining\n"
- + "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n"
- + "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"),
- new AnnotationModel());
- // Add AnnotationPainter (required by CodeMining)
- addAnnotationPainter(sourceViewer);
- // Initialize codemining providers
- ((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] {
- new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
- // Execute codemining in a reconciler
- MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
-
- @Override
- public void setDocument(IDocument document) {
- ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
- }
-
- @Override
- public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
-
- }
-
- @Override
- public void reconcile(IRegion partition) {
- ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
- }
- }, false);
- reconciler.install(sourceViewer);
-
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-
- private static void addAnnotationPainter(ISourceViewer viewer) {
- IAnnotationAccess annotationAccess = new IAnnotationAccess() {
- @Override
- public Object getType(Annotation annotation) {
- return annotation.getType();
- }
-
- @Override
- public boolean isMultiLine(Annotation annotation) {
- return true;
- }
-
- @Override
- public boolean isTemporary(Annotation annotation) {
- return true;
- }
-
- };
- AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
- ((ITextViewerExtension2) viewer).addPainter(painter);
- // Register this annotation painter as CodeMining annotation painter.
- ((ISourceViewerExtension5) viewer).setCodeMiningAnnotationPainter(painter);
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
+ */
+package org.eclipse.jface.text.examples.codemining;
+
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.codemining.ICodeMiningProvider;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+import org.eclipse.jface.text.source.AnnotationPainter;
+import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.ISourceViewerExtension5;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A Code Mining demo with class references and implementations minings.
+ *
+ */
+public class CodeMiningDemo {
+
+ public static void main(String[] args) throws Exception {
+
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setText("Code Mining demo");
+
+ ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
+ sourceViewer.setDocument(
+ new Document("// Type class & new keyword and see references CodeMining\n"
+ + "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n"
+ + "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"),
+ new AnnotationModel());
+ // Add AnnotationPainter (required by CodeMining)
+ addAnnotationPainter(sourceViewer);
+ // Initialize codemining providers
+ ((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] {
+ new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
+ // Execute codemining in a reconciler
+ MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
+
+ @Override
+ public void setDocument(IDocument document) {
+ ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
+ }
+
+ @Override
+ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+
+ }
+
+ @Override
+ public void reconcile(IRegion partition) {
+ ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
+ }
+ }, false);
+ reconciler.install(sourceViewer);
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ private static void addAnnotationPainter(ISourceViewer viewer) {
+ IAnnotationAccess annotationAccess = new IAnnotationAccess() {
+ @Override
+ public Object getType(Annotation annotation) {
+ return annotation.getType();
+ }
+
+ @Override
+ public boolean isMultiLine(Annotation annotation) {
+ return true;
+ }
+
+ @Override
+ public boolean isTemporary(Annotation annotation) {
+ return true;
+ }
+
+ };
+ AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
+ ((ITextViewerExtension2) viewer).addPainter(painter);
+ // Register this annotation painter as CodeMining annotation painter.
+ ((ISourceViewerExtension5) viewer).setCodeMiningAnnotationPainter(painter);
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorAnnotation.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorAnnotation.java
index 315b7e5995f..9ff5dbdeaf9 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorAnnotation.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorAnnotation.java
@@ -1,130 +1,130 @@
-/**s
- * Copyright (c) 2017 Angelo ZERR.
+/**s
+ * 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.examples.sources.inlined;
-
-import java.util.function.Consumer;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
-import org.eclipse.jface.util.Geometry;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.ColorDialog;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * Color annotation displays a colorized square before the rgb declaration.
- */
-public class ColorAnnotation extends LineContentAnnotation {
-
- private Color color;
-
- private Consumer<MouseEvent> action = e -> {
- StyledText styledText = super.getTextWidget();
- Shell shell = new Shell(styledText.getDisplay());
- Rectangle location = Geometry.toDisplay(styledText, new Rectangle(e.x, e.y, 1, 1));
- shell.setLocation(location.x, location.y);
- // Open color dialog
- ColorDialog dialog = new ColorDialog(shell);
- // dialog.setRGB(annotation.getRGBA().rgb);
- RGB color = dialog.open();
- if (color != null) {
- // Color was selected, update the viewer
- try {
- int offset = getPosition().getOffset();
- IDocument document = getViewer().getDocument();
- IRegion line = document.getLineInformation(document.getLineOfOffset(offset));
- int length = line.getLength() - (offset - line.getOffset());
- String rgb = formatToRGB(color);
- document.replace(offset, length, rgb);
- } catch (BadLocationException e1) {
-
- }
- }
- };
-
- /**
- * Format the given rgb to hexa color.
- *
- * @param rgb
- * @return the hexa color from the given rgb.
- */
- private static String formatToRGB(RGB rgb) {
- return new StringBuilder("rgb(").append(rgb.red).append(",").append(rgb.green).append(",").append(rgb.blue)
- .append(")").toString();
- }
-
- public ColorAnnotation(Position pos, ISourceViewer viewer) {
- super(pos, viewer);
- }
-
- public void setColor(Color color) {
- this.color = color;
- }
-
- @Override
- protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
- FontMetrics fontMetrics = gc.getFontMetrics();
- int size = getSquareSize(fontMetrics);
- x += fontMetrics.getLeading();
- y += fontMetrics.getDescent();
-
- Rectangle rect = new Rectangle(x, y, size, size);
-
- // Fill square
- gc.setBackground(this.color);
- gc.fillRectangle(rect);
-
- // Draw square box
- gc.setForeground(textWidget.getForeground());
- gc.drawRectangle(rect);
- return getSquareWidth(gc.getFontMetrics());
- }
-
- /**
- * Returns the colorized square size.
- *
- * @param fontMetrics
- * @return the colorized square size.
- */
- public static int getSquareSize(FontMetrics fontMetrics) {
- return fontMetrics.getHeight() - 2 * fontMetrics.getDescent();
- }
-
- /**
- * Compute width of square
- *
- * @param styledText
- * @return the width of square
- */
- private static int getSquareWidth(FontMetrics fontMetrics) {
- // width = 2 spaces + size width of square
- int width = 2 * fontMetrics.getAverageCharWidth() + getSquareSize(fontMetrics);
- return width;
- }
-
- @Override
- public Consumer<MouseEvent> getAction(MouseEvent e) {
- return action;
- }
-}
+ * 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.examples.sources.inlined;
+
+import java.util.function.Consumer;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
+import org.eclipse.jface.util.Geometry;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Color annotation displays a colorized square before the rgb declaration.
+ */
+public class ColorAnnotation extends LineContentAnnotation {
+
+ private Color color;
+
+ private Consumer<MouseEvent> action = e -> {
+ StyledText styledText = super.getTextWidget();
+ Shell shell = new Shell(styledText.getDisplay());
+ Rectangle location = Geometry.toDisplay(styledText, new Rectangle(e.x, e.y, 1, 1));
+ shell.setLocation(location.x, location.y);
+ // Open color dialog
+ ColorDialog dialog = new ColorDialog(shell);
+ // dialog.setRGB(annotation.getRGBA().rgb);
+ RGB color = dialog.open();
+ if (color != null) {
+ // Color was selected, update the viewer
+ try {
+ int offset = getPosition().getOffset();
+ IDocument document = getViewer().getDocument();
+ IRegion line = document.getLineInformation(document.getLineOfOffset(offset));
+ int length = line.getLength() - (offset - line.getOffset());
+ String rgb = formatToRGB(color);
+ document.replace(offset, length, rgb);
+ } catch (BadLocationException e1) {
+
+ }
+ }
+ };
+
+ /**
+ * Format the given rgb to hexa color.
+ *
+ * @param rgb
+ * @return the hexa color from the given rgb.
+ */
+ private static String formatToRGB(RGB rgb) {
+ return new StringBuilder("rgb(").append(rgb.red).append(",").append(rgb.green).append(",").append(rgb.blue)
+ .append(")").toString();
+ }
+
+ public ColorAnnotation(Position pos, ISourceViewer viewer) {
+ super(pos, viewer);
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ @Override
+ protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
+ FontMetrics fontMetrics = gc.getFontMetrics();
+ int size = getSquareSize(fontMetrics);
+ x += fontMetrics.getLeading();
+ y += fontMetrics.getDescent();
+
+ Rectangle rect = new Rectangle(x, y, size, size);
+
+ // Fill square
+ gc.setBackground(this.color);
+ gc.fillRectangle(rect);
+
+ // Draw square box
+ gc.setForeground(textWidget.getForeground());
+ gc.drawRectangle(rect);
+ return getSquareWidth(gc.getFontMetrics());
+ }
+
+ /**
+ * Returns the colorized square size.
+ *
+ * @param fontMetrics
+ * @return the colorized square size.
+ */
+ public static int getSquareSize(FontMetrics fontMetrics) {
+ return fontMetrics.getHeight() - 2 * fontMetrics.getDescent();
+ }
+
+ /**
+ * Compute width of square
+ *
+ * @param styledText
+ * @return the width of square
+ */
+ private static int getSquareWidth(FontMetrics fontMetrics) {
+ // width = 2 spaces + size width of square
+ int width = 2 * fontMetrics.getAverageCharWidth() + getSquareSize(fontMetrics);
+ return width;
+ }
+
+ @Override
+ public Consumer<MouseEvent> getAction(MouseEvent e) {
+ return action;
+ }
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorStatusAnnotation.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorStatusAnnotation.java
index c3cd35d3019..b9faf06d335 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorStatusAnnotation.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/ColorStatusAnnotation.java
@@ -1,34 +1,34 @@
-/**
- * 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.examples.sources.inlined;
-
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
-
-/**
- * Color status annotation shows the result of rgb parse before each line which
- * defines 'color:'.
- */
-public class ColorStatusAnnotation extends LineHeaderAnnotation {
-
- public ColorStatusAnnotation(Position position, ISourceViewer viewer) {
- super(position, viewer);
- }
-
- public void setStatus(String status) {
- super.setText(status);
- }
-
-}
+ * 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.examples.sources.inlined;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
+
+/**
+ * Color status annotation shows the result of rgb parse before each line which
+ * defines 'color:'.
+ */
+public class ColorStatusAnnotation extends LineHeaderAnnotation {
+
+ public ColorStatusAnnotation(Position position, ISourceViewer viewer) {
+ super(position, viewer);
+ }
+
+ public void setStatus(String status) {
+ super.setText(status);
+ }
+
+}
diff --git a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java
index 803911c302c..d50d7e1466b 100644
--- a/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java
+++ b/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java
@@ -1,289 +1,289 @@
-/**
- * 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.examples.sources.inlined;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.reconciler.DirtyRegion;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
-import org.eclipse.jface.text.reconciler.MonoReconciler;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationModel;
-import org.eclipse.jface.text.source.AnnotationPainter;
-import org.eclipse.jface.text.source.IAnnotationAccess;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
-import org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport;
-import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
-import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
-import org.eclipse.jface.text.source.inlined.Positions;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * An inlined demo with {@link LineHeaderAnnotation} and
- * {@link LineContentAnnotation} annotations both:
- *
- * <ul>
- * <li>a status OK, NOK is displayed before the line which starts with 'color:'.
- * This status is the result of the content after 'color' which must be a rgb
- * content. Here {@link ColorStatusAnnotation} is used.</li>
- * <li>a colorized square is displayed before the rgb declaration (inside the
- * line content). Here {@link ColorAnnotation} is used.</li>
- * </ul>
- *
- */
-public class InlinedAnnotationDemo {
-
- public static void main(String[] args) throws Exception {
-
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- shell.setText("Inlined annotation demo");
-
- // Create source viewer and initialize the content
- ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
- sourceViewer.setDocument(new Document("\ncolor:rgb(255, 255, 0)"), new AnnotationModel());
-
- // Initialize inlined annotations support
- InlinedAnnotationSupport support = new InlinedAnnotationSupport();
- support.install(sourceViewer, createAnnotationPainter(sourceViewer));
-
- // Refresh inlined annotation in none UI Thread with reconciler.
- MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
-
- @Override
- public void setDocument(IDocument document) {
- Set<AbstractInlinedAnnotation> annotations = getInlinedAnnotation(sourceViewer, support);
- support.updateAnnotations(annotations);
- }
-
- @Override
- public void reconcile(IRegion partition) {
- Set<AbstractInlinedAnnotation> anns = getInlinedAnnotation(sourceViewer, support);
- support.updateAnnotations(anns);
- }
-
- @Override
- public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
-
- }
- }, false);
- reconciler.setDelay(1);
- reconciler.install(sourceViewer);
-
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-
- /**
- * Create annotation painter.
- *
- * @param viewer
- * the viewer.
- * @return annotation painter.
- */
- private static AnnotationPainter createAnnotationPainter(ISourceViewer viewer) {
- IAnnotationAccess annotationAccess = new IAnnotationAccess() {
- @Override
- public Object getType(Annotation annotation) {
- return annotation.getType();
- }
-
- @Override
- public boolean isMultiLine(Annotation annotation) {
- return true;
- }
-
- @Override
- public boolean isTemporary(Annotation annotation) {
- return true;
- }
-
- };
- AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
- ((ITextViewerExtension2) viewer).addPainter(painter);
- return painter;
- }
-
- /**
- * Returns the inlined annotations list to display in the given viewer.
- *
- * @param viewer
- * the viewer
- * @param support
- * the inlined annotation suppor.
- * @return the inlined annotations list to display in the given viewer.
- */
- private static Set<AbstractInlinedAnnotation> getInlinedAnnotation(ISourceViewer viewer,
- InlinedAnnotationSupport support) {
- IDocument document = viewer.getDocument();
- Set<AbstractInlinedAnnotation> annotations = new HashSet<>();
- int lineCount = document.getNumberOfLines();
- for (int i = 0; i < lineCount; i++) {
- String line = getLineText(document, i).trim();
- int index = line.indexOf("color:");
- if (index == 0) {
- String rgb = line.substring(index + "color:".length(), line.length()).trim();
- try {
- String status = "OK!";
- Color color = parse(rgb, viewer.getTextWidget().getDisplay());
- if (color != null) {
- } else {
- status = "ERROR!";
- }
- // Status color annotation
- Position pos = Positions.of(i, document, true);
- ColorStatusAnnotation statusAnnotation = support.findExistingAnnotation(pos);
- if (statusAnnotation == null) {
- statusAnnotation = new ColorStatusAnnotation(pos, viewer);
- }
- statusAnnotation.setStatus(status);
- annotations.add(statusAnnotation);
-
- // Color annotation
- if (color != null) {
- Position colorPos = new Position(pos.offset + index + "color:".length(), 1);
- ColorAnnotation colorAnnotation = support.findExistingAnnotation(colorPos);
- if (colorAnnotation == null) {
- colorAnnotation = new ColorAnnotation(colorPos, viewer);
- }
- colorAnnotation.setColor(color);
- annotations.add(colorAnnotation);
- }
-
- // rgb parameter names annotations
- int rgbIndex = line.indexOf("rgb");
- if (rgbIndex != -1) {
- rgbIndex = rgbIndex + "rgb".length();
- int startOffset = pos.offset + rgbIndex;
- String rgbContent = line.substring(rgbIndex, line.length());
- int startIndex = addRGBParamNameAnnotation("red:", rgbContent, 0, startOffset, viewer, support,
- annotations);
- if (startIndex != -1) {
- startIndex = addRGBParamNameAnnotation("green:", rgbContent, startIndex, startOffset, viewer,
- support, annotations);
- if (startIndex != -1) {
- startIndex = addRGBParamNameAnnotation("blue:", rgbContent, startIndex, startOffset,
- viewer, support, annotations);
- }
- }
- }
-
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- }
- }
- return annotations;
- }
-
- /**
- * Add RGB parameter name annotation
- *
- * @param paramName
- * @param rgbContent
- * @param startIndex
- * @param startOffset
- * @param viewer
- * @param support
- * @param annotations
- * @return the current parsed index
- */
- private static int addRGBParamNameAnnotation(String paramName, String rgbContent, int startIndex, int startOffset,
- ISourceViewer viewer, InlinedAnnotationSupport support, Set<AbstractInlinedAnnotation> annotations) {
- char startChar = startIndex == 0 ? '(' : ',';
- char[] chars = rgbContent.toCharArray();
- for (int i = startIndex; i < chars.length; i++) {
- char c = chars[i];
- if (c == startChar) {
- if (i == chars.length - 1) {
- return -1;
- }
- Position paramPos = new Position(startOffset + i + 1, 1);
- LineContentAnnotation colorParamAnnotation = support.findExistingAnnotation(paramPos);
- if (colorParamAnnotation == null) {
- colorParamAnnotation = new LineContentAnnotation(paramPos, viewer);
- }
- colorParamAnnotation.setText(paramName);
- annotations.add(colorParamAnnotation);
- return i + 1;
- }
- }
- return -1;
- }
-
- /**
- * Parse the given input rgb color and returns an instance of SWT Color and null
- * otherwise.
- *
- * @param input
- * the rgb string color
- * @param device
- * @return the created color and null otherwise.
- */
- private static Color parse(String input, Device device) {
- Pattern c = Pattern.compile("rgb *\\( *([0-9]+), *([0-9]+), *([0-9]+) *\\)");
- Matcher m = c.matcher(input);
- if (m.matches()) {
- try {
- return new Color(device, Integer.valueOf(m.group(1)), // r
- Integer.valueOf(m.group(2)), // g
- Integer.valueOf(m.group(3))); // b
- } catch (Exception e) {
-
- }
- }
- return null;
- }
-
- /**
- * Returns the line text.
- *
- * @param document
- * the document.
- * @param line
- * the line index.
- * @return the line text.
- */
- private static String getLineText(IDocument document, int line) {
- try {
- int offset = document.getLineOffset(line);
- int length = document.getLineLength(line);
- return document.get(offset, length);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
-}
+ * 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.examples.sources.inlined;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+import org.eclipse.jface.text.source.AnnotationPainter;
+import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
+import org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport;
+import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
+import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
+import org.eclipse.jface.text.source.inlined.Positions;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * An inlined demo with {@link LineHeaderAnnotation} and
+ * {@link LineContentAnnotation} annotations both:
+ *
+ * <ul>
+ * <li>a status OK, NOK is displayed before the line which starts with 'color:'.
+ * This status is the result of the content after 'color' which must be a rgb
+ * content. Here {@link ColorStatusAnnotation} is used.</li>
+ * <li>a colorized square is displayed before the rgb declaration (inside the
+ * line content). Here {@link ColorAnnotation} is used.</li>
+ * </ul>
+ *
+ */
+public class InlinedAnnotationDemo {
+
+ public static void main(String[] args) throws Exception {
+
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setText("Inlined annotation demo");
+
+ // Create source viewer and initialize the content
+ ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
+ sourceViewer.setDocument(new Document("\ncolor:rgb(255, 255, 0)"), new AnnotationModel());
+
+ // Initialize inlined annotations support
+ InlinedAnnotationSupport support = new InlinedAnnotationSupport();
+ support.install(sourceViewer, createAnnotationPainter(sourceViewer));
+
+ // Refresh inlined annotation in none UI Thread with reconciler.
+ MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
+
+ @Override
+ public void setDocument(IDocument document) {
+ Set<AbstractInlinedAnnotation> annotations = getInlinedAnnotation(sourceViewer, support);
+ support.updateAnnotations(annotations);
+ }
+
+ @Override
+ public void reconcile(IRegion partition) {
+ Set<AbstractInlinedAnnotation> anns = getInlinedAnnotation(sourceViewer, support);
+ support.updateAnnotations(anns);
+ }
+
+ @Override
+ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+
+ }
+ }, false);
+ reconciler.setDelay(1);
+ reconciler.install(sourceViewer);
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ /**
+ * Create annotation painter.
+ *
+ * @param viewer
+ * the viewer.
+ * @return annotation painter.
+ */
+ private static AnnotationPainter createAnnotationPainter(ISourceViewer viewer) {
+ IAnnotationAccess annotationAccess = new IAnnotationAccess() {
+ @Override
+ public Object getType(Annotation annotation) {
+ return annotation.getType();
+ }
+
+ @Override
+ public boolean isMultiLine(Annotation annotation) {
+ return true;
+ }
+
+ @Override
+ public boolean isTemporary(Annotation annotation) {
+ return true;
+ }
+
+ };
+ AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
+ ((ITextViewerExtension2) viewer).addPainter(painter);
+ return painter;
+ }
+
+ /**
+ * Returns the inlined annotations list to display in the given viewer.
+ *
+ * @param viewer
+ * the viewer
+ * @param support
+ * the inlined annotation suppor.
+ * @return the inlined annotations list to display in the given viewer.
+ */
+ private static Set<AbstractInlinedAnnotation> getInlinedAnnotation(ISourceViewer viewer,
+ InlinedAnnotationSupport support) {
+ IDocument document = viewer.getDocument();
+ Set<AbstractInlinedAnnotation> annotations = new HashSet<>();
+ int lineCount = document.getNumberOfLines();
+ for (int i = 0; i < lineCount; i++) {
+ String line = getLineText(document, i).trim();
+ int index = line.indexOf("color:");
+ if (index == 0) {
+ String rgb = line.substring(index + "color:".length(), line.length()).trim();
+ try {
+ String status = "OK!";
+ Color color = parse(rgb, viewer.getTextWidget().getDisplay());
+ if (color != null) {
+ } else {
+ status = "ERROR!";
+ }
+ // Status color annotation
+ Position pos = Positions.of(i, document, true);
+ ColorStatusAnnotation statusAnnotation = support.findExistingAnnotation(pos);
+ if (statusAnnotation == null) {
+ statusAnnotation = new ColorStatusAnnotation(pos, viewer);
+ }
+ statusAnnotation.setStatus(status);
+ annotations.add(statusAnnotation);
+
+ // Color annotation
+ if (color != null) {
+ Position colorPos = new Position(pos.offset + index + "color:".length(), 1);
+ ColorAnnotation colorAnnotation = support.findExistingAnnotation(colorPos);
+ if (colorAnnotation == null) {
+ colorAnnotation = new ColorAnnotation(colorPos, viewer);
+ }
+ colorAnnotation.setColor(color);
+ annotations.add(colorAnnotation);
+ }
+
+ // rgb parameter names annotations
+ int rgbIndex = line.indexOf("rgb");
+ if (rgbIndex != -1) {
+ rgbIndex = rgbIndex + "rgb".length();
+ int startOffset = pos.offset + rgbIndex;
+ String rgbContent = line.substring(rgbIndex, line.length());
+ int startIndex = addRGBParamNameAnnotation("red:", rgbContent, 0, startOffset, viewer, support,
+ annotations);
+ if (startIndex != -1) {
+ startIndex = addRGBParamNameAnnotation("green:", rgbContent, startIndex, startOffset, viewer,
+ support, annotations);
+ if (startIndex != -1) {
+ startIndex = addRGBParamNameAnnotation("blue:", rgbContent, startIndex, startOffset,
+ viewer, support, annotations);
+ }
+ }
+ }
+
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return annotations;
+ }
+
+ /**
+ * Add RGB parameter name annotation
+ *
+ * @param paramName
+ * @param rgbContent
+ * @param startIndex
+ * @param startOffset
+ * @param viewer
+ * @param support
+ * @param annotations
+ * @return the current parsed index
+ */
+ private static int addRGBParamNameAnnotation(String paramName, String rgbContent, int startIndex, int startOffset,
+ ISourceViewer viewer, InlinedAnnotationSupport support, Set<AbstractInlinedAnnotation> annotations) {
+ char startChar = startIndex == 0 ? '(' : ',';
+ char[] chars = rgbContent.toCharArray();
+ for (int i = startIndex; i < chars.length; i++) {
+ char c = chars[i];
+ if (c == startChar) {
+ if (i == chars.length - 1) {
+ return -1;
+ }
+ Position paramPos = new Position(startOffset + i + 1, 1);
+ LineContentAnnotation colorParamAnnotation = support.findExistingAnnotation(paramPos);
+ if (colorParamAnnotation == null) {
+ colorParamAnnotation = new LineContentAnnotation(paramPos, viewer);
+ }
+ colorParamAnnotation.setText(paramName);
+ annotations.add(colorParamAnnotation);
+ return i + 1;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Parse the given input rgb color and returns an instance of SWT Color and null
+ * otherwise.
+ *
+ * @param input
+ * the rgb string color
+ * @param device
+ * @return the created color and null otherwise.
+ */
+ private static Color parse(String input, Device device) {
+ Pattern c = Pattern.compile("rgb *\\( *([0-9]+), *([0-9]+), *([0-9]+) *\\)");
+ Matcher m = c.matcher(input);
+ if (m.matches()) {
+ try {
+ return new Color(device, Integer.valueOf(m.group(1)), // r
+ Integer.valueOf(m.group(2)), // g
+ Integer.valueOf(m.group(3))); // b
+ } catch (Exception e) {
+
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the line text.
+ *
+ * @param document
+ * the document.
+ * @param line
+ * the line index.
+ * @return the line text.
+ */
+ private static String getLineText(IDocument document, int line) {
+ try {
+ int offset = document.getLineOffset(line);
+ int length = document.getLineLength(line);
+ return document.get(offset, length);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+}

Back to the top