Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Corbat2014-07-29 09:17:10 +0000
committerThomas Corbat2014-08-14 06:55:59 +0000
commitac8965a9049388bfd2f118d619897f512c3aa363 (patch)
tree543974b36bbbdd0b264141d5c010cf14415189c1
parent742c1d9ee8b966d6aed68246b24279a314c55ebd (diff)
downloadorg.eclipse.cdt-ac8965a9049388bfd2f118d619897f512c3aa363.tar.gz
org.eclipse.cdt-ac8965a9049388bfd2f118d619897f512c3aa363.tar.xz
org.eclipse.cdt-ac8965a9049388bfd2f118d619897f512c3aa363.zip
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
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java94
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeAssistPreferencePage.java25
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistPreference.java7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java47
6 files changed, 177 insertions, 3 deletions
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 2d0ab6c3062..ffd6cd8f83b 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
@@ -26,11 +26,15 @@ 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.ui.CUIPlugin;
+
+import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
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);
}
+ 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*/
public void testLocalVariable() throws Exception {
final String[] expected= {
@@ -1415,4 +1433,80 @@ public class CompletionTests extends AbstractContentAssistTest {
final String[] expectedID = { "C1", "C2", "C3" };
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);
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeAssistPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeAssistPreferencePage.java
index 3dbef4bcb72..0da996569f7 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeAssistPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeAssistPreferencePage.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
* IBM Corporation
* Kirk Beitz (Nokia)
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
+ * Thomas Corbat
*******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
@@ -20,13 +21,13 @@ import java.util.ArrayList;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
-
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
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_DOUBLECOLON));
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.ORDER_PROPOSALS));
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;
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();
return contentAssistComposite;
@@ -171,6 +190,8 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON, true);
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, true);
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.PREFIX_COMPLETION, true);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
index a92de73695c..074be583b9b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
@@ -14,6 +14,7 @@
* Kirk Beitz (Nokia)
* James Blackburn (Broadcom Corp.)
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
+ * Thomas Corbat (IFS)
*******************************************************************************/
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_autoActivationEnableReplaceDotWithArrow;
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_completionProposalBackgroundColor;
public static String CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
index 1d3c15bcaa7..c3f4874407c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
@@ -45,6 +45,9 @@ CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutToolTip=If a pr
CEditorPreferencePage_ContentAssistPage_parameterBackgroundColor=Parameter hint background
CEditorPreferencePage_ContentAssistPage_parameterForegroundColor=Parameter hint foreground
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
# {0} will be replaced by the keyboard shortcut for the command (e.g. "Ctrl+Space", or "no shortcut")
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistPreference.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistPreference.java
index bac11da36eb..257486d8ae6 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistPreference.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistPreference.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
* Kirk Beitz (Nokia)
+ * Thomas Corbat (IFS)
*******************************************************************************/
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_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$
+ /** 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) */
// public final static String SHOW_DOCUMENTED_PROPOSALS= "content_assist_show_visible_proposals"; //$NON-NLS-1$
/** Preference key for alphabetic ordering of proposals */
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java
index d336de28ecd..5c7323936f6 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java
@@ -20,6 +20,7 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.BadLocationException;
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.ICPPMethod;
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.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
@@ -99,6 +102,8 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
* @author Bryan Wilkinson
*/
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 TYPENAME = "typename"; //$NON-NLS-1$;
private static final String ELLIPSIS = "..."; //$NON-NLS-1$;
@@ -387,8 +392,14 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
StringBuilder representation = new StringBuilder();
final String parameterDelimiter = context.getTemplateParameterDelimiter();
+ final boolean addDefaultedParameters = isDisplayDefaultedParameters();
+ final boolean addDefaultArguments = isDisplayDefaultArguments();
for (int i = 0; i < parameters.length; i++) {
ICPPTemplateParameter parameter = parameters[i];
+ ICPPTemplateArgument defaultValue = parameter.getDefaultValue();
+ if (!addDefaultedParameters && defaultValue != null) {
+ break;
+ }
if (i > 0) {
representation.append(parameterDelimiter);
}
@@ -408,6 +419,15 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
}
representation.append(' ');
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();
}
@@ -474,6 +494,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
final String parameterDelimiter = context.getFunctionParameterDelimiter();
for (int i = 0; i < params.length; ++i) {
IParameter param = params[i];
+ if (skipDefaultedParameter(param)) {
+ break;
+ }
IType paramType = param.getType();
if (i > 0) {
dispargs.append(parameterDelimiter);
@@ -487,6 +510,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
dispargs.append(' ');
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()) {
@@ -561,6 +590,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
proposals.add(proposal);
}
+ private boolean skipDefaultedParameter(IParameter param) {
+ return !isDisplayDefaultedParameters() && param instanceof ICPPParameter && ((ICPPParameter)param).hasDefaultValue();
+ }
+
private void handleVariable(IVariable variable, CContentAssistInvocationContext context,
int baseRelevance, List<ICompletionProposal> proposals) {
if (context.isContextInformationStyle()) {
@@ -755,4 +788,18 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
return 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();
+ }
}

Back to the top