From f49237262dc7977acd1c7bfb6239881dd3d3563b Mon Sep 17 00:00:00 2001 From: Neil Guzman Date: Tue, 11 Jun 2013 10:45:23 -0400 Subject: rpm: Autocompletion fix for pkgs with '.' or '+' Previously autocompletion would break when encountering a '.' or '+' (e.g. java-1.* or libstdc++). Fixed by allowing '.' and '+' as acceptable characters to check for amend: added test case Change-Id: Ic5f10c960a18491808c1dec06474a468e5f11975 Reviewed-on: https://git.eclipse.org/r/13749 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov IP-Clean: Alexander Kurtakov Tested-by: Alexander Kurtakov --- .../tests/SpecfileCompletionProcessorTest.java | 53 +++++++++++++++++++++- .../rpm/ui/editor/SpecfileCompletionProcessor.java | 2 +- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/SpecfileCompletionProcessorTest.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/SpecfileCompletionProcessorTest.java index 26763c4f72..e3dfd34fc7 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/SpecfileCompletionProcessorTest.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor.tests/src/org/eclipse/linuxtools/rpm/ui/editor/tests/SpecfileCompletionProcessorTest.java @@ -32,7 +32,10 @@ public class SpecfileCompletionProcessorTest extends FileTestCase { + "Source3: main.tar.gz"; private static final String BUILD_REQUIRES = "BuildRequires: p"; - + + private static final String NON_ALPHA_DOT = "Requires: java-1."; + private static final String NON_ALPHA_PLUS = "Requires: libstdc+"; + private SpecfileEditor initEditor(String contents) throws Exception { newFile(contents); IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench() @@ -106,4 +109,52 @@ public class SpecfileCompletionProcessorTest extends FileTestCase { } } + + @Test + public void testBRCompletionNonAlphaDot() throws Exception { + setPackageList(new String[]{"java-1.5.0-gcj", "java-1.7.0-openjdk", "java-1.7.0-openjdk-devel", "java-1.7.0-openjdk-javadoc"}); + SpecfileEditor editor = initEditor(NON_ALPHA_DOT); + testProject.refresh(); + // This is needed so the changes in the testFile are loaded in the + // editor + editor.doRevertToSaved(); + SpecfileCompletionProcessor complProcessor = new SpecfileCompletionProcessor( + editor); + assertNotNull(complProcessor); + editor.getSpecfileSourceViewer().setSelectedRange(NON_ALPHA_DOT.length(), 0); + ICompletionProposal[] proposals = complProcessor + .computeCompletionProposals(editor.getSpecfileSourceViewer(), NON_ALPHA_DOT.length()); + int sourceComplCount = 0; + for (int i = 0; i < proposals.length; i++) { + ICompletionProposal proposal = proposals[i]; + if (proposal.getDisplayString().startsWith("java-1.")) { + ++sourceComplCount; + } + } + assertEquals(4, sourceComplCount); + } + + @Test + public void testBRCompletionNonAlphaPlus() throws Exception { + setPackageList(new String[]{"libstdc++", "libstdc++-devel"}); + SpecfileEditor editor = initEditor(NON_ALPHA_PLUS); + testProject.refresh(); + // This is needed so the changes in the testFile are loaded in the + // editor + editor.doRevertToSaved(); + SpecfileCompletionProcessor complProcessor = new SpecfileCompletionProcessor( + editor); + assertNotNull(complProcessor); + editor.getSpecfileSourceViewer().setSelectedRange(NON_ALPHA_PLUS.length(), 0); + ICompletionProposal[] proposals = complProcessor + .computeCompletionProposals(editor.getSpecfileSourceViewer(), NON_ALPHA_PLUS.length()); + int sourceComplCount = 0; + for (int i = 0; i < proposals.length; i++) { + ICompletionProposal proposal = proposals[i]; + if (proposal.getDisplayString().startsWith("libstdc+")) { + ++sourceComplCount; + } + } + assertEquals(2, sourceComplCount); + } } diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileCompletionProcessor.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileCompletionProcessor.java index 29d4d793db..b1b3b71b97 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileCompletionProcessor.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileCompletionProcessor.java @@ -458,7 +458,7 @@ public class SpecfileCompletionProcessor implements IContentAssistProcessor { try { while (i > 0) { char ch = document.getChar(i - 1); - if (!Character.isLetterOrDigit(ch) && (ch != '%') && (ch != '_') && (ch != '-') && (ch != '{')) { + if (!Character.isLetterOrDigit(ch) && (ch != '%') && (ch != '_') && (ch != '-') && (ch != '{') && (ch != '.') && (ch != '+')) { break; } i--; -- cgit v1.2.3