Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-01-11 19:33:48 -0500
committerGerrit Code Review @ Eclipse.org2017-01-25 16:50:46 -0500
commit81cbe876668119819deb101956e03f7490886be2 (patch)
treea087af878afcbff52bd76c4c3ee8250f4ff769b2
parent9526f139622e2a73cede8db90078fe48d2f8f516 (diff)
downloadorg.eclipse.cdt-81cbe876668119819deb101956e03f7490886be2.tar.gz
org.eclipse.cdt-81cbe876668119819deb101956e03f7490886be2.tar.xz
org.eclipse.cdt-81cbe876668119819deb101956e03f7490886be2.zip
Bug 391439 - Do not do replacement for help proposal with context information style
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java11
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java8
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java4
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTestBase.java230
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java214
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java1
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java56
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java10
8 files changed, 310 insertions, 224 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java
index fbc09be52b..9d8e8909a6 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java
@@ -79,14 +79,21 @@ public class BaseUITestCase extends BaseTestCase {
}
/**
+ * Reads a section in comments form the source of the given class.
+ */
+ protected String readTaggedComment(Class clazz, final String tag) throws IOException {
+ return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "ui", clazz, tag);
+ }
+
+ /**
* Reads a section in comments form the source of the given class. Fully
* equivalent to <code>readTaggedComment(getClass(), tag)</code>
* @since 4.0
*/
protected String readTaggedComment(final String tag) throws IOException {
- return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "ui", getClass(), tag);
+ return readTaggedComment(getClass(), tag);
}
-
+
/**
* Reads multiple sections in comments from the source of the given class.
* @since 4.0
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java
index 8ec2fe05a0..a61e2dfd9f 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java
@@ -35,7 +35,7 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
* Flag indicating whether this help provider should provide help info.
* Should be set to <code>true</code> during tests only.
*/
- static boolean fgEnabled= false;
+ public static boolean fgEnabled= false;
public CHelpTestInfoProvider(){
fProviderID = PROVIDER_ID_PREFIX + fNumProviders++;
@@ -90,9 +90,9 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
if (!fgEnabled) {
return new IFunctionSummary[0];
}
- Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized",fIsInitialized);
- return null; // TODO returning null until someone puts in a preference to control it.
- //return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks,prefix,fProviderID);
+ Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized", fIsInitialized);
+ //return null; // TODO returning null until someone puts in a preference to control it.
+ return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks, prefix, fProviderID);
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
index 96e5b54bc9..451bfedb50 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
@@ -61,7 +61,7 @@ import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
public abstract class AbstractContentAssistTest extends BaseUITestCase {
public static enum CompareType { ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION }
- private class ContentAssistResult {
+ protected class ContentAssistResult {
long startTime;
long endTime;
Object[] results;
@@ -124,7 +124,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
return CUIPlugin.getDefault().getPreferenceStore();
}
- private ContentAssistResult invokeContentAssist(int offset, int length, boolean isCompletion,
+ protected ContentAssistResult invokeContentAssist(int offset, int length, boolean isCompletion,
boolean isTemplate, boolean filterResults) throws Exception {
if (CTestPlugin.getDefault().isDebugging()) {
System.out.println("\n\n\n\n\nTesting " + this.getClass().getName());
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTestBase.java
new file mode 100644
index 0000000000..a8613f22ff
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTestBase.java
@@ -0,0 +1,230 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Nathan Ridge and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.text.contentassist2;
+
+import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.CONTEXT;
+import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.REPLACEMENT;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
+
+public class CompletionTestBase extends AbstractContentAssistTest {
+ private static final String HEADER_FILE_NAME = "CompletionTest.h";
+ private static final String SOURCE_FILE_NAME = "CompletionTest.cpp";
+ private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
+
+ protected int fCursorOffset;
+ private boolean fCheckExtraResults= true;
+ protected IProject fProject;
+
+ public CompletionTestBase(String name) {
+ super(name, true);
+ }
+
+ /*
+ * @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractCompletionTest#setUpProjectContent(org.eclipse.core.resources.IProject)
+ */
+ @Override
+ protected IFile setUpProjectContent(IProject project) throws Exception {
+ fProject= project;
+ String headerContent= readTaggedComment(CompletionTestBase.class, HEADER_FILE_NAME);
+ StringBuilder sourceContent= getContentsForTest(1)[0];
+ sourceContent.insert(0, "#include \"" + HEADER_FILE_NAME + "\"\n");
+ fCursorOffset= sourceContent.indexOf(CURSOR_LOCATION_TAG);
+ assertTrue("No cursor location specified", fCursorOffset >= 0);
+ sourceContent.delete(fCursorOffset, fCursorOffset + CURSOR_LOCATION_TAG.length());
+ assertNotNull(createFile(project, HEADER_FILE_NAME, headerContent));
+ return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
+ }
+
+ /*
+ * @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest#doCheckExtraResults()
+ */
+ @Override
+ protected boolean doCheckExtraResults() {
+ return fCheckExtraResults;
+ }
+
+ private void setCheckExtraResults(boolean check) {
+ fCheckExtraResults= check;
+ }
+
+ protected void assertMinimumCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
+ setCheckExtraResults(false);
+ try {
+ assertCompletionResults(offset, expected, compareType);
+ } finally {
+ setCheckExtraResults(true);
+ }
+ }
+
+ protected void assertCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
+ assertContentAssistResults(offset, expected, true, compareType);
+ }
+
+ protected void assertCompletionResults(String[] expected) throws Exception {
+ assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
+ }
+
+ protected void assertParameterHint(String[] expected) throws Exception {
+ assertContentAssistResults(fCursorOffset, expected, false, CONTEXT);
+ }
+
+ protected void assertDotReplacedWithArrow() throws Exception {
+ assertEquals("->", getDocument().get(fCursorOffset - 1, 2));
+ }
+
+ protected static void setDisplayDefaultArguments(boolean value) {
+ IPreferenceStore preferenceStore = getPreferenceStore();
+ preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS, value);
+ }
+
+ protected void setReplaceDotWithArrow(boolean value) {
+ IPreferenceStore preferenceStore = getPreferenceStore();
+ preferenceStore.setValue(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, value);
+ fProcessorNeedsConfiguring = true; // to pick up the modified auto-activation preference
+ }
+
+ protected static void setDisplayDefaultedParameters(boolean value) {
+ IPreferenceStore preferenceStore = getPreferenceStore();
+ preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT, value);
+ }
+
+ // {CompletionTest.h}
+ // class C1;
+ // class C2;
+ // class C3;
+ //
+ // extern C1* gC1;
+ // C2* gC2 = 0;
+ //
+ // extern C1* gfC1();
+ // C2* gfC2();
+ //
+ // enum E1 {e11, e12};
+ //
+ // class C1 {
+ // public:
+ // enum E2 {e21, e22};
+ //
+ // C1* fMySelf;
+ // void iam1();
+ //
+ // C1* m123();
+ // C1* m12();
+ // C1* m13();
+ //
+ // protected:
+ // void m1protected();
+ // private:
+ // void m1private();
+ // };
+ // typedef C1 T1;
+ // using A1 = C1;
+ //
+ // class C2 : public T1 {
+ // public:
+ // C2* fMySelf;
+ // void iam2();
+ //
+ // C2* m123();
+ // C2* m12();
+ // C2* m23();
+ // C1* operator()(int x);
+ //
+ // protected:
+ // void m2protected();
+ // private:
+ // void m2private();
+ // friend void _friend_function(C3* x);
+ // friend class _friend_class;
+ // };
+ // typedef C2 T2;
+ //
+ // class C3 : public C2 {
+ // public:
+ // C3* fMySelf;
+ // void iam3();
+ //
+ // C3* m123();
+ // C3* m13();
+ //
+ // template<typename T> T tConvert();
+ // protected:
+ // void m3protected();
+ // private:
+ // void m3private();
+ // };
+ // typedef C3 T3;
+ //
+ // namespace ns {
+ // const int NSCONST= 1;
+ // class CNS {
+ // void mcns();
+ // };
+ // };
+ // template <class T> class TClass {
+ // T fTField;
+ // public:
+ // TClass(T tArg) : fTField(tArg) {
+ // }
+ // T add(T tOther) {
+ // return fTField + tOther;
+ // }
+ // class NestedClass{};
+ // };
+ // // bug 109480
+ // class Printer
+ // {
+ // public:
+ // static void InitPrinter(unsigned char port);
+ // private:
+ // //Storage for port printer is on
+ // static unsigned char port;
+ // protected:
+ // };
+ // struct Struct1;
+ // struct Struct2;
+ // union Union1;
+ // union Union2;
+ // struct s206450 {
+ // struct {int a1; int a2;};
+ // union {int u1; char u2;};
+ // struct {int a3;} a4;
+ // int b;
+ // };
+ // typedef enum {__nix} _e204758;
+ // void _f204758(_e204758 x);
+ //
+ // // Bug 331056
+ // namespace _A_331056 {
+ // class Reference {};
+ // }
+ // namespace _B_331056 {
+ // using ::_A_331056::Reference;
+ // }
+ //
+ // template<typename T1, typename T2>
+ // struct Specialization {
+ // };
+ // template<typename T2>
+ // struct Specialization<int, T2> {
+ // };
+ // template<>
+ // struct Specialization<int, int> {
+ // };
+ //
+ // template<typename T1, typename T2>
+ // using AliasForSpecialization = Specialization<T1, T2>;
+ //
+ // template<typename T1, typename T2>
+ // using AliasForTemplateAlias = AliasForSpecialization<T1, T2>;
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
index 2a8044df1f..04b8ee4b0f 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
@@ -32,31 +32,20 @@ import java.util.Set;
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
-import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
-
/**
* A collection of code completion tests.
*
* @since 4.0
*/
-public class CompletionTests extends AbstractContentAssistTest {
- private static final String HEADER_FILE_NAME = "CompletionTest.h";
- private static final String SOURCE_FILE_NAME = "CompletionTest.cpp";
- private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
+public class CompletionTests extends CompletionTestBase {
private static final String DISTURB_FILE_NAME= "DisturbWith.cpp";
- protected int fCursorOffset;
- private boolean fCheckExtraResults= true;
- private IProject fProject;
-
// {DisturbWith.cpp}
// int gTemp;
// void gFunc();
@@ -73,213 +62,14 @@ public class CompletionTests extends AbstractContentAssistTest {
// class gnsClass {};
// };
- // {CompletionTest.h}
- // class C1;
- // class C2;
- // class C3;
- //
- // extern C1* gC1;
- // C2* gC2 = 0;
- //
- // extern C1* gfC1();
- // C2* gfC2();
- //
- // enum E1 {e11, e12};
- //
- // class C1 {
- // public:
- // enum E2 {e21, e22};
- //
- // C1* fMySelf;
- // void iam1();
- //
- // C1* m123();
- // C1* m12();
- // C1* m13();
- //
- // protected:
- // void m1protected();
- // private:
- // void m1private();
- // };
- // typedef C1 T1;
- // using A1 = C1;
- //
- // class C2 : public T1 {
- // public:
- // C2* fMySelf;
- // void iam2();
- //
- // C2* m123();
- // C2* m12();
- // C2* m23();
- // C1* operator()(int x);
- //
- // protected:
- // void m2protected();
- // private:
- // void m2private();
- // friend void _friend_function(C3* x);
- // friend class _friend_class;
- // };
- // typedef C2 T2;
- //
- // class C3 : public C2 {
- // public:
- // C3* fMySelf;
- // void iam3();
- //
- // C3* m123();
- // C3* m13();
- //
- // template<typename T> T tConvert();
- // protected:
- // void m3protected();
- // private:
- // void m3private();
- // };
- // typedef C3 T3;
- //
- // namespace ns {
- // const int NSCONST= 1;
- // class CNS {
- // void mcns();
- // };
- // };
- // template <class T> class TClass {
- // T fTField;
- // public:
- // TClass(T tArg) : fTField(tArg) {
- // }
- // T add(T tOther) {
- // return fTField + tOther;
- // }
- // class NestedClass{};
- // };
- // // bug 109480
- // class Printer
- // {
- // public:
- // static void InitPrinter(unsigned char port);
- // private:
- // //Storage for port printer is on
- // static unsigned char port;
- // protected:
- // };
- // struct Struct1;
- // struct Struct2;
- // union Union1;
- // union Union2;
- // struct s206450 {
- // struct {int a1; int a2;};
- // union {int u1; char u2;};
- // struct {int a3;} a4;
- // int b;
- // };
- // typedef enum {__nix} _e204758;
- // void _f204758(_e204758 x);
- //
- // // Bug 331056
- // namespace _A_331056 {
- // class Reference {};
- // }
- // namespace _B_331056 {
- // using ::_A_331056::Reference;
- // }
- //
- // template<typename T1, typename T2>
- // struct Specialization {
- // };
- // template<typename T2>
- // struct Specialization<int, T2> {
- // };
- // template<>
- // struct Specialization<int, int> {
- // };
- //
- // template<typename T1, typename T2>
- // using AliasForSpecialization = Specialization<T1, T2>;
- //
- // template<typename T1, typename T2>
- // using AliasForTemplateAlias = AliasForSpecialization<T1, T2>;
-
public CompletionTests(String name) {
- super(name, true);
+ super(name);
}
public static Test suite() {
return BaseTestCase.suite(CompletionTests.class, "_");
}
- /*
- * @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractCompletionTest#setUpProjectContent(org.eclipse.core.resources.IProject)
- */
- @Override
- protected IFile setUpProjectContent(IProject project) throws Exception {
- fProject= project;
- String headerContent= readTaggedComment(HEADER_FILE_NAME);
- StringBuilder sourceContent= getContentsForTest(1)[0];
- sourceContent.insert(0, "#include \"" + HEADER_FILE_NAME + "\"\n");
- fCursorOffset= sourceContent.indexOf(CURSOR_LOCATION_TAG);
- assertTrue("No cursor location specified", fCursorOffset >= 0);
- sourceContent.delete(fCursorOffset, fCursorOffset + CURSOR_LOCATION_TAG.length());
- assertNotNull(createFile(project, HEADER_FILE_NAME, headerContent));
- return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
- }
-
- /*
- * @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest#doCheckExtraResults()
- */
- @Override
- protected boolean doCheckExtraResults() {
- return fCheckExtraResults;
- }
-
- private void setCheckExtraResults(boolean check) {
- fCheckExtraResults= check;
- }
-
- private void assertMinimumCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
- setCheckExtraResults(false);
- try {
- assertCompletionResults(offset, expected, compareType);
- } finally {
- setCheckExtraResults(true);
- }
- }
-
- protected void assertCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
- assertContentAssistResults(offset, expected, true, compareType);
- }
-
- protected void assertCompletionResults(String[] expected) throws Exception {
- assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
- }
-
- protected void assertParameterHint(String[] expected) throws Exception {
- assertContentAssistResults(fCursorOffset, expected, false, CONTEXT);
- }
-
- protected void assertDotReplacedWithArrow() throws Exception {
- assertEquals("->", getDocument().get(fCursorOffset - 1, 2));
- }
-
- private static void setDisplayDefaultArguments(boolean value) {
- IPreferenceStore preferenceStore = getPreferenceStore();
- preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS, value);
- }
-
- private void setReplaceDotWithArrow(boolean value) {
- IPreferenceStore preferenceStore = getPreferenceStore();
- preferenceStore.setValue(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, value);
- fProcessorNeedsConfiguring = true; // to pick up the modified auto-activation preference
- }
-
- private static void setDisplayDefaultedParameters(boolean value) {
- IPreferenceStore preferenceStore = getPreferenceStore();
- preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT, value);
- }
-
//void gfunc() {C1 v; v.m/*cursor*/
public void testLocalVariable() throws Exception {
final String[] expected= {
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java
index 354cb986d2..6953925722 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java
@@ -70,6 +70,7 @@ public class ContentAssist2TestSuite extends TestSuite {
addTest(CompletionTest_VariableType_Prefix.suite());
addTest(CompletionTests.suite());
+ addTest(HelpProposalTests.suite());
addTest(CompletionTests_PlainC.suite());
addTest(ParameterHintTests.suite());
addTest(CPPParameterGuessingTests.suite());
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java
new file mode 100644
index 0000000000..045794f4fd
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Nathan Ridge.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.text.contentassist2;
+
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
+import org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider;
+
+import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
+
+import junit.framework.Test;
+
+/**
+ * Tests for {@link org.eclipse.cdt.internal.ui.text.contentassist.HelpCompletionProposalComputer}.
+ */
+public class HelpProposalTests extends CompletionTestBase {
+ private boolean fOldTestInfoProviderEnablement;
+
+ public HelpProposalTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return BaseTestCase.suite(HelpProposalTests.class, "_");
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ fOldTestInfoProviderEnablement = CHelpTestInfoProvider.fgEnabled;
+ CHelpTestInfoProvider.fgEnabled = true;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ CHelpTestInfoProvider.fgEnabled = fOldTestInfoProviderEnablement;
+ super.tearDown();
+ }
+
+ // int main() {
+ // setvbuf(file, NULL, _IOLBF, /*cursor*/);
+ // }
+ public void testHelpProposalClobberingTokens_391439() throws Exception {
+ Object[] results = invokeContentAssist(fCursorOffset, 0, true, false, true).results;
+ assertEquals(1, results.length);
+ assertInstance(results[0], CCompletionProposal.class);
+ CCompletionProposal proposal = ((CCompletionProposal) results[0]);
+ assertEquals(0, proposal.getReplacementLength());
+ assertEquals("", proposal.getReplacementString());
+ assertNotNull(proposal.getContextInformation());
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java
index 76ec652655..1d6ee99205 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java
@@ -96,8 +96,9 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
if (summaries == null)
return Collections.emptyList();
- int repOffset = cContext.getInvocationOffset() - prefix.length();
- int repLength = prefix.length();
+ boolean doReplacement = !cContext.isContextInformationStyle();
+ int repLength = doReplacement ? prefix.length() : 0;
+ int repOffset = cContext.getInvocationOffset() - repLength;
Image image = CUIPlugin.getImageDescriptorRegistry().get(
CElementImageProvider.getFunctionImageDescriptor());
@@ -110,10 +111,12 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
.getPrototype();
String fargs = fproto.getArguments();
+ String repString = doReplacement ? fname : ""; //$NON-NLS-1$
+
int relevance = computeBaseRelevance(prefix, summary.getName()) + RelevanceConstants.HELP_TYPE_RELEVANCE;
CCompletionProposal proposal;
proposal = new CCompletionProposal(
- fname,
+ repString,
repOffset,
repLength,
image,
@@ -147,5 +150,4 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
return proposals;
}
-
}

Back to the top