mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
Bug 418493 - [Content Assist] Show default values within parameter hints
Preferences: - Displaying parameters with default argument - Displaying default arguments Default arguments for functions and templates. Conflicts: core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java Conflicts: core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java Rebased to changed parent Change-Id: Ifb505f5723dc26212c34f492d3d49b7badf366ea Signed-off-by: Thomas Corbat <tcorbat@hsr.ch> Reviewed-on: https://git.eclipse.org/r/30646 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Hudson CI
This commit is contained in:
parent
742c1d9ee8
commit
ac8965a904
6 changed files with 177 additions and 3 deletions
|
@ -26,11 +26,15 @@ 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.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.ui.CUIPlugin;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
||||||
|
|
||||||
import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.*;
|
import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.*;
|
||||||
|
|
||||||
|
@ -244,6 +248,20 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
assertContentAssistResults(fCursorOffset, expected, false, CONTEXT);
|
assertContentAssistResults(fCursorOffset, expected, false, CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setDisplayDefaultArguments(boolean value) {
|
||||||
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
|
preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
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*/
|
//void gfunc() {C1 v; v.m/*cursor*/
|
||||||
public void testLocalVariable() throws Exception {
|
public void testLocalVariable() throws Exception {
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
|
@ -1415,4 +1433,80 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
final String[] expectedID = { "C1", "C2", "C3" };
|
final String[] expectedID = { "C1", "C2", "C3" };
|
||||||
assertContentAssistResults(fCursorOffset, expectedID, true, ID);
|
assertContentAssistResults(fCursorOffset, expectedID, true, ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void default_argument(int i = 23) {
|
||||||
|
// default_arg/*cursor*/
|
||||||
|
// }
|
||||||
|
public void testDefaultFunctionArgument() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(true);
|
||||||
|
setDisplayDefaultArguments(true);
|
||||||
|
final String[] expectedDisplay = { "default_argument(int i = 23) : void" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
final String[] expectedReplacement = { "default_argument()" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedReplacement, true, REPLACEMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void default_argument(int i = 23) {
|
||||||
|
// default_arg/*cursor*/
|
||||||
|
// }
|
||||||
|
public void testNoDefaultFunctionArgument() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(true);
|
||||||
|
setDisplayDefaultArguments(false);
|
||||||
|
final String[] expectedDisplay = { "default_argument(int i) : void" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void default_argument(int i = 23) {
|
||||||
|
// default_arg/*cursor*/
|
||||||
|
// }
|
||||||
|
public void testNoDefaultFunctionParameter() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(false);
|
||||||
|
setDisplayDefaultArguments(false);
|
||||||
|
final String[] expectedDisplay = { "default_argument() : void" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T = int>
|
||||||
|
// struct default_argument {};
|
||||||
|
// default_arg/*cursor*/
|
||||||
|
public void testDefaultTemplateArgument() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(true);
|
||||||
|
setDisplayDefaultArguments(true);
|
||||||
|
final String[] expectedDisplay = { "default_argument<typename T = int>" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
final String[] expectedReplacement = { "default_argument<>" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedReplacement, true, REPLACEMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T = int>
|
||||||
|
// struct default_argument {};
|
||||||
|
// default_arg/*cursor*/
|
||||||
|
public void testNoDefaultTemplateArgument() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(true);
|
||||||
|
setDisplayDefaultArguments(false);
|
||||||
|
final String[] expectedDisplay = { "default_argument<typename T>" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T = int>
|
||||||
|
// struct default_argument {};
|
||||||
|
// default_arg/*cursor*/
|
||||||
|
public void testNoDefaultTemplateParameter() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(false);
|
||||||
|
setDisplayDefaultArguments(false);
|
||||||
|
final String[] expectedDisplay = { "default_argument<>" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// struct tpl {};
|
||||||
|
// template<typename T1, typename T2 = tpl<T1>>
|
||||||
|
// struct other_tpl {};
|
||||||
|
// other_tpl/*cursor*/
|
||||||
|
public void testDefaultTemplateTemplateArgument() throws Exception {
|
||||||
|
setDisplayDefaultedParameters(true);
|
||||||
|
setDisplayDefaultArguments(true);
|
||||||
|
final String[] expectedDisplay = { "other_tpl<typename T1, typename T2 = tpl<T1>>" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2011 QNX Software Systems and others.
|
* Copyright (c) 2002, 2014 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Kirk Beitz (Nokia)
|
* Kirk Beitz (Nokia)
|
||||||
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
||||||
|
* Thomas Corbat
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.preferences;
|
package org.eclipse.cdt.internal.ui.preferences;
|
||||||
|
@ -20,13 +21,13 @@ import java.util.ArrayList;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
|
import org.eclipse.swt.widgets.Button;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Control;
|
||||||
import org.eclipse.swt.widgets.Group;
|
import org.eclipse.swt.widgets.Group;
|
||||||
import org.eclipse.ui.IWorkbench;
|
import org.eclipse.ui.IWorkbench;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
|
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
|
||||||
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
||||||
|
@ -56,6 +57,8 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
|
||||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW));
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW));
|
||||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON));
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON));
|
||||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW));
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW));
|
||||||
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT));
|
||||||
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS));
|
||||||
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_DOCUMENTED_PROPOSALS));
|
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_DOCUMENTED_PROPOSALS));
|
||||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ORDER_PROPOSALS));
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ORDER_PROPOSALS));
|
||||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES));
|
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES));
|
||||||
|
@ -149,6 +152,22 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
|
||||||
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_autoActivationDelay;
|
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_autoActivationDelay;
|
||||||
addTextField(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_DELAY, 4, 0, true);
|
addTextField(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_DELAY, 4, 0, true);
|
||||||
|
|
||||||
|
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
|
||||||
|
// The following items are grouped for Default Arguments
|
||||||
|
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_defaultArgumentsGroupTitle;
|
||||||
|
Group defaultArgumentsGroup = addGroupBox(contentAssistComposite, label, 2);
|
||||||
|
|
||||||
|
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_displayParametersWithDefaultArgument;
|
||||||
|
Button displayDefaultedParameters = addCheckBox(defaultArgumentsGroup, label,
|
||||||
|
ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT, 0);
|
||||||
|
|
||||||
|
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_displayDefaultArguments;
|
||||||
|
Button displayDefaultArguments = addCheckBox(defaultArgumentsGroup, label,
|
||||||
|
ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS, 0);
|
||||||
|
|
||||||
|
createDependency(displayDefaultedParameters,
|
||||||
|
ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT, displayDefaultArguments);
|
||||||
|
|
||||||
initializeFields();
|
initializeFields();
|
||||||
|
|
||||||
return contentAssistComposite;
|
return contentAssistComposite;
|
||||||
|
@ -171,6 +190,8 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
|
||||||
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON, true);
|
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON, true);
|
||||||
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, true);
|
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, true);
|
||||||
store.setDefault(ContentAssistPreference.AUTOACTIVATION_DELAY, 500);
|
store.setDefault(ContentAssistPreference.AUTOACTIVATION_DELAY, 500);
|
||||||
|
store.setDefault(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT, true);
|
||||||
|
store.setDefault(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS, true);
|
||||||
|
|
||||||
store.setDefault(ContentAssistPreference.AUTOINSERT, true);
|
store.setDefault(ContentAssistPreference.AUTOINSERT, true);
|
||||||
store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true);
|
store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* Kirk Beitz (Nokia)
|
* Kirk Beitz (Nokia)
|
||||||
* James Blackburn (Broadcom Corp.)
|
* James Blackburn (Broadcom Corp.)
|
||||||
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
||||||
|
* Thomas Corbat (IFS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.preferences;
|
package org.eclipse.cdt.internal.ui.preferences;
|
||||||
|
|
||||||
|
@ -49,6 +50,9 @@ public final class PreferencesMessages extends NLS {
|
||||||
public static String CEditorPreferencePage_ContentAssistPage_autoActivationEnableDoubleColon;
|
public static String CEditorPreferencePage_ContentAssistPage_autoActivationEnableDoubleColon;
|
||||||
public static String CEditorPreferencePage_ContentAssistPage_autoActivationEnableReplaceDotWithArrow;
|
public static String CEditorPreferencePage_ContentAssistPage_autoActivationEnableReplaceDotWithArrow;
|
||||||
public static String CEditorPreferencePage_ContentAssistPage_autoActivationDelay;
|
public static String CEditorPreferencePage_ContentAssistPage_autoActivationDelay;
|
||||||
|
public static String CEditorPreferencePage_ContentAssistPage_defaultArgumentsGroupTitle;
|
||||||
|
public static String CEditorPreferencePage_ContentAssistPage_displayParametersWithDefaultArgument;
|
||||||
|
public static String CEditorPreferencePage_ContentAssistPage_displayDefaultArguments;
|
||||||
public static String CEditorPreferencePage_ContentAssistPage_proposalFilterSelect;
|
public static String CEditorPreferencePage_ContentAssistPage_proposalFilterSelect;
|
||||||
public static String CEditorPreferencePage_ContentAssistPage_completionProposalBackgroundColor;
|
public static String CEditorPreferencePage_ContentAssistPage_completionProposalBackgroundColor;
|
||||||
public static String CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor;
|
public static String CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor;
|
||||||
|
|
|
@ -45,6 +45,9 @@ CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutToolTip=If a pr
|
||||||
CEditorPreferencePage_ContentAssistPage_parameterBackgroundColor=Parameter hint background
|
CEditorPreferencePage_ContentAssistPage_parameterBackgroundColor=Parameter hint background
|
||||||
CEditorPreferencePage_ContentAssistPage_parameterForegroundColor=Parameter hint foreground
|
CEditorPreferencePage_ContentAssistPage_parameterForegroundColor=Parameter hint foreground
|
||||||
CEditorPreferencePage_ContentAssistPage_sortingSection_title=Sorting and Filtering
|
CEditorPreferencePage_ContentAssistPage_sortingSection_title=Sorting and Filtering
|
||||||
|
CEditorPreferencePage_ContentAssistPage_defaultArgumentsGroupTitle=Default Arguments
|
||||||
|
CEditorPreferencePage_ContentAssistPage_displayParametersWithDefaultArgument=Display parameters with default argument
|
||||||
|
CEditorPreferencePage_ContentAssistPage_displayDefaultArguments=Display default arguments
|
||||||
CEditorPreferencePage_sourceHoverBackgroundColor=Source hover background
|
CEditorPreferencePage_sourceHoverBackgroundColor=Source hover background
|
||||||
|
|
||||||
# {0} will be replaced by the keyboard shortcut for the command (e.g. "Ctrl+Space", or "no shortcut")
|
# {0} will be replaced by the keyboard shortcut for the command (e.g. "Ctrl+Space", or "no shortcut")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2011 IBM Corporation and others.
|
* Copyright (c) 2000, 2014 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
* Kirk Beitz (Nokia)
|
* Kirk Beitz (Nokia)
|
||||||
|
* Thomas Corbat (IFS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||||
|
|
||||||
|
@ -60,6 +61,10 @@ public class ContentAssistPreference {
|
||||||
public final static String AUTOACTIVATION_TRIGGERS_ARROW= "content_assist_autoactivation_trigger_arrow"; //$NON-NLS-1$
|
public final static String AUTOACTIVATION_TRIGGERS_ARROW= "content_assist_autoactivation_trigger_arrow"; //$NON-NLS-1$
|
||||||
public final static String AUTOACTIVATION_TRIGGERS_DOUBLECOLON= "content_assist_autoactivation_trigger_doublecolon"; //$NON-NLS-1$
|
public final static String AUTOACTIVATION_TRIGGERS_DOUBLECOLON= "content_assist_autoactivation_trigger_doublecolon"; //$NON-NLS-1$
|
||||||
public final static String AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW= "content_assist_autoactivation_trigger_replace_dot_with_arrow"; //$NON-NLS-1$
|
public final static String AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW= "content_assist_autoactivation_trigger_replace_dot_with_arrow"; //$NON-NLS-1$
|
||||||
|
/** Preference key for display of defaulted parameters in content assist */
|
||||||
|
public final static String DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT = "content_assist_default_argument_display_parameters_with_default_argument"; //$NON-NLS-1$
|
||||||
|
/** Preference key for display of default arguments in content assist */
|
||||||
|
public final static String DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS = "content_assist_default_argument_display_arguments"; //$NON-NLS-1$
|
||||||
// /** Preference key for visibility of proposals (unused) */
|
// /** Preference key for visibility of proposals (unused) */
|
||||||
// public final static String SHOW_DOCUMENTED_PROPOSALS= "content_assist_show_visible_proposals"; //$NON-NLS-1$
|
// public final static String SHOW_DOCUMENTED_PROPOSALS= "content_assist_show_visible_proposals"; //$NON-NLS-1$
|
||||||
/** Preference key for alphabetic ordering of proposals */
|
/** Preference key for alphabetic ordering of proposals */
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
@ -67,6 +68,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||||
|
@ -99,6 +102,8 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||||
* @author Bryan Wilkinson
|
* @author Bryan Wilkinson
|
||||||
*/
|
*/
|
||||||
public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer {
|
public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer {
|
||||||
|
private static final String HASH = "#"; //$NON-NLS-1$;
|
||||||
|
private static final String DEFAULT_ARGUMENT_PATTERN = " = {0}"; //$NON-NLS-1$;
|
||||||
private static final String TEMPLATE_PARAMETER_PATTERN = "template<{0}> class"; //$NON-NLS-1$;
|
private static final String TEMPLATE_PARAMETER_PATTERN = "template<{0}> class"; //$NON-NLS-1$;
|
||||||
private static final String TYPENAME = "typename"; //$NON-NLS-1$;
|
private static final String TYPENAME = "typename"; //$NON-NLS-1$;
|
||||||
private static final String ELLIPSIS = "..."; //$NON-NLS-1$;
|
private static final String ELLIPSIS = "..."; //$NON-NLS-1$;
|
||||||
|
@ -387,8 +392,14 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
StringBuilder representation = new StringBuilder();
|
StringBuilder representation = new StringBuilder();
|
||||||
|
|
||||||
final String parameterDelimiter = context.getTemplateParameterDelimiter();
|
final String parameterDelimiter = context.getTemplateParameterDelimiter();
|
||||||
|
final boolean addDefaultedParameters = isDisplayDefaultedParameters();
|
||||||
|
final boolean addDefaultArguments = isDisplayDefaultArguments();
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
ICPPTemplateParameter parameter = parameters[i];
|
ICPPTemplateParameter parameter = parameters[i];
|
||||||
|
ICPPTemplateArgument defaultValue = parameter.getDefaultValue();
|
||||||
|
if (!addDefaultedParameters && defaultValue != null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
representation.append(parameterDelimiter);
|
representation.append(parameterDelimiter);
|
||||||
}
|
}
|
||||||
|
@ -408,6 +419,15 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
representation.append(' ');
|
representation.append(' ');
|
||||||
representation.append(parameter.getName());
|
representation.append(parameter.getName());
|
||||||
|
if (addDefaultArguments && defaultValue != null) {
|
||||||
|
String defaultArgumentRepresentation = MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, defaultValue);
|
||||||
|
for (int parameterIndex = 0; parameterIndex < i; parameterIndex++) {
|
||||||
|
String templateArgumentID = HASH + parameterIndex;
|
||||||
|
String templateArgumentValue = parameters[parameterIndex].getName();
|
||||||
|
defaultArgumentRepresentation = defaultArgumentRepresentation.replaceAll(templateArgumentID, templateArgumentValue);
|
||||||
|
}
|
||||||
|
representation.append(defaultArgumentRepresentation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return representation.toString();
|
return representation.toString();
|
||||||
}
|
}
|
||||||
|
@ -474,6 +494,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
final String parameterDelimiter = context.getFunctionParameterDelimiter();
|
final String parameterDelimiter = context.getFunctionParameterDelimiter();
|
||||||
for (int i = 0; i < params.length; ++i) {
|
for (int i = 0; i < params.length; ++i) {
|
||||||
IParameter param = params[i];
|
IParameter param = params[i];
|
||||||
|
if (skipDefaultedParameter(param)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
IType paramType = param.getType();
|
IType paramType = param.getType();
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
dispargs.append(parameterDelimiter);
|
dispargs.append(parameterDelimiter);
|
||||||
|
@ -487,6 +510,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
dispargs.append(' ');
|
dispargs.append(' ');
|
||||||
dispargs.append(paramName);
|
dispargs.append(paramName);
|
||||||
}
|
}
|
||||||
|
if (param instanceof ICPPParameter) {
|
||||||
|
ICPPParameter cppParam = (ICPPParameter) param;
|
||||||
|
if (cppParam.hasDefaultValue() && isDisplayDefaultArguments()) {
|
||||||
|
dispargs.append(MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, cppParam.getDefaultValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function.takesVarArgs()) {
|
if (function.takesVarArgs()) {
|
||||||
|
@ -561,6 +590,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
proposals.add(proposal);
|
proposals.add(proposal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean skipDefaultedParameter(IParameter param) {
|
||||||
|
return !isDisplayDefaultedParameters() && param instanceof ICPPParameter && ((ICPPParameter)param).hasDefaultValue();
|
||||||
|
}
|
||||||
|
|
||||||
private void handleVariable(IVariable variable, CContentAssistInvocationContext context,
|
private void handleVariable(IVariable variable, CContentAssistInvocationContext context,
|
||||||
int baseRelevance, List<ICompletionProposal> proposals) {
|
int baseRelevance, List<ICompletionProposal> proposals) {
|
||||||
if (context.isContextInformationStyle()) {
|
if (context.isContextInformationStyle()) {
|
||||||
|
@ -755,4 +788,18 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
return imageDescriptor != null ?
|
return imageDescriptor != null ?
|
||||||
CUIPlugin.getImageDescriptorRegistry().get(imageDescriptor) : null;
|
CUIPlugin.getImageDescriptorRegistry().get(imageDescriptor) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isDisplayDefaultArguments() {
|
||||||
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
|
return preferenceStore.getBoolean(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDisplayDefaultedParameters() {
|
||||||
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
|
return preferenceStore.getBoolean(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IPreferenceStore getPreferenceStore() {
|
||||||
|
return CUIPlugin.getDefault().getPreferenceStore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue