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 4462b8db3c1..b0905b25928 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 @@ -12,6 +12,7 @@ * Kirk Beitz (Nokia) * Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion) * Thomas Corbat + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.preferences; @@ -48,6 +49,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage { overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, ContentAssistPreference.AUTOACTIVATION_DELAY)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.AUTOINSERT)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.PREFIX_COMPLETION)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.GUESS_ARGUMENTS)); // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, ContentAssistPreference.TIMEOUT_DELAY)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW)); @@ -106,6 +108,9 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage { label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically; addCheckBox(insertionGroup, label, ContentAssistPreference.PREFIX_COMPLETION, 0); + label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_guessArguments; + addCheckBox(insertionGroup, label, ContentAssistPreference.GUESS_ARGUMENTS, 0); + //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // sorting and filtering label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_sortingSection_title; @@ -138,7 +143,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage { addCheckBox(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, 0); label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_autoActivationDelay; - addTextField(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_DELAY, 4, 0, true); + addTextField(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_DELAY, 4, 4, true); //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // The following items are grouped for Default Arguments @@ -181,6 +186,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage { store.setDefault(ContentAssistPreference.AUTOINSERT, true); store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true); + store.setDefault(ContentAssistPreference.GUESS_ARGUMENTS, true); store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false); store.setDefault(ContentAssistPreference.PROPOSALS_FILTER, ProposalFilterPreferencesUtil.getProposalFilternamesAsString()); 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 1664bbd466e..2e62339b8bc 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 @@ -42,6 +42,7 @@ public final class PreferencesMessages extends NLS { public static String CEditorPreferencePage_ContentAssistPage_insertionGroupTitle; public static String CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically; public static String CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically; + public static String CEditorPreferencePage_ContentAssistPage_guessArguments; public static String CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder; public static String CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches; public static String CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle; 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 a9209d344c3..5ca24098dfa 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 @@ -26,8 +26,9 @@ CEditorPreferencePage_colors=Synta&x #CEditorPreferencePage_ContentAssistPage_searchGroupCurrentFileOption=S&earch current file and included files #CEditorPreferencePage_ContentAssistPage_searchGroupCurrentProjectOption=Search current &project CEditorPreferencePage_ContentAssistPage_insertionGroupTitle=Insertion -CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically=&Insert single proposals automatically +CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically=&Insert a single proposal automatically CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically=I&nsert common prefixes automatically +CEditorPreferencePage_ContentAssistPage_guessArguments=&Fill function arguments and show guessed arguments CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present proposals in a&lphabetical order CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches=Show ca&mel case matches CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle=Auto-Activation 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 4cc511ff35f..a94a919707a 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 @@ -4,12 +4,13 @@ * 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 - * + * * Contributors: * IBM - Initial API and implementation * Anton Leherbauer (Wind River Systems) * Kirk Beitz (Nokia) * Thomas Corbat (IFS) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.contentassist; @@ -78,7 +79,7 @@ public class ContentAssistPreference { public final static String PROJECT_SEARCH_SCOPE= "content_assist_project_search_scope"; //$NON-NLS-1$ /** Preference key for completion filtering */ public final static String PROPOSALS_FILTER= "content_assist_proposal_filter"; //$NON-NLS-1$ - + /** Key for boolean preference telling whether camel case/underscore matches are to be shown by content assist features or not*/ public static final String SHOW_CAMEL_CASE_MATCHES = "contentAssist.showCamelCaseMatches"; //$NON-NLS-1$ @@ -86,19 +87,19 @@ public class ContentAssistPreference { RGB rgb= PreferenceConverter.getColor(store, key); return manager.getColor(rgb); } - + private static Color getColor(IPreferenceStore store, String key) { CTextTools textTools= CUIPlugin.getDefault().getTextTools(); return getColor(store, key, textTools.getColorManager()); } - + private static CContentAssistProcessor getCProcessor(ContentAssistant assistant) { IContentAssistProcessor p= assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE); if (p instanceof CContentAssistProcessor) return (CContentAssistProcessor) p; return null; } - + private static void configureCProcessor(ContentAssistant assistant, IPreferenceStore store) { CContentAssistProcessor ccp= getCProcessor(assistant); if (ccp == null) @@ -111,10 +112,10 @@ public class ContentAssistPreference { // // enabled= store.getBoolean(CASE_SENSITIVITY); // ccp.restrictProposalsToMatchingCases(enabled); - + // enabled= store.getBoolean(ORDER_PROPOSALS); // ccp.orderProposalsAlphabetically(enabled); - + // enabled= store.getBoolean(ADD_INCLUDE); // ccp.allowAddingIncludes(enabled); } @@ -148,14 +149,14 @@ public class ContentAssistPreference { triggers = "."; //$NON-NLS-1$ ccp.setReplacementAutoActivationCharacters(triggers); } - + /** * Configure the given content assistant from the given store. */ public static void configure(ContentAssistant assistant, IPreferenceStore store) { CTextTools textTools= CUIPlugin.getDefault().getTextTools(); IColorManager manager= textTools.getColorManager(); - + boolean enabledDot= store.getBoolean(AUTOACTIVATION_TRIGGERS_DOT); boolean enabledArrow= store.getBoolean(AUTOACTIVATION_TRIGGERS_ARROW); boolean enabledDoubleColon= store.getBoolean(AUTOACTIVATION_TRIGGERS_DOUBLECOLON); @@ -163,24 +164,24 @@ public class ContentAssistPreference { boolean enabled = (enabledDot || enabledArrow || enabledDoubleColon || enabledReplaceDotWithArrow); assistant.enableAutoActivation(enabled); - + int delay= store.getInt(AUTOACTIVATION_DELAY); assistant.setAutoActivationDelay(delay); - + Color c1= getColor(store, PROPOSALS_FOREGROUND, manager); assistant.setProposalSelectorForeground(c1); - + Color c2= getColor(store, PROPOSALS_BACKGROUND, manager); assistant.setProposalSelectorBackground(c2); - + Color c3= getColor(store, PARAMETERS_FOREGROUND, manager); assistant.setContextInformationPopupForeground(c3); assistant.setContextSelectorForeground(c3); - + Color c4= getColor(store, PARAMETERS_BACKGROUND, manager); assistant.setContextInformationPopupBackground(c4); assistant.setContextSelectorBackground(c4); - + enabled= store.getBoolean(AUTOINSERT); assistant.enableAutoInsert(enabled); @@ -189,15 +190,15 @@ public class ContentAssistPreference { configureCProcessor(assistant, store); } - + private static void changeCProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { CContentAssistProcessor ccp= getCProcessor(assistant); if (ccp == null) return; - + if ((AUTOACTIVATION_TRIGGERS_DOT.equals(key)) || (AUTOACTIVATION_TRIGGERS_ARROW.equals(key)) - || (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(key)) + || (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(key)) || (AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW.equals(key))){ configureActivationCharacters(store, ccp); } @@ -217,14 +218,14 @@ public class ContentAssistPreference { // ccp.allowAddingIncludes(enabled); // } } - + /** * Changes the configuration of the given content assistant according to the given property * change event and the given preference store. */ public static void changeConfiguration(ContentAssistant assistant, IPreferenceStore store, PropertyChangeEvent event) { String p= event.getProperty(); - + if ((AUTOACTIVATION_TRIGGERS_DOT.equals(p)) || (AUTOACTIVATION_TRIGGERS_ARROW.equals(p)) || (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(p)) @@ -259,12 +260,12 @@ public class ContentAssistPreference { boolean enabled= store.getBoolean(PREFIX_COMPLETION); assistant.enablePrefixCompletion(enabled); } - + changeCProcessor(assistant, store, p); } - + private static ContentAssistPreference instance = null; - + private final IPropertyChangeListener propertyListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { @@ -274,33 +275,33 @@ public class ContentAssistPreference { } } }; - + private ContentAssistPreference() { getPreferences().addPropertyChangeListener(propertyListener); updateOnPreferences(); } - + public static synchronized ContentAssistPreference getInstance() { if (instance == null) { instance = new ContentAssistPreference(); } - + return instance; } - + private static IPreferenceStore getPreferences() { return CUIPlugin.getDefault().getPreferenceStore(); } - + private synchronized void updateOnPreferences() { boolean showCamelCaseMatches = getPreferences().getBoolean(ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES); ContentAssistMatcherFactory.getInstance().setShowCamelCaseMatches(showCamelCaseMatches); } - + private void shutdownInternal() { getPreferences().removePropertyChangeListener(propertyListener); } - + public static synchronized void shutdown() { if (instance != null) { instance.shutdownInternal(); 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 404ed340e09..2936d79b89f 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 @@ -124,21 +124,22 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer 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$; - private String fPrefix; + private String fPrefix = ""; //$NON-NLS-1$ + private boolean fGuessArguments; private List fAvailableElements; /** * Default constructor is required (executable extension). */ public DOMCompletionProposalComputer() { - fPrefix = ""; //$NON-NLS-1$ } @Override protected List computeCompletionProposals(CContentAssistInvocationContext context, IASTCompletionNode completionNode, String prefix) { fPrefix = prefix; - initializeDefinedElements(context); + fGuessArguments = getPreferenceStore().getBoolean(ContentAssistPreference.GUESS_ARGUMENTS); + fAvailableElements = fGuessArguments ? getDefinedElements(context) : Collections.emptyList(); List proposals = new ArrayList<>(); if (inPreprocessorDirective(context)) { @@ -622,7 +623,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (function.getParameters() != null && function.getParameters().length != 0 && isBeforeParameters(context)) { proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal, - function, fPrefix)); + function, fPrefix, fGuessArguments)); } else { proposals.add(proposal); } @@ -659,9 +660,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer /** * Initializes the list of variables accessible at the start of the current statement. */ - private void initializeDefinedElements(CContentAssistInvocationContext context) { - fAvailableElements = Collections.emptyList(); - + private List getDefinedElements(CContentAssistInvocationContext context) { // Get all variables accessible at the start of the statement. // ex1: int a = foo( // ^ --> We don't want 'a' as a suggestion. @@ -672,7 +671,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer // ^ --> If this offset is used, the only defined name will be "bar(char*)". IASTCompletionNode node = context.getCompletionNode(); if (node == null) - return; + return Collections.emptyList(); // Find the enclosing statement at the point of completion. IASTStatement completionStatement = null; @@ -687,8 +686,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } } if (completionStatement == null) - return; - + return Collections.emptyList(); // Get content assist results for an empty prefix at the start of the statement. final int statementOffset = getNodeOffset(completionStatement); @@ -701,7 +699,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer IBinding[] bindings = findBindingsForContextAssist(name, ast); if (bindings.length == 0) - return; + return Collections.emptyList(); // Get all variables declared in the translation unit. final Set declaredVariables = new HashSet<>(); @@ -732,7 +730,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer elementsMap.put(binding.getName(), binding); } } - fAvailableElements = new ArrayList<>(elementsMap.values()); + return new ArrayList<>(elementsMap.values()); } private IBinding[] findBindingsForContextAssist(IASTName name, IASTTranslationUnit ast) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java index 0de68014854..b860195ce62 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java @@ -9,6 +9,7 @@ * Andrew McCullough - initial API and implementation * IBM Corporation - general improvement and bug fixes, partial reimplementation * Mohamed Azab (Mentor Graphics) - Bug 438549. Add mechanism for parameter guessing. + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.contentassist; @@ -44,6 +45,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CUIPlugin; @@ -66,10 +68,11 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { private char[][] fParametersNames; private IType[] fParametersTypes; private List fAssignableElements; + private final boolean fGuessArguments; public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context, List availableElements, CCompletionProposal proposal, IFunction function, - String prefix) { + String prefix, boolean guessArguments) { String replacement = getParametersList(function); String fullPrefix = function.getName() + "("; //$NON-NLS-1$ int replacementOffset = proposal.getReplacementOffset(); @@ -106,7 +109,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { ParameterGuessingProposal ret = new ParameterGuessingProposal(replacement, replacementOffset, replacementLength, proposal.getImage(), proposal.getDisplayString(), proposal.getIdString(), proposal.getRelevance(), context.getViewer(), function, invocationOffset, parseOffset, - context.getTranslationUnit(), document); + context.getTranslationUnit(), document, guessArguments); ret.setContextInformation(proposal.getContextInformation()); ret.fFullPrefix = fullPrefix; ret.fCEditor = getCEditor(context.getEditor()); @@ -135,9 +138,10 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, String idString, int relevance, ITextViewer viewer, IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu, - IDocument document) { + IDocument document, boolean guessArguments) { super(replacementString, replacementOffset, replacementLength, image, displayString, idString, relevance, viewer, function, invocationOffset, parseOffset, tu, document); + this.fGuessArguments = guessArguments; } /** @@ -165,12 +169,14 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { // Initialize necessary fields. fParametersNames = getFunctionParametersNames(fFunctionParameters); fParametersTypes = getFunctionParametersTypes(fFunctionParameters); - - try { - guessParameters(); - } catch (Exception e) { - CUIPlugin.log(e); - return; + + if (fGuessArguments) { + try { + guessParameters(); + } catch (Exception e) { + CUIPlugin.log(e); + return; + } } int baseOffset = getReplacementOffset(); @@ -250,7 +256,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); } - private void guessParameters() throws Exception { + private void guessParameters() throws CModelException { int count = fParametersNames.length; fPositions = new Position[count]; fChoices = new ICompletionProposal[count][]; @@ -269,11 +275,11 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { fPositions[i] = position; fChoices[i] = argumentProposals; } - updateProposalsPossitions(); + updateProposalsPositions(); } - private void updateProposalsPossitions() throws Exception { - StringBuffer buffer = new StringBuffer(); + private void updateProposalsPositions() { + StringBuilder buffer = new StringBuilder(); buffer.append(fFullPrefix); setCursorPosition(buffer.length());