diff --git a/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF
index b5840024b7..8fec3da593 100644
--- a/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF
@@ -120,6 +120,7 @@ Require-Bundle:
org.eclipse.equinox.security;bundle-version="[1.4.100,2.0.0)"
Import-Package: aQute.bnd.build.model;version="[4.2.0,5.0.0)",
aQute.bnd.header;version="[2.5.0,3.0.0)",
+ aQute.bnd.help;version="2.0.0",
aQute.bnd.osgi;version="[5.6.0,8.0.0)",
aQute.bnd.osgi.repository;version="[3.0.0,4.0.0)",
aQute.bnd.osgi.resource;version="[4.3.0,6.0.0)",
diff --git a/ui/org.eclipse.pde.ui/plugin.xml b/ui/org.eclipse.pde.ui/plugin.xml
index 9a713430e7..e661957143 100644
--- a/ui/org.eclipse.pde.ui/plugin.xml
+++ b/ui/org.eclipse.pde.ui/plugin.xml
@@ -2478,8 +2478,22 @@
+
+
+
+
+
+
+
+
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndCompletionProcessor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndCompletionProcessor.java
index c6542cf98f..55add9d025 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndCompletionProcessor.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndCompletionProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2022 bndtools project.
+ * Copyright (c) 2011, 2023 bndtools project and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,8 +13,9 @@
* Ferry Huberts - ongoing enhancements
* Neil Bartlett - ongoing enhancements
* BJ Hargrave - ongoing enhancements
+ * Christoph Läubrich - adjust to coding conventions, fix missing completions on empty lines
*******************************************************************************/
-package bndtools.editor.completion;
+package org.eclipse.pde.internal.ui.bndtools;
import java.util.ArrayList;
import java.util.Collections;
@@ -22,6 +23,8 @@
import java.util.regex.Pattern;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ContextInformation;
@@ -34,24 +37,27 @@
public class BndCompletionProcessor implements IContentAssistProcessor {
- private static final Pattern PREFIX_PATTERN = Pattern.compile("(\\S+)$");
+ private static final Pattern PREFIX_PATTERN = Pattern.compile("(\\S+)$"); //$NON-NLS-1$
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
try {
- String pre = viewer.getDocument()
- .get(0, offset);
- Matcher matcher = PREFIX_PATTERN.matcher(pre);
- if (matcher.find()) {
- String prefix = matcher.group(1);
- ICompletionProposal[] found = proposals(prefix, offset);
- if (found.length == 1) {
- found[0].apply(viewer.getDocument());
- viewer.setSelectedRange(offset + (found[0].getDisplayString()
- .length() - prefix.length() + 2), 0);
- return new ICompletionProposal[0];
+ IDocument document = viewer.getDocument();
+ IRegion lineInfo = document.getLineInformationOfOffset(offset);
+ if (lineInfo.getOffset() != offset) {
+ String pre = document.get(0, offset);
+ Matcher matcher = PREFIX_PATTERN.matcher(pre);
+ if (matcher.find()) {
+ String prefix = matcher.group(1);
+ ICompletionProposal[] found = proposals(prefix, offset);
+ if (found.length == 1) {
+ found[0].apply(document);
+ viewer.setSelectedRange(offset + (found[0].getDisplayString().length() - prefix.length() + 2),
+ 0);
+ return new ICompletionProposal[0];
+ }
+ return found;
}
- return found;
}
return proposals(null, offset);
} catch (BadLocationException e) {
@@ -79,7 +85,6 @@ private static ICompletionProposal[] proposals(String prefix, int offset) {
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- // TODO Auto-generated method stub
return null;
}
@@ -99,13 +104,11 @@ public char[] getContextInformationAutoActivationCharacters() {
@Override
public IContextInformationValidator getContextInformationValidator() {
- // TODO Auto-generated method stub
return null;
}
@Override
public String getErrorMessage() {
- // TODO Auto-generated method stub
return null;
}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndScanner.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndScanner.java
index bf3752be33..b425f4b7d7 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndScanner.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/BndScanner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2023 bndtools project.
+ * Copyright (c) 2011, 2023 bndtools project and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,29 +15,48 @@
* BJ Hargrave - ongoing enhancements
* Amit Kumar Mondal - ongoing enhancements
* Peter Kriens - ongoing enhancements
+ * Christoph Läubrich - incline code from BndSourceViewerConfiguration regarding colors, adjust to eclipse coding conventions
*******************************************************************************/
-package bndtools.editor.completion;
+package org.eclipse.pde.internal.ui.bndtools;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
+import org.eclipse.jdt.ui.text.IColorManager;
+import org.eclipse.jdt.ui.text.IJavaColorConstants;
+import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.RGB;
import aQute.bnd.help.Syntax;
import aQute.bnd.osgi.Constants;
public class BndScanner extends RuleBasedScanner {
- BndSourceViewerConfiguration bsvc;
final Set instructions;
final Set directives = new HashSet<>();
-
- public BndScanner(BndSourceViewerConfiguration manager) {
- bsvc = manager;
+ private Token T_DEFAULT;
+ private Token T_KEY;
+ private Token T_ERROR;
+ private Token T_COMMENT;
+ private Token T_INSTRUCTION;
+ private Token T_OPTION;
+
+ public BndScanner(IColorManager colorManager) {
+ T_DEFAULT = new Token(new TextAttribute(colorManager.getColor(IJavaColorConstants.JAVA_DEFAULT)));
+ T_KEY = new Token(new TextAttribute(colorManager.getColor(IJavaColorConstants.JAVADOC_LINK), null, SWT.NONE));
+ T_ERROR = new Token(new TextAttribute(colorManager.getColor(IJavaColorConstants.JAVA_KEYWORD),
+ colorManager.getColor(new RGB(255, 0, 0)), SWT.BOLD));
+ T_COMMENT = new Token(new TextAttribute(colorManager.getColor(IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT)));
+ T_INSTRUCTION = new Token(
+ new TextAttribute(colorManager.getColor(IJavaColorConstants.JAVADOC_KEYWORD), null, SWT.BOLD));
+ T_OPTION = new Token(
+ new TextAttribute(colorManager.getColor(IJavaColorConstants.JAVADOC_LINK), null, SWT.BOLD));
instructions = Syntax.HELP.values()
.stream()
.map(Syntax::getHeader)
@@ -55,7 +74,7 @@ public BndScanner(BndSourceViewerConfiguration manager) {
};
setRules(rules);
- setDefaultReturnToken(bsvc.T_DEFAULT);
+ setDefaultReturnToken(T_DEFAULT);
}
IToken comment(ICharacterScanner scanner) {
@@ -76,13 +95,12 @@ IToken comment(ICharacterScanner scanner) {
n++;
if (c == '\n' || c == '\r' || c == ICharacterScanner.EOF)
- return bsvc.T_COMMENT;
+ return T_COMMENT;
}
- } else {
- while (n-- > 0)
- scanner.unread();
- return Token.UNDEFINED;
}
+ while (n-- > 0)
+ scanner.unread();
+ return Token.UNDEFINED;
}
}
@@ -124,14 +142,14 @@ IToken keyword(ICharacterScanner scanner) {
String key = sb.toString();
if (Constants.options.contains(key)) {
- return bsvc.T_OPTION;
+ return T_OPTION;
}
if (instructions.contains(key)) {
- return bsvc.T_INSTRUCTION;
+ return T_INSTRUCTION;
}
- return bsvc.T_KEY;
+ return T_KEY;
}
IToken error(ICharacterScanner scanner) {
@@ -145,7 +163,7 @@ IToken error(ICharacterScanner scanner) {
c = scanner.read();
}
scanner.unread();
- return bsvc.T_ERROR;
+ return T_ERROR;
}
}
while (n-- > 0)
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/MacroRule.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/MacroRule.java
index 0aea03b4ae..d4f3bffa44 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/MacroRule.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/bndtools/MacroRule.java
@@ -13,7 +13,7 @@
* Neil Bartlett - ongoing enhancements
* BJ Hargrave - ongoing enhancements
*******************************************************************************/
-package bndtools.editor.completion;
+package org.eclipse.pde.internal.ui.bndtools;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BNDPresentationReconciler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BNDPresentationReconciler.java
new file mode 100644
index 0000000000..736668b1cb
--- /dev/null
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BNDPresentationReconciler.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2023 Christoph Läubrich 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:
+ * Christoph Läubrich - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.ui.editor.bnd;
+
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.pde.internal.ui.bndtools.BndScanner;
+
+public class BNDPresentationReconciler extends PresentationReconciler {
+ public BNDPresentationReconciler() {
+ BndScanner scanner = new BndScanner(JavaUI.getColorManager());
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
+ this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BndAutoCompleteProcessor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BndBuildPathAutoCompleteProcessor.java
similarity index 98%
rename from ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BndAutoCompleteProcessor.java
rename to ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BndBuildPathAutoCompleteProcessor.java
index 13c4e61f0e..8f0fbe4e58 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BndAutoCompleteProcessor.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/bnd/BndBuildPathAutoCompleteProcessor.java
@@ -33,7 +33,7 @@
import aQute.bnd.properties.LineType;
import aQute.bnd.properties.PropertiesLineReader;
-public class BndAutoCompleteProcessor implements IContentAssistProcessor {
+public class BndBuildPathAutoCompleteProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {