mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 02:05:39 +02:00
Bug 391439 - Do not do replacement for help proposal with context information style
Change-Id: I4d8988e9601e1f1b9722830b61cbf2d4c564a4cd
This commit is contained in:
parent
b434f0d78d
commit
73d5df1550
8 changed files with 309 additions and 223 deletions
|
@ -78,13 +78,20 @@ public class BaseUITestCase extends BaseTestCase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Reads a section in comments form the source of the given class. Fully
|
||||||
* equivalent to <code>readTaggedComment(getClass(), tag)</code>
|
* equivalent to <code>readTaggedComment(getClass(), tag)</code>
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
protected String readTaggedComment(final String tag) throws IOException {
|
protected String readTaggedComment(final String tag) throws IOException {
|
||||||
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "ui", getClass(), tag);
|
return readTaggedComment(getClass(), tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
|
||||||
* Flag indicating whether this help provider should provide help info.
|
* Flag indicating whether this help provider should provide help info.
|
||||||
* Should be set to <code>true</code> during tests only.
|
* Should be set to <code>true</code> during tests only.
|
||||||
*/
|
*/
|
||||||
static boolean fgEnabled= false;
|
public static boolean fgEnabled= false;
|
||||||
|
|
||||||
public CHelpTestInfoProvider() {
|
public CHelpTestInfoProvider() {
|
||||||
fProviderID = PROVIDER_ID_PREFIX + fNumProviders++;
|
fProviderID = PROVIDER_ID_PREFIX + fNumProviders++;
|
||||||
|
@ -77,8 +77,8 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
|
||||||
return new IFunctionSummary[0];
|
return new IFunctionSummary[0];
|
||||||
}
|
}
|
||||||
Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized", fIsInitialized);
|
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 null; // TODO returning null until someone puts in a preference to control it.
|
||||||
//return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks, prefix, fProviderID);
|
return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks, prefix, fProviderID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,7 +61,7 @@ import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
|
||||||
public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
public static enum CompareType { ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION }
|
public static enum CompareType { ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION }
|
||||||
|
|
||||||
private class ContentAssistResult {
|
protected class ContentAssistResult {
|
||||||
long startTime;
|
long startTime;
|
||||||
long endTime;
|
long endTime;
|
||||||
Object[] results;
|
Object[] results;
|
||||||
|
@ -124,7 +124,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
return CUIPlugin.getDefault().getPreferenceStore();
|
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 {
|
boolean isTemplate, boolean filterResults) throws Exception {
|
||||||
if (CTestPlugin.getDefault().isDebugging()) {
|
if (CTestPlugin.getDefault().isDebugging()) {
|
||||||
System.out.println("\n\n\n\n\nTesting " + this.getClass().getName());
|
System.out.println("\n\n\n\n\nTesting " + this.getClass().getName());
|
||||||
|
|
|
@ -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>;
|
||||||
|
}
|
|
@ -32,31 +32,20 @@ import java.util.Set;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
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.jface.text.IDocument;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of code completion tests.
|
* A collection of code completion tests.
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class CompletionTests extends AbstractContentAssistTest {
|
public class CompletionTests extends CompletionTestBase {
|
||||||
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*/";
|
|
||||||
private static final String DISTURB_FILE_NAME= "DisturbWith.cpp";
|
private static final String DISTURB_FILE_NAME= "DisturbWith.cpp";
|
||||||
|
|
||||||
protected int fCursorOffset;
|
|
||||||
private boolean fCheckExtraResults= true;
|
|
||||||
private IProject fProject;
|
|
||||||
|
|
||||||
// {DisturbWith.cpp}
|
// {DisturbWith.cpp}
|
||||||
// int gTemp;
|
// int gTemp;
|
||||||
// void gFunc();
|
// void gFunc();
|
||||||
|
@ -73,213 +62,14 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
// class gnsClass {};
|
// 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) {
|
public CompletionTests(String name) {
|
||||||
super(name, true);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return BaseTestCase.suite(CompletionTests.class, "_");
|
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*/
|
//void gfunc() {C1 v; v.m/*cursor*/
|
||||||
public void testLocalVariable() throws Exception {
|
public void testLocalVariable() throws Exception {
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class ContentAssist2TestSuite extends TestSuite {
|
||||||
addTest(CompletionTest_VariableType_Prefix.suite());
|
addTest(CompletionTest_VariableType_Prefix.suite());
|
||||||
|
|
||||||
addTest(CompletionTests.suite());
|
addTest(CompletionTests.suite());
|
||||||
|
addTest(HelpProposalTests.suite());
|
||||||
addTest(CompletionTests_PlainC.suite());
|
addTest(CompletionTests_PlainC.suite());
|
||||||
addTest(ParameterHintTests.suite());
|
addTest(ParameterHintTests.suite());
|
||||||
addTest(CPPParameterGuessingTests.suite());
|
addTest(CPPParameterGuessingTests.suite());
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -96,8 +96,9 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
if (summaries == null)
|
if (summaries == null)
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
||||||
int repOffset = cContext.getInvocationOffset() - prefix.length();
|
boolean doReplacement = !cContext.isContextInformationStyle();
|
||||||
int repLength = prefix.length();
|
int repLength = doReplacement ? prefix.length() : 0;
|
||||||
|
int repOffset = cContext.getInvocationOffset() - repLength;
|
||||||
Image image = CUIPlugin.getImageDescriptorRegistry().get(
|
Image image = CUIPlugin.getImageDescriptorRegistry().get(
|
||||||
CElementImageProvider.getFunctionImageDescriptor());
|
CElementImageProvider.getFunctionImageDescriptor());
|
||||||
|
|
||||||
|
@ -110,10 +111,12 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
.getPrototype();
|
.getPrototype();
|
||||||
String fargs = fproto.getArguments();
|
String fargs = fproto.getArguments();
|
||||||
|
|
||||||
|
String repString = doReplacement ? fname : ""; //$NON-NLS-1$
|
||||||
|
|
||||||
int relevance = computeBaseRelevance(prefix, summary.getName()) + RelevanceConstants.HELP_TYPE_RELEVANCE;
|
int relevance = computeBaseRelevance(prefix, summary.getName()) + RelevanceConstants.HELP_TYPE_RELEVANCE;
|
||||||
CCompletionProposal proposal;
|
CCompletionProposal proposal;
|
||||||
proposal = new CCompletionProposal(
|
proposal = new CCompletionProposal(
|
||||||
fname,
|
repString,
|
||||||
repOffset,
|
repOffset,
|
||||||
repLength,
|
repLength,
|
||||||
image,
|
image,
|
||||||
|
@ -147,5 +150,4 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
return proposals;
|
return proposals;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue