mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Bug 461527 - Replacing dot with arrow during content assist for typedef
to pointer type Change-Id: Ie81106bda1ad82ce487b6e9df5e74c308c3c9e88 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
5d2f7bcb56
commit
1e8964285e
3 changed files with 44 additions and 8 deletions
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||
|
||||
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.TextUtilities;
|
||||
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
||||
|
@ -35,6 +36,7 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
|
|||
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
|
||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||
|
@ -46,6 +48,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
|
|||
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
|
||||
|
||||
public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||
|
@ -57,6 +60,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
|||
private IFile fCFile;
|
||||
protected ITextEditor fEditor;
|
||||
private final boolean fIsCpp;
|
||||
protected boolean fProcessorNeedsConfiguring;
|
||||
|
||||
public AbstractContentAssistTest(String name, boolean isCpp) {
|
||||
super(name);
|
||||
|
@ -99,6 +103,10 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
protected static IPreferenceStore getPreferenceStore() {
|
||||
return CUIPlugin.getDefault().getPreferenceStore();
|
||||
}
|
||||
|
||||
protected void assertContentAssistResults(int offset, int length, String[] expected,
|
||||
boolean isCompletion, boolean isTemplate, boolean filterResults, CompareType compareType) throws Exception {
|
||||
if (CTestPlugin.getDefault().isDebugging()) {
|
||||
|
@ -111,6 +119,10 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
|||
boolean isCode= IDocument.DEFAULT_CONTENT_TYPE.equals(contentType);
|
||||
ContentAssistant assistant = new ContentAssistant();
|
||||
CContentAssistProcessor processor = new CContentAssistProcessor(fEditor, assistant, contentType);
|
||||
assistant.setContentAssistProcessor(processor, contentType);
|
||||
if (fProcessorNeedsConfiguring) {
|
||||
ContentAssistPreference.configure(assistant, getPreferenceStore());
|
||||
}
|
||||
long startTime= System.currentTimeMillis();
|
||||
sourceViewer.setSelectedRange(offset, length);
|
||||
Object[] results = isCompletion ?
|
||||
|
|
|
@ -38,7 +38,6 @@ 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.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
||||
|
||||
|
@ -259,21 +258,27 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
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);
|
||||
}
|
||||
|
||||
private static IPreferenceStore getPreferenceStore() {
|
||||
return CUIPlugin.getDefault().getPreferenceStore();
|
||||
}
|
||||
|
||||
//void gfunc() {C1 v; v.m/*cursor*/
|
||||
public void testLocalVariable() throws Exception {
|
||||
final String[] expected= {
|
||||
|
@ -1682,8 +1687,23 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
// void test(B<T> b) {
|
||||
// b.val./*cursor*/
|
||||
// }
|
||||
public void testFieldOfDeferredClassInstance_Bug402617() throws Exception {
|
||||
public void testFieldOfDeferredClassInstance_bug402617() throws Exception {
|
||||
final String[] expected = { "A", "foo(void)" };
|
||||
assertContentAssistResults(fCursorOffset, expected, true, ID);
|
||||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
// struct A {
|
||||
// int foo;
|
||||
// };
|
||||
// typedef A* B;
|
||||
// int main() {
|
||||
// B waldo;
|
||||
// waldo./*cursor*/
|
||||
// }
|
||||
public void testDotToArrowConversionForTypedef_bug461527() throws Exception {
|
||||
setReplaceDotWithArrow(true);
|
||||
final String[] expected = { "A", "foo : int" };
|
||||
assertCompletionResults(fCursorOffset, expected, DISPLAY);
|
||||
assertDotReplacedWithArrow();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,14 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
|
||||
import org.eclipse.cdt.ui.text.contentassist.IProposalFilter;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.ProposalFilterPreferencesUtil;
|
||||
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
|
||||
|
@ -269,7 +272,8 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
|||
if (names.length > 0 && names[0].getParent() instanceof IASTFieldReference) {
|
||||
IASTFieldReference ref = (IASTFieldReference) names[0].getParent();
|
||||
IASTExpression ownerExpr = ref.getFieldOwner();
|
||||
if (ownerExpr.getExpressionType() instanceof IPointerType) {
|
||||
IType ownerExprType = SemanticUtil.getNestedType(ownerExpr.getExpressionType(), SemanticUtil.TDEF);
|
||||
if (ownerExprType instanceof IPointerType) {
|
||||
context = replaceDotWithArrow(viewer, offset, isCompletion, context, activationChar);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue