Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-05-18 16:45:17 -0400
committerPaul Pazderski2019-05-18 17:47:36 -0400
commit9e7f66919496659795478f8cd80804da71498fff (patch)
treeced476eaaaa4e1cb0d65f56c3b7852a908eee1f8
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
-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
-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
-rw-r--r--org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.genericeditor.examples/pom.xml2
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagCharacterPairMatcher.java42
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java92
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferencesCodeMiningProvider.java150
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java200
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java934
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java178
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java212
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java62
30 files changed, 2906 insertions, 2906 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 733a27c44..2d8a485fa 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 33614e469..3da946736 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 a313659cf..065dc22be 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 c4a82ba1a..29151731d 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 5bfc12234..203c0a547 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 86b8d4f11..24da65a1a 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 315b7e599..9ff5dbdea 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 c3cd35d30..b9faf06d3 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 803911c30..d50d7e146 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;
+ }
+ }
+}
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 41715bafd..0abbc7523 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 34e86434d..697a3a387 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 da4ede56f..337824fbc 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 b95b39a0f..87cd90d92 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 c83a2f8a1..afe0799b3 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 2a36d76a2..50290aa10 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 c3b1ead49..540c6e295 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 987d12236..ef91c0c89 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 a7a898b7d..6ec1ca33d 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 51cf13ec6..6f8d699d3 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 e3bf8dc6b..a9bd09f2c 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;
+ }
+}
diff --git a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
index d57a01e90..e495516d7 100644
--- a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Examples for Generic Editor
Bundle-SymbolicName: org.eclipse.ui.genericeditor.examples;singleton:=true
-Bundle-Version: 1.1.200.qualifier
+Bundle-Version: 1.1.300.qualifier
Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.ui.genericeditor;bundle-version="1.0.0",
diff --git a/org.eclipse.ui.genericeditor.examples/pom.xml b/org.eclipse.ui.genericeditor.examples/pom.xml
index e3fa9053c..3394f95ca 100644
--- a/org.eclipse.ui.genericeditor.examples/pom.xml
+++ b/org.eclipse.ui.genericeditor.examples/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.genericeditor.examples</artifactId>
- <version>1.1.200-SNAPSHOT</version>
+ <version>1.1.300-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagCharacterPairMatcher.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagCharacterPairMatcher.java
index 0158795e5..6bdda8dbc 100644
--- a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagCharacterPairMatcher.java
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagCharacterPairMatcher.java
@@ -1,21 +1,21 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v20.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
- */
-package org.eclipse.ui.genericeditor.examples.dotproject;
-
-import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
-
-public class TagCharacterPairMatcher extends DefaultCharacterPairMatcher {
-
- public TagCharacterPairMatcher() {
- super(new char[] { '<', '>', '"', '"' });
- }
-
-}
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.genericeditor.examples.dotproject;
+
+import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
+
+public class TagCharacterPairMatcher extends DefaultCharacterPairMatcher {
+
+ public TagCharacterPairMatcher() {
+ super(new char[] { '<', '>', '"', '"' });
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java
index 4be015971..1ace81c25 100644
--- a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferenceCodeMining.java
@@ -1,49 +1,49 @@
-/**
- * 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.ui.genericeditor.examples.dotproject.codemining;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-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;
-import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
-
-/**
- * Project reference mining.
- */
-public class ProjectReferenceCodeMining extends LineHeaderCodeMining {
-
- private final String projectName;
-
- public ProjectReferenceCodeMining(String projectName, int beforeLineNumber, IDocument document,
- ICodeMiningProvider provider) throws BadLocationException {
- super(beforeLineNumber, document, provider);
- this.projectName = projectName;
- }
-
- @Override
- protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
- return CompletableFuture.runAsync(() -> {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- int refCount = project != null ? project.getReferencingProjects().length : 0;
- super.setLabel(refCount + (refCount > 1 ? " references" : " reference"));
- });
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [CodeMining] Provide extension point for CodeMining - Bug 528419
+ */
+package org.eclipse.ui.genericeditor.examples.dotproject.codemining;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+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;
+import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
+
+/**
+ * Project reference mining.
+ */
+public class ProjectReferenceCodeMining extends LineHeaderCodeMining {
+
+ private final String projectName;
+
+ public ProjectReferenceCodeMining(String projectName, int beforeLineNumber, IDocument document,
+ ICodeMiningProvider provider) throws BadLocationException {
+ super(beforeLineNumber, document, provider);
+ this.projectName = projectName;
+ }
+
+ @Override
+ protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
+ return CompletableFuture.runAsync(() -> {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ int refCount = project != null ? project.getReferencingProjects().length : 0;
+ super.setLabel(refCount + (refCount > 1 ? " references" : " reference"));
+ });
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferencesCodeMiningProvider.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferencesCodeMiningProvider.java
index e73ac19ec..98e07c4f7 100644
--- a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferencesCodeMiningProvider.java
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/codemining/ProjectReferencesCodeMiningProvider.java
@@ -1,78 +1,78 @@
-/**
- * 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.ui.genericeditor.examples.dotproject.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;
-
-/**
- * Project reference minings provider.
- */
-public class ProjectReferencesCodeMiningProvider extends AbstractCodeMiningProvider {
-
- @Override
- public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
- IProgressMonitor monitor) {
- return CompletableFuture.supplyAsync(() -> {
- IDocument document = viewer.getDocument();
- List<ICodeMining> minings = new ArrayList<>();
- int lineCount = document.getNumberOfLines();
- for (int i = 0; i < lineCount; i++) {
- // check if request was canceled.
- monitor.isCanceled();
- String line = getLineText(document, i).trim();
- int startIndex = line.indexOf("<name>");
- if (startIndex != -1) {
- // It's the first name, we consider we are in <projectDescription></name>
- startIndex += "<name>".length();
- int endIndex = line.indexOf("</name>");
- if (endIndex > startIndex) {
- // Check if parent element is projectDescription
- String projectName = line.substring(startIndex, endIndex);
- if (projectName.length() > 0) {
- try {
- minings.add(new ProjectReferenceCodeMining(projectName, i, document, this));
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- }
- }
- // stop the compute of minings to avoid process other name like
- // <buildCommand><name>
- break;
- }
- }
- return minings;
- });
- }
-
- private 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] Provide extension point for CodeMining - Bug 528419
+ */
+package org.eclipse.ui.genericeditor.examples.dotproject.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;
+
+/**
+ * Project reference minings provider.
+ */
+public class ProjectReferencesCodeMiningProvider extends AbstractCodeMiningProvider {
+
+ @Override
+ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
+ IProgressMonitor monitor) {
+ return CompletableFuture.supplyAsync(() -> {
+ IDocument document = viewer.getDocument();
+ List<ICodeMining> minings = new ArrayList<>();
+ int lineCount = document.getNumberOfLines();
+ for (int i = 0; i < lineCount; i++) {
+ // check if request was canceled.
+ monitor.isCanceled();
+ String line = getLineText(document, i).trim();
+ int startIndex = line.indexOf("<name>");
+ if (startIndex != -1) {
+ // It's the first name, we consider we are in <projectDescription></name>
+ startIndex += "<name>".length();
+ int endIndex = line.indexOf("</name>");
+ if (endIndex > startIndex) {
+ // Check if parent element is projectDescription
+ String projectName = line.substring(startIndex, endIndex);
+ if (projectName.length() > 0) {
+ try {
+ minings.add(new ProjectReferenceCodeMining(projectName, i, document, this));
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ // stop the compute of minings to avoid process other name like
+ // <buildCommand><name>
+ break;
+ }
+ }
+ return minings;
+ });
+ }
+
+ private 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.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java
index 52f03824f..c18e2173f 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java
@@ -1,100 +1,100 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v20.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
- */
-package org.eclipse.ui.internal.genericeditor;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IRegistryChangeEvent;
-import org.eclipse.core.runtime.IRegistryChangeListener;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.text.source.ICharacterPairMatcher;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-/**
- * A registry of character pair matchers provided by extension
- * <code>org.eclipse.ui.genericeditor.characterPairMatchers</code>. Those
- * extensions are specific to a given {@link IContentType}.
- *
- * @since 1.2
- */
-public class CharacterPairMatcherRegistry {
-
- private static final String EXTENSION_POINT_ID = GenericEditorPlugin.BUNDLE_ID + ".characterPairMatchers"; //$NON-NLS-1$
-
- private Map<IConfigurationElement, GenericContentTypeRelatedExtension<ICharacterPairMatcher>> extensions = new HashMap<>();
- private boolean outOfSync = true;
-
- /**
- * Creates the registry and binds it to the extension point.
- */
- public CharacterPairMatcherRegistry() {
- Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() {
- @Override
- public void registryChanged(IRegistryChangeEvent event) {
- outOfSync = true;
- }
- }, EXTENSION_POINT_ID);
- }
-
- /**
- * Get the contributed {@link IPresentationReconciliers}s that are relevant to
- * hook on source viewer according to document content types.
- *
- * @param sourceViewer the source viewer we're hooking completion to.
- * @param editor the text editor
- * @param contentTypes the content types of the document we're editing.
- * @return the list of {@link ICharacterPairMatcher} contributed for at least
- * one of the content types.
- */
- public List<ICharacterPairMatcher> getCharacterPairMatchers(ISourceViewer sourceViewer, ITextEditor editor,
- Set<IContentType> contentTypes) {
- if (this.outOfSync) {
- sync();
- }
- return this.extensions.values().stream().filter(ext -> contentTypes.contains(ext.targetContentType))
- .filter(ext -> ext.matches(sourceViewer, editor))
- .sorted(new ContentTypeSpecializationComparator<ICharacterPairMatcher>())
- .map(GenericContentTypeRelatedExtension<ICharacterPairMatcher>::createDelegate)
- .collect(Collectors.toList());
- }
-
- private void sync() {
- Set<IConfigurationElement> toRemoveExtensions = new HashSet<>(this.extensions.keySet());
- for (IConfigurationElement extension : Platform.getExtensionRegistry()
- .getConfigurationElementsFor(EXTENSION_POINT_ID)) {
- toRemoveExtensions.remove(extension);
- if (!this.extensions.containsKey(extension)) {
- try {
- this.extensions.put(extension,
- new GenericContentTypeRelatedExtension<ICharacterPairMatcher>(extension));
- } catch (Exception ex) {
- GenericEditorPlugin.getDefault().getLog()
- .log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, ex.getMessage(), ex));
- }
- }
- }
- for (IConfigurationElement toRemove : toRemoveExtensions) {
- this.extensions.remove(toRemove);
- }
- this.outOfSync = false;
- }
-
-}
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * A registry of character pair matchers provided by extension
+ * <code>org.eclipse.ui.genericeditor.characterPairMatchers</code>. Those
+ * extensions are specific to a given {@link IContentType}.
+ *
+ * @since 1.2
+ */
+public class CharacterPairMatcherRegistry {
+
+ private static final String EXTENSION_POINT_ID = GenericEditorPlugin.BUNDLE_ID + ".characterPairMatchers"; //$NON-NLS-1$
+
+ private Map<IConfigurationElement, GenericContentTypeRelatedExtension<ICharacterPairMatcher>> extensions = new HashMap<>();
+ private boolean outOfSync = true;
+
+ /**
+ * Creates the registry and binds it to the extension point.
+ */
+ public CharacterPairMatcherRegistry() {
+ Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() {
+ @Override
+ public void registryChanged(IRegistryChangeEvent event) {
+ outOfSync = true;
+ }
+ }, EXTENSION_POINT_ID);
+ }
+
+ /**
+ * Get the contributed {@link IPresentationReconciliers}s that are relevant to
+ * hook on source viewer according to document content types.
+ *
+ * @param sourceViewer the source viewer we're hooking completion to.
+ * @param editor the text editor
+ * @param contentTypes the content types of the document we're editing.
+ * @return the list of {@link ICharacterPairMatcher} contributed for at least
+ * one of the content types.
+ */
+ public List<ICharacterPairMatcher> getCharacterPairMatchers(ISourceViewer sourceViewer, ITextEditor editor,
+ Set<IContentType> contentTypes) {
+ if (this.outOfSync) {
+ sync();
+ }
+ return this.extensions.values().stream().filter(ext -> contentTypes.contains(ext.targetContentType))
+ .filter(ext -> ext.matches(sourceViewer, editor))
+ .sorted(new ContentTypeSpecializationComparator<ICharacterPairMatcher>())
+ .map(GenericContentTypeRelatedExtension<ICharacterPairMatcher>::createDelegate)
+ .collect(Collectors.toList());
+ }
+
+ private void sync() {
+ Set<IConfigurationElement> toRemoveExtensions = new HashSet<>(this.extensions.keySet());
+ for (IConfigurationElement extension : Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(EXTENSION_POINT_ID)) {
+ toRemoveExtensions.remove(extension);
+ if (!this.extensions.containsKey(extension)) {
+ try {
+ this.extensions.put(extension,
+ new GenericContentTypeRelatedExtension<ICharacterPairMatcher>(extension));
+ } catch (Exception ex) {
+ GenericEditorPlugin.getDefault().getLog()
+ .log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, ex.getMessage(), ex));
+ }
+ }
+ }
+ for (IConfigurationElement toRemove : toRemoveExtensions) {
+ this.extensions.remove(toRemove);
+ }
+ this.outOfSync = false;
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java
index 7a05cb915..19a56b9e6 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java
@@ -1,468 +1,468 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2018 IBM Corporation and others.
- *
- * 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:
- * IBM Corporation - initial API and implementation
- * Angelo Zerr <angelo.zerr@gmail.com> - adapt code org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingStrategy to support generic indent folding strategy.
- * [generic editor] Default Code folding for generic editor should use IndentFoldingStrategy - Bug 520659
- */
-package org.eclipse.ui.internal.genericeditor.folding;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-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.reconciler.DirtyRegion;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.projection.IProjectionListener;
-import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
-import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
-import org.eclipse.jface.text.source.projection.ProjectionViewer;
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-
-/**
- * Indent folding strategy to fold code by using indentation. The folding
- * strategy must be associated with a viewer for it to function.
- */
-public class IndentFoldingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension, IProjectionListener {
-
- private IDocument document;
- private ProjectionViewer viewer;
- private ProjectionAnnotationModel projectionAnnotationModel;
- private final String lineStartsWithKeyword;
-
- public IndentFoldingStrategy() {
- this(null);
- }
-
- public IndentFoldingStrategy(String lineStartsWithKeyword) {
- this.lineStartsWithKeyword = lineStartsWithKeyword;
- }
-
- /**
- * A FoldingAnnotation is a {@link ProjectionAnnotation} it is folding and
- * overriding the paint method (in a hacky type way) to prevent one line folding
- * annotations to be drawn.
- */
- protected class FoldingAnnotation extends ProjectionAnnotation {
- private boolean visible; /* workaround for BUG85874 */
-
- /**
- * Creates a new FoldingAnnotation.
- *
- * @param isCollapsed true if this annotation should be collapsed, false
- * otherwise
- */
- public FoldingAnnotation(boolean isCollapsed) {
- super(isCollapsed);
- visible = false;
- }
-
- /**
- * Does not paint hidden annotations. Annotations are hidden when they only span
- * one line.
- *
- * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC,
- * org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
- */
- @Override
- public void paint(GC gc, Canvas canvas, Rectangle rectangle) {
- /* workaround for BUG85874 */
- /*
- * only need to check annotations that are expanded because hidden annotations
- * should never have been given the chance to collapse.
- */
- if (!isCollapsed()) {
- // working with rectangle, so line height
- FontMetrics metrics = gc.getFontMetrics();
- if (metrics != null) {
- // do not draw annotations that only span one line and
- // mark them as not visible
- if ((rectangle.height / metrics.getHeight()) <= 1) {
- visible = false;
- return;
- }
- }
- }
- visible = true;
- super.paint(gc, canvas, rectangle);
- }
-
- @Override
- public void markCollapsed() {
- /* workaround for BUG85874 */
- // do not mark collapsed if annotation is not visible
- if (visible)
- super.markCollapsed();
- }
- }
-
- /**
- * The folding strategy must be associated with a viewer for it to function
- *
- * @param viewer the viewer to associate this folding strategy with
- */
- public void setViewer(ProjectionViewer viewer) {
- if (this.viewer != null) {
- this.viewer.removeProjectionListener(this);
- }
- this.viewer = viewer;
- this.viewer.addProjectionListener(this);
- this.projectionAnnotationModel = this.viewer.getProjectionAnnotationModel();
- }
-
- public void uninstall() {
- setDocument(null);
-
- if (viewer != null) {
- viewer.removeProjectionListener(this);
- viewer = null;
- }
-
- projectionDisabled();
- }
-
- @Override
- public void setDocument(IDocument document) {
- this.document = document;
- }
-
- @Override
- public void projectionDisabled() {
- projectionAnnotationModel = null;
- }
-
- @Override
- public void projectionEnabled() {
- if (viewer != null) {
- projectionAnnotationModel = viewer.getProjectionAnnotationModel();
- }
- }
-
- private class LineIndent {
- public int line;
- public final int indent;
-
- public LineIndent(int line, int indent) {
- this.line = line;
- this.indent = indent;
- }
- }
-
- @Override
- public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
- if (projectionAnnotationModel != null) {
-
- // these are what are passed off to the annotation model to
- // actually create and maintain the annotations
- List<Annotation> modifications = new ArrayList<Annotation>();
- List<FoldingAnnotation> deletions = new ArrayList<FoldingAnnotation>();
- List<FoldingAnnotation> existing = new ArrayList<FoldingAnnotation>();
- Map<Annotation, Position> additions = new HashMap<Annotation, Position>();
-
- // find and mark all folding annotations with length 0 for deletion
- markInvalidAnnotationsForDeletion(dirtyRegion, deletions, existing);
-
- List<LineIndent> previousRegions = new ArrayList<LineIndent>();
-
- int tabSize = 1;
- int minimumRangeSize = 1;
- try {
-
- // Today we recompute annotation from the whole document each
- // time.
- // performance s good even with large document, but it should be
- // better to loop for only DirtyRegion (and before/after)
- // int offset = dirtyRegion.getOffset();
- // int length = dirtyRegion.getLength();
- // int startLine = 0; //document.getLineOfOffset(offset);
- int endLine = document.getNumberOfLines() - 1; // startLine +
- // document.getNumberOfLines(offset,
- // length) - 1;
-
- // sentinel, to make sure there's at least one entry
- previousRegions.add(new LineIndent(endLine + 1, -1));
-
- int lastLineWhichIsNotEmpty = 0;
- int lineEmptyCount = 0;
- Integer lastLineForKeyword = null;
- int line = endLine;
- for (line = endLine; line >= 0; line--) {
- int lineOffset = document.getLineOffset(line);
- String delim = document.getLineDelimiter(line);
- int lineLength = document.getLineLength(line) - (delim != null ? delim.length() : 0);
- String lineContent = document.get(lineOffset, lineLength);
-
- LineState state = getLineState(lineContent, lastLineForKeyword);
- switch (state) {
- case StartWithKeyWord:
- lineEmptyCount = 0;
- lastLineWhichIsNotEmpty = line;
- if (lastLineForKeyword == null) {
- lastLineForKeyword = line;
- }
- break;
- case EmptyLine:
- lineEmptyCount++;
- break;
- default:
- addAnnotationForKeyword(modifications, deletions, existing, additions,
- line + 1 + lineEmptyCount, lastLineForKeyword);
- lastLineForKeyword = null;
- lineEmptyCount = 0;
- lastLineWhichIsNotEmpty = line;
- int indent = computeIndentLevel(lineContent, tabSize);
- if (indent == -1) {
- continue; // only whitespace
- }
-
- LineIndent previous = previousRegions.get(previousRegions.size() - 1);
- if (previous.indent > indent) {
- // discard all regions with larger indent
- do {
- previousRegions.remove(previousRegions.size() - 1);
- previous = previousRegions.get(previousRegions.size() - 1);
- } while (previous.indent > indent);
-
- // new folding range
- int endLineNumber = previous.line - 1;
- if (endLineNumber - line >= minimumRangeSize) {
- updateAnnotation(modifications, deletions, existing, additions, line, endLineNumber);
- }
- }
- if (previous.indent == indent) {
- previous.line = line;
- } else { // previous.indent < indent
- // new region with a bigger indent
- previousRegions.add(new LineIndent(line, indent));
- }
- }
- }
- addAnnotationForKeyword(modifications, deletions, existing, additions, lastLineWhichIsNotEmpty,
- lastLineForKeyword);
- } catch (BadLocationException e) {
- // should never done
- e.printStackTrace();
- }
-
- // be sure projection has not been disabled
- if (projectionAnnotationModel != null) {
- if (existing.size() > 0) {
- deletions.addAll(existing);
- }
- // send the calculated updates to the annotations to the
- // annotation model
- projectionAnnotationModel.modifyAnnotations(deletions.toArray(new Annotation[1]), additions,
- modifications.toArray(new Annotation[0]));
- }
- }
- }
-
- private void addAnnotationForKeyword(List<Annotation> modifications, List<FoldingAnnotation> deletions,
- List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int startLine,
- Integer lastLineForKeyword) throws BadLocationException {
- if (lastLineForKeyword != null) {
- updateAnnotation(modifications, deletions, existing, additions, startLine, lastLineForKeyword);
- }
- }
-
- private enum LineState {
- StartWithKeyWord, DontStartWithKeyWord, EmptyLine
- }
-
- /**
- * Returns the line state for line which starts with a given keyword.
- *
- * @param lineContent line content.
- * @param lastLineForKeyword last line for the given keyword.
- * @return
- */
- private LineState getLineState(String lineContent, Integer lastLineForKeyword) {
- if (lineStartsWithKeyword == null) {
- // none keyword defined.
- return LineState.DontStartWithKeyWord;
- }
- if (lineContent != null && lineContent.trim().startsWith(lineStartsWithKeyword)) {
- // The line starts with the given keyword (ex: starts with "import")
- return LineState.StartWithKeyWord;
- }
- if (lastLineForKeyword != null && (lineContent == null || lineContent.trim().length() == 0)) {
- // a last line for keyword was defined, line is empty
- return LineState.EmptyLine;
- }
- return LineState.DontStartWithKeyWord;
- }
-
- /**
- * Compute indentation level of the given line by using the given tab size.
- *
- * @param line the line text.
- * @param tabSize the tab size.
- * @return the indentation level of the given line by using the given tab size.
- */
- private static int computeIndentLevel(String line, int tabSize) {
- int i = 0;
- int indent = 0;
- while (i < line.length()) {
- char ch = line.charAt(i);
- if (ch == ' ') {
- indent++;
- } else if (ch == '\t') {
- indent = indent - indent % tabSize + tabSize;
- } else {
- break;
- }
- i++;
- }
- if (i == line.length()) {
- return -1; // line only consists of whitespace
- }
- return indent;
- }
-
- /**
- * Given a {@link DirtyRegion} returns an {@link Iterator} of the already
- * existing annotations in that region.
- *
- * @param dirtyRegion the {@link DirtyRegion} to check for existing annotations
- * in
- *
- * @return an {@link Iterator} over the annotations in the given
- * {@link DirtyRegion}. The iterator could have no annotations in it. Or
- * <code>null</code> if projection has been disabled.
- */
- private Iterator<Annotation> getAnnotationIterator(DirtyRegion dirtyRegion) {
- Iterator<Annotation> annoIter = null;
- // be sure project has not been disabled
- if (projectionAnnotationModel != null) {
- // workaround for Platform Bug 299416
- annoIter = projectionAnnotationModel.getAnnotationIterator(0, document.getLength(), false, false);
- }
- return annoIter;
- }
-
- /**
- * Update annotations.
- *
- * @param modifications the folding annotations to update.
- * @param deletions the folding annotations to delete.
- * @param existing the existing folding annotations.
- * @param additions annoation to add
- * @param line the line index
- * @param endLineNumber the end line number
- * @throws BadLocationException
- */
- private void updateAnnotation(List<Annotation> modifications, List<FoldingAnnotation> deletions,
- List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int line, Integer endLineNumber)
- throws BadLocationException {
- int startOffset = document.getLineOffset(line);
- int endOffset = document.getLineOffset(endLineNumber) + document.getLineLength(endLineNumber);
- Position newPos = new Position(startOffset, endOffset - startOffset);
- if (existing.size() > 0) {
- FoldingAnnotation existingAnnotation = existing.remove(existing.size() - 1);
- updateAnnotations(existingAnnotation, newPos, modifications, deletions);
- } else {
- additions.put(new FoldingAnnotation(false), newPos);
- }
- }
-
- /**
- * Update annotations.
- *
- * @param existingAnnotation the existing annotations that need to be updated
- * based on the given dirtied IndexRegion
- * @param newPos the new position that caused the annotations need
- * for updating and null otherwise.
- * @param modifications the list of annotations to be modified
- * @param deletions the list of annotations to be deleted
- */
- protected void updateAnnotations(Annotation existingAnnotation, Position newPos, List<Annotation> modifications,
- List<FoldingAnnotation> deletions) {
- if (existingAnnotation instanceof FoldingAnnotation) {
- FoldingAnnotation foldingAnnotation = (FoldingAnnotation) existingAnnotation;
-
- // if a new position can be calculated then update the position of
- // the annotation,
- // else the annotation needs to be deleted
- if (newPos != null && newPos.length > 0 && projectionAnnotationModel != null) {
- Position oldPos = projectionAnnotationModel.getPosition(foldingAnnotation);
- // only update the position if we have to
- if (!newPos.equals(oldPos)) {
- oldPos.setOffset(newPos.offset);
- oldPos.setLength(newPos.length);
- modifications.add(foldingAnnotation);
- }
- } else {
- deletions.add(foldingAnnotation);
- }
- }
- }
-
- /**
- * <p>
- * Searches the given {@link DirtyRegion} for annotations that now have a length
- * of 0. This is caused when something that was being folded has been deleted.
- * These {@link FoldingAnnotation}s are then added to the {@link List} of
- * {@link FoldingAnnotation}s to be deleted
- * </p>
- *
- * @param dirtyRegion find the now invalid {@link FoldingAnnotation}s in this
- * {@link DirtyRegion}
- * @param deletions the current list of {@link FoldingAnnotation}s marked for
- * deletion that the newly found invalid
- * {@link FoldingAnnotation}s will be added to
- */
- protected void markInvalidAnnotationsForDeletion(DirtyRegion dirtyRegion, List<FoldingAnnotation> deletions,
- List<FoldingAnnotation> existing) {
- Iterator<Annotation> iter = getAnnotationIterator(dirtyRegion);
- if (iter != null) {
- while (iter.hasNext()) {
- Annotation anno = iter.next();
- if (anno instanceof FoldingAnnotation) {
- FoldingAnnotation folding = (FoldingAnnotation) anno;
- Position pos = projectionAnnotationModel.getPosition(anno);
- if (pos.length == 0) {
- deletions.add(folding);
- } else {
- existing.add(folding);
- }
- }
- }
- }
- }
-
- @Override
- public void reconcile(IRegion partition) {
- // not used, we use:
- // reconcile(DirtyRegion dirtyRegion, IRegion subRegion)
- }
-
- @Override
- public void setProgressMonitor(IProgressMonitor monitor) {
- // Do nothing
- }
-
- @Override
- public void initialReconcile() {
- reconcile(new DirtyRegion(0, document.getLength(), DirtyRegion.INSERT, document.get()), null);
- }
+/*******************************************************************************
+ * Copyright (c) 2009, 2018 IBM Corporation and others.
+ *
+ * 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:
+ * IBM Corporation - initial API and implementation
+ * Angelo Zerr <angelo.zerr@gmail.com> - adapt code org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingStrategy to support generic indent folding strategy.
+ * [generic editor] Default Code folding for generic editor should use IndentFoldingStrategy - Bug 520659
+ */
+package org.eclipse.ui.internal.genericeditor.folding;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+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.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.projection.IProjectionListener;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+
+/**
+ * Indent folding strategy to fold code by using indentation. The folding
+ * strategy must be associated with a viewer for it to function.
+ */
+public class IndentFoldingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension, IProjectionListener {
+
+ private IDocument document;
+ private ProjectionViewer viewer;
+ private ProjectionAnnotationModel projectionAnnotationModel;
+ private final String lineStartsWithKeyword;
+
+ public IndentFoldingStrategy() {
+ this(null);
+ }
+
+ public IndentFoldingStrategy(String lineStartsWithKeyword) {
+ this.lineStartsWithKeyword = lineStartsWithKeyword;
+ }
+
+ /**
+ * A FoldingAnnotation is a {@link ProjectionAnnotation} it is folding and
+ * overriding the paint method (in a hacky type way) to prevent one line folding
+ * annotations to be drawn.
+ */
+ protected class FoldingAnnotation extends ProjectionAnnotation {
+ private boolean visible; /* workaround for BUG85874 */
+
+ /**
+ * Creates a new FoldingAnnotation.
+ *
+ * @param isCollapsed true if this annotation should be collapsed, false
+ * otherwise
+ */
+ public FoldingAnnotation(boolean isCollapsed) {
+ super(isCollapsed);
+ visible = false;
+ }
+
+ /**
+ * Does not paint hidden annotations. Annotations are hidden when they only span
+ * one line.
+ *
+ * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC,
+ * org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
+ */
+ @Override
+ public void paint(GC gc, Canvas canvas, Rectangle rectangle) {
+ /* workaround for BUG85874 */
+ /*
+ * only need to check annotations that are expanded because hidden annotations
+ * should never have been given the chance to collapse.
+ */
+ if (!isCollapsed()) {
+ // working with rectangle, so line height
+ FontMetrics metrics = gc.getFontMetrics();
+ if (metrics != null) {
+ // do not draw annotations that only span one line and
+ // mark them as not visible
+ if ((rectangle.height / metrics.getHeight()) <= 1) {
+ visible = false;
+ return;
+ }
+ }
+ }
+ visible = true;
+ super.paint(gc, canvas, rectangle);
+ }
+
+ @Override
+ public void markCollapsed() {
+ /* workaround for BUG85874 */
+ // do not mark collapsed if annotation is not visible
+ if (visible)
+ super.markCollapsed();
+ }
+ }
+
+ /**
+ * The folding strategy must be associated with a viewer for it to function
+ *
+ * @param viewer the viewer to associate this folding strategy with
+ */
+ public void setViewer(ProjectionViewer viewer) {
+ if (this.viewer != null) {
+ this.viewer.removeProjectionListener(this);
+ }
+ this.viewer = viewer;
+ this.viewer.addProjectionListener(this);
+ this.projectionAnnotationModel = this.viewer.getProjectionAnnotationModel();
+ }
+
+ public void uninstall() {
+ setDocument(null);
+
+ if (viewer != null) {
+ viewer.removeProjectionListener(this);
+ viewer = null;
+ }
+
+ projectionDisabled();
+ }
+
+ @Override
+ public void setDocument(IDocument document) {
+ this.document = document;
+ }
+
+ @Override
+ public void projectionDisabled() {
+ projectionAnnotationModel = null;
+ }
+
+ @Override
+ public void projectionEnabled() {
+ if (viewer != null) {
+ projectionAnnotationModel = viewer.getProjectionAnnotationModel();
+ }
+ }
+
+ private class LineIndent {
+ public int line;
+ public final int indent;
+
+ public LineIndent(int line, int indent) {
+ this.line = line;
+ this.indent = indent;
+ }
+ }
+
+ @Override
+ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+ if (projectionAnnotationModel != null) {
+
+ // these are what are passed off to the annotation model to
+ // actually create and maintain the annotations
+ List<Annotation> modifications = new ArrayList<Annotation>();
+ List<FoldingAnnotation> deletions = new ArrayList<FoldingAnnotation>();
+ List<FoldingAnnotation> existing = new ArrayList<FoldingAnnotation>();
+ Map<Annotation, Position> additions = new HashMap<Annotation, Position>();
+
+ // find and mark all folding annotations with length 0 for deletion
+ markInvalidAnnotationsForDeletion(dirtyRegion, deletions, existing);
+
+ List<LineIndent> previousRegions = new ArrayList<LineIndent>();
+
+ int tabSize = 1;
+ int minimumRangeSize = 1;
+ try {
+
+ // Today we recompute annotation from the whole document each
+ // time.
+ // performance s good even with large document, but it should be
+ // better to loop for only DirtyRegion (and before/after)
+ // int offset = dirtyRegion.getOffset();
+ // int length = dirtyRegion.getLength();
+ // int startLine = 0; //document.getLineOfOffset(offset);
+ int endLine = document.getNumberOfLines() - 1; // startLine +
+ // document.getNumberOfLines(offset,
+ // length) - 1;
+
+ // sentinel, to make sure there's at least one entry
+ previousRegions.add(new LineIndent(endLine + 1, -1));
+
+ int lastLineWhichIsNotEmpty = 0;
+ int lineEmptyCount = 0;
+ Integer lastLineForKeyword = null;
+ int line = endLine;
+ for (line = endLine; line >= 0; line--) {
+ int lineOffset = document.getLineOffset(line);
+ String delim = document.getLineDelimiter(line);
+ int lineLength = document.getLineLength(line) - (delim != null ? delim.length() : 0);
+ String lineContent = document.get(lineOffset, lineLength);
+
+ LineState state = getLineState(lineContent, lastLineForKeyword);
+ switch (state) {
+ case StartWithKeyWord:
+ lineEmptyCount = 0;
+ lastLineWhichIsNotEmpty = line;
+ if (lastLineForKeyword == null) {
+ lastLineForKeyword = line;
+ }
+ break;
+ case EmptyLine:
+ lineEmptyCount++;
+ break;
+ default:
+ addAnnotationForKeyword(modifications, deletions, existing, additions,
+ line + 1 + lineEmptyCount, lastLineForKeyword);
+ lastLineForKeyword = null;
+ lineEmptyCount = 0;
+ lastLineWhichIsNotEmpty = line;
+ int indent = computeIndentLevel(lineContent, tabSize);
+ if (indent == -1) {
+ continue; // only whitespace
+ }
+
+ LineIndent previous = previousRegions.get(previousRegions.size() - 1);
+ if (previous.indent > indent) {
+ // discard all regions with larger indent
+ do {
+ previousRegions.remove(previousRegions.size() - 1);
+ previous = previousRegions.get(previousRegions.size() - 1);
+ } while (previous.indent > indent);
+
+ // new folding range
+ int endLineNumber = previous.line - 1;
+ if (endLineNumber - line >= minimumRangeSize) {
+ updateAnnotation(modifications, deletions, existing, additions, line, endLineNumber);
+ }
+ }
+ if (previous.indent == indent) {
+ previous.line = line;
+ } else { // previous.indent < indent
+ // new region with a bigger indent
+ previousRegions.add(new LineIndent(line, indent));
+ }
+ }
+ }
+ addAnnotationForKeyword(modifications, deletions, existing, additions, lastLineWhichIsNotEmpty,
+ lastLineForKeyword);
+ } catch (BadLocationException e) {
+ // should never done
+ e.printStackTrace();
+ }
+
+ // be sure projection has not been disabled
+ if (projectionAnnotationModel != null) {
+ if (existing.size() > 0) {
+ deletions.addAll(existing);
+ }
+ // send the calculated updates to the annotations to the
+ // annotation model
+ projectionAnnotationModel.modifyAnnotations(deletions.toArray(new Annotation[1]), additions,
+ modifications.toArray(new Annotation[0]));
+ }
+ }
+ }
+
+ private void addAnnotationForKeyword(List<Annotation> modifications, List<FoldingAnnotation> deletions,
+ List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int startLine,
+ Integer lastLineForKeyword) throws BadLocationException {
+ if (lastLineForKeyword != null) {
+ updateAnnotation(modifications, deletions, existing, additions, startLine, lastLineForKeyword);
+ }
+ }
+
+ private enum LineState {
+ StartWithKeyWord, DontStartWithKeyWord, EmptyLine
+ }
+
+ /**
+ * Returns the line state for line which starts with a given keyword.
+ *
+ * @param lineContent line content.
+ * @param lastLineForKeyword last line for the given keyword.
+ * @return
+ */
+ private LineState getLineState(String lineContent, Integer lastLineForKeyword) {
+ if (lineStartsWithKeyword == null) {
+ // none keyword defined.
+ return LineState.DontStartWithKeyWord;
+ }
+ if (lineContent != null && lineContent.trim().startsWith(lineStartsWithKeyword)) {
+ // The line starts with the given keyword (ex: starts with "import")
+ return LineState.StartWithKeyWord;
+ }
+ if (lastLineForKeyword != null && (lineContent == null || lineContent.trim().length() == 0)) {
+ // a last line for keyword was defined, line is empty
+ return LineState.EmptyLine;
+ }
+ return LineState.DontStartWithKeyWord;
+ }
+
+ /**
+ * Compute indentation level of the given line by using the given tab size.
+ *
+ * @param line the line text.
+ * @param tabSize the tab size.
+ * @return the indentation level of the given line by using the given tab size.
+ */
+ private static int computeIndentLevel(String line, int tabSize) {
+ int i = 0;
+ int indent = 0;
+ while (i < line.length()) {
+ char ch = line.charAt(i);
+ if (ch == ' ') {
+ indent++;
+ } else if (ch == '\t') {
+ indent = indent - indent % tabSize + tabSize;
+ } else {
+ break;
+ }
+ i++;
+ }
+ if (i == line.length()) {
+ return -1; // line only consists of whitespace
+ }
+ return indent;
+ }
+
+ /**
+ * Given a {@link DirtyRegion} returns an {@link Iterator} of the already
+ * existing annotations in that region.
+ *
+ * @param dirtyRegion the {@link DirtyRegion} to check for existing annotations
+ * in
+ *
+ * @return an {@link Iterator} over the annotations in the given
+ * {@link DirtyRegion}. The iterator could have no annotations in it. Or
+ * <code>null</code> if projection has been disabled.
+ */
+ private Iterator<Annotation> getAnnotationIterator(DirtyRegion dirtyRegion) {
+ Iterator<Annotation> annoIter = null;
+ // be sure project has not been disabled
+ if (projectionAnnotationModel != null) {
+ // workaround for Platform Bug 299416
+ annoIter = projectionAnnotationModel.getAnnotationIterator(0, document.getLength(), false, false);
+ }
+ return annoIter;
+ }
+
+ /**
+ * Update annotations.
+ *
+ * @param modifications the folding annotations to update.
+ * @param deletions the folding annotations to delete.
+ * @param existing the existing folding annotations.
+ * @param additions annoation to add
+ * @param line the line index
+ * @param endLineNumber the end line number
+ * @throws BadLocationException
+ */
+ private void updateAnnotation(List<Annotation> modifications, List<FoldingAnnotation> deletions,
+ List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int line, Integer endLineNumber)
+ throws BadLocationException {
+ int startOffset = document.getLineOffset(line);
+ int endOffset = document.getLineOffset(endLineNumber) + document.getLineLength(endLineNumber);
+ Position newPos = new Position(startOffset, endOffset - startOffset);
+ if (existing.size() > 0) {
+ FoldingAnnotation existingAnnotation = existing.remove(existing.size() - 1);
+ updateAnnotations(existingAnnotation, newPos, modifications, deletions);
+ } else {
+ additions.put(new FoldingAnnotation(false), newPos);
+ }
+ }
+
+ /**
+ * Update annotations.
+ *
+ * @param existingAnnotation the existing annotations that need to be updated
+ * based on the given dirtied IndexRegion
+ * @param newPos the new position that caused the annotations need
+ * for updating and null otherwise.
+ * @param modifications the list of annotations to be modified
+ * @param deletions the list of annotations to be deleted
+ */
+ protected void updateAnnotations(Annotation existingAnnotation, Position newPos, List<Annotation> modifications,
+ List<FoldingAnnotation> deletions) {
+ if (existingAnnotation instanceof FoldingAnnotation) {
+ FoldingAnnotation foldingAnnotation = (FoldingAnnotation) existingAnnotation;
+
+ // if a new position can be calculated then update the position of
+ // the annotation,
+ // else the annotation needs to be deleted
+ if (newPos != null && newPos.length > 0 && projectionAnnotationModel != null) {
+ Position oldPos = projectionAnnotationModel.getPosition(foldingAnnotation);
+ // only update the position if we have to
+ if (!newPos.equals(oldPos)) {
+ oldPos.setOffset(newPos.offset);
+ oldPos.setLength(newPos.length);
+ modifications.add(foldingAnnotation);
+ }
+ } else {
+ deletions.add(foldingAnnotation);
+ }
+ }
+ }
+
+ /**
+ * <p>
+ * Searches the given {@link DirtyRegion} for annotations that now have a length
+ * of 0. This is caused when something that was being folded has been deleted.
+ * These {@link FoldingAnnotation}s are then added to the {@link List} of
+ * {@link FoldingAnnotation}s to be deleted
+ * </p>
+ *
+ * @param dirtyRegion find the now invalid {@link FoldingAnnotation}s in this
+ * {@link DirtyRegion}
+ * @param deletions the current list of {@link FoldingAnnotation}s marked for
+ * deletion that the newly found invalid
+ * {@link FoldingAnnotation}s will be added to
+ */
+ protected void markInvalidAnnotationsForDeletion(DirtyRegion dirtyRegion, List<FoldingAnnotation> deletions,
+ List<FoldingAnnotation> existing) {
+ Iterator<Annotation> iter = getAnnotationIterator(dirtyRegion);
+ if (iter != null) {
+ while (iter.hasNext()) {
+ Annotation anno = iter.next();
+ if (anno instanceof FoldingAnnotation) {
+ FoldingAnnotation folding = (FoldingAnnotation) anno;
+ Position pos = projectionAnnotationModel.getPosition(anno);
+ if (pos.length == 0) {
+ deletions.add(folding);
+ } else {
+ existing.add(folding);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void reconcile(IRegion partition) {
+ // not used, we use:
+ // reconcile(DirtyRegion dirtyRegion, IRegion subRegion)
+ }
+
+ @Override
+ public void setProgressMonitor(IProgressMonitor monitor) {
+ // Do nothing
+ }
+
+ @Override
+ public void initialReconcile() {
+ reconcile(new DirtyRegion(0, document.getLength(), DirtyRegion.INSERT, document.get()), null);
+ }
} \ No newline at end of file
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java
index 40ed23496..a93f180da 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java
@@ -1,89 +1,89 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v20.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
- */
-package org.eclipse.ui.internal.genericeditor.preferences;
-
-import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.resource.ColorRegistry;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Preference initializer for Generic Editor plug-in.
- *
- * @since 1.2
- */
-public class GenericEditorPluginPreferenceInitializer extends AbstractPreferenceInitializer {
-
- @Override
- public void initializeDefaultPreferences() {
- IPreferenceStore store = GenericEditorPreferenceConstants.getPreferenceStore();
- GenericEditorPreferenceConstants.initializeDefaultValues(store);
- }
-
- public static void setThemeBasedPreferences(IPreferenceStore store, boolean fireEvent) {
- ColorRegistry registry = null;
- if (PlatformUI.isWorkbenchRunning())
- registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
-
- setDefault(store, GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR,
- findRGB(registry, IGenericEditorThemeConstants.EDITOR_MATCHING_BRACKETS_COLOR, new RGB(127, 0, 85)),
- fireEvent);
-
- }
-
- /**
- * Sets the default value and fires a property change event if necessary.
- *
- * @param store the preference store
- * @param key the preference key
- * @param newValue the new value
- * @param fireEvent <code>false</code> if no event should be fired
- * @since 1.2
- */
- private static void setDefault(IPreferenceStore store, String key, RGB newValue, boolean fireEvent) {
- if (!fireEvent) {
- PreferenceConverter.setDefault(store, key, newValue);
- return;
- }
-
- RGB oldValue = null;
- if (store.isDefault(key))
- oldValue = PreferenceConverter.getDefaultColor(store, key);
-
- PreferenceConverter.setDefault(store, key, newValue);
-
- if (oldValue != null && !oldValue.equals(newValue))
- store.firePropertyChangeEvent(key, oldValue, newValue);
- }
-
- /**
- * Returns the RGB for the given key in the given color registry.
- *
- * @param registry the color registry
- * @param key the key for the constant in the registry
- * @param defaultRGB the default RGB if no entry is found
- * @return RGB the RGB
- * @since 1.2
- */
- private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) {
- if (registry == null)
- return defaultRGB;
-
- RGB rgb = registry.getRGB(key);
- if (rgb != null)
- return rgb;
-
- return defaultRGB;
- }
-
-}
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Preference initializer for Generic Editor plug-in.
+ *
+ * @since 1.2
+ */
+public class GenericEditorPluginPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = GenericEditorPreferenceConstants.getPreferenceStore();
+ GenericEditorPreferenceConstants.initializeDefaultValues(store);
+ }
+
+ public static void setThemeBasedPreferences(IPreferenceStore store, boolean fireEvent) {
+ ColorRegistry registry = null;
+ if (PlatformUI.isWorkbenchRunning())
+ registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
+
+ setDefault(store, GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR,
+ findRGB(registry, IGenericEditorThemeConstants.EDITOR_MATCHING_BRACKETS_COLOR, new RGB(127, 0, 85)),
+ fireEvent);
+
+ }
+
+ /**
+ * Sets the default value and fires a property change event if necessary.
+ *
+ * @param store the preference store
+ * @param key the preference key
+ * @param newValue the new value
+ * @param fireEvent <code>false</code> if no event should be fired
+ * @since 1.2
+ */
+ private static void setDefault(IPreferenceStore store, String key, RGB newValue, boolean fireEvent) {
+ if (!fireEvent) {
+ PreferenceConverter.setDefault(store, key, newValue);
+ return;
+ }
+
+ RGB oldValue = null;
+ if (store.isDefault(key))
+ oldValue = PreferenceConverter.getDefaultColor(store, key);
+
+ PreferenceConverter.setDefault(store, key, newValue);
+
+ if (oldValue != null && !oldValue.equals(newValue))
+ store.firePropertyChangeEvent(key, oldValue, newValue);
+ }
+
+ /**
+ * Returns the RGB for the given key in the given color registry.
+ *
+ * @param registry the color registry
+ * @param key the key for the constant in the registry
+ * @param defaultRGB the default RGB if no entry is found
+ * @return RGB the RGB
+ * @since 1.2
+ */
+ private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) {
+ if (registry == null)
+ return defaultRGB;
+
+ RGB rgb = registry.getRGB(key);
+ if (rgb != null)
+ return rgb;
+
+ return defaultRGB;
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java
index 75dda6478..13660961f 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java
@@ -1,106 +1,106 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v20.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
- */
-package org.eclipse.ui.internal.genericeditor.preferences;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
-
-/**
- * Preference constants used in the Generic Editor preference store. Clients
- * should only read the Generic Editor preference store using these values.
- * Clients are not allowed to modify the preference store programmatically.
- * <p>
- * This class it is not intended to be instantiated or subclassed by clients.
- * </p>
- *
- * @since 1.2
- *
- * @noinstantiate This class is not intended to be instantiated by clients.
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class GenericEditorPreferenceConstants {
-
- private GenericEditorPreferenceConstants() {
-
- }
-
- /**
- * A named preference that controls whether bracket matching highlighting is
- * turned on or off.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- *
- * @since 1.2
- */
- public final static String EDITOR_MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$
-
- /**
- * A named preference that holds the color used to highlight matching brackets.
- * <p>
- * Value is of type <code>String</code>. A RGB color value encoded as a string
- * using class <code>PreferenceConverter</code>
- * </p>
- *
- * @see org.eclipse.jface.resource.StringConverter
- * @see org.eclipse.jface.preference.PreferenceConverter
- *
- * @since 1.2
- */
- public final static String EDITOR_MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$
-
- /**
- * A named preference that controls whether bracket at caret location is
- * highlighted or not.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- *
- * @since 1.2
- */
- public final static String EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION = "highlightBracketAtCaretLocation"; //$NON-NLS-1$
-
- /**
- * A named preference that controls whether enclosing bracket matching
- * highlighting is turned on or off.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- *
- * @since 1.2
- */
- public final static String EDITOR_ENCLOSING_BRACKETS = "enclosingBrackets"; //$NON-NLS-1$
-
- /**
- * Returns the Generic Editor preference store.
- *
- * @return the Generic Editor preference store
- */
- public static IPreferenceStore getPreferenceStore() {
- return GenericEditorPlugin.getDefault().getPreferenceStore();
- }
-
- /**
- * Initializes the given preference store with the default values.
- *
- * @param store the preference store to be initialized
- *
- * @since 1.2
- */
- public static void initializeDefaultValues(IPreferenceStore store) {
- store.setDefault(GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
- store.setDefault(GenericEditorPreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, false);
- store.setDefault(GenericEditorPreferenceConstants.EDITOR_ENCLOSING_BRACKETS, false);
- // Colors that are set by the current theme
- GenericEditorPluginPreferenceInitializer.setThemeBasedPreferences(store, false);
- }
-
-}
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
+
+/**
+ * Preference constants used in the Generic Editor preference store. Clients
+ * should only read the Generic Editor preference store using these values.
+ * Clients are not allowed to modify the preference store programmatically.
+ * <p>
+ * This class it is not intended to be instantiated or subclassed by clients.
+ * </p>
+ *
+ * @since 1.2
+ *
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public class GenericEditorPreferenceConstants {
+
+ private GenericEditorPreferenceConstants() {
+
+ }
+
+ /**
+ * A named preference that controls whether bracket matching highlighting is
+ * turned on or off.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$
+
+ /**
+ * A named preference that holds the color used to highlight matching brackets.
+ * <p>
+ * Value is of type <code>String</code>. A RGB color value encoded as a string
+ * using class <code>PreferenceConverter</code>
+ * </p>
+ *
+ * @see org.eclipse.jface.resource.StringConverter
+ * @see org.eclipse.jface.preference.PreferenceConverter
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$
+
+ /**
+ * A named preference that controls whether bracket at caret location is
+ * highlighted or not.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION = "highlightBracketAtCaretLocation"; //$NON-NLS-1$
+
+ /**
+ * A named preference that controls whether enclosing bracket matching
+ * highlighting is turned on or off.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_ENCLOSING_BRACKETS = "enclosingBrackets"; //$NON-NLS-1$
+
+ /**
+ * Returns the Generic Editor preference store.
+ *
+ * @return the Generic Editor preference store
+ */
+ public static IPreferenceStore getPreferenceStore() {
+ return GenericEditorPlugin.getDefault().getPreferenceStore();
+ }
+
+ /**
+ * Initializes the given preference store with the default values.
+ *
+ * @param store the preference store to be initialized
+ *
+ * @since 1.2
+ */
+ public static void initializeDefaultValues(IPreferenceStore store) {
+ store.setDefault(GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
+ store.setDefault(GenericEditorPreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, false);
+ store.setDefault(GenericEditorPreferenceConstants.EDITOR_ENCLOSING_BRACKETS, false);
+ // Colors that are set by the current theme
+ GenericEditorPluginPreferenceInitializer.setThemeBasedPreferences(store, false);
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java
index aad591abf..e65baf9ae 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java
@@ -1,31 +1,31 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v20.html
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
- */
-package org.eclipse.ui.internal.genericeditor.preferences;
-
-import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
-
-/**
- * Defines the constants used in the <code>org.eclipse.ui.themes</code>
- * extension contributed by this plug-in.
- *
- * @since 1.2
- */
-public interface IGenericEditorThemeConstants {
-
- String ID_PREFIX = GenericEditorPlugin.BUNDLE_ID + "."; //$NON-NLS-1$
-
- /**
- * Theme constant for the color used to highlight matching brackets.
- */
- public final String EDITOR_MATCHING_BRACKETS_COLOR = ID_PREFIX
- + GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
-
-}
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor.preferences;
+
+import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
+
+/**
+ * Defines the constants used in the <code>org.eclipse.ui.themes</code>
+ * extension contributed by this plug-in.
+ *
+ * @since 1.2
+ */
+public interface IGenericEditorThemeConstants {
+
+ String ID_PREFIX = GenericEditorPlugin.BUNDLE_ID + "."; //$NON-NLS-1$
+
+ /**
+ * Theme constant for the color used to highlight matching brackets.
+ */
+ public final String EDITOR_MATCHING_BRACKETS_COLOR = ID_PREFIX
+ + GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
+
+}

Back to the top