Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 59656 Details for
Bug 175283
[Content Assist] Invalid keyword completion
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed patch
patch175283v1.txt (text/plain), 27.08 KB, created by
Bryan Wilkinson
on 2007-02-23 09:44:48 EST
(
hide
)
Description:
proposed patch
Filename:
MIME Type:
Creator:
Bryan Wilkinson
Created:
2007-02-23 09:44:48 EST
Size:
27.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.cdt.ui >Index: src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java >=================================================================== >RCS file: src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java >diff -N src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java >--- src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java 31 Jan 2007 13:09:21 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,207 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 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 >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM - Initial API and implementation >- * Anton Leherbauer (Wind River Systems) >- *******************************************************************************/ >-package org.eclipse.cdt.internal.ui.text.contentassist; >- >-import java.util.List; >- >-import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; >-import org.eclipse.cdt.core.dom.ast.IASTFieldReference; >-import org.eclipse.cdt.core.dom.ast.IASTName; >-import org.eclipse.cdt.core.model.IWorkingCopy; >-import org.eclipse.cdt.core.parser.Directives; >-import org.eclipse.cdt.core.parser.Keywords; >-import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; >-import org.eclipse.cdt.ui.CUIPlugin; >-import org.eclipse.cdt.ui.text.ICPartitions; >-import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor; >-import org.eclipse.jface.resource.ImageDescriptor; >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextViewer; >-import org.eclipse.jface.text.TextUtilities; >-import org.eclipse.swt.graphics.Image; >- >-public class KeywordCompletionContributor implements ICompletionContributor { >- >- public void contributeCompletionProposals(ITextViewer viewer, int offset, >- IWorkingCopy workingCopy, ASTCompletionNode completionNode, >- String prefix, List proposals) { >- >- // No prefix, no completions >- if (prefix.length() == 0) >- return; >- >- String[] keywords; >- if(inPreprocessorDirective(viewer.getDocument(), offset)) { >- keywords= preprocessorKeywords; >- } else { >- if (!validContext(completionNode)) >- return; >- >- keywords = cppkeywords; // default to C++ >- if (workingCopy != null && workingCopy.isCLanguage()) >- keywords = ckeywords; >- >- } >- // add matching keyword proposals >- ImageDescriptor imagedesc = CElementImageProvider.getKeywordImageDescriptor(); >- Image image = imagedesc != null ? CUIPlugin.getImageDescriptorRegistry().get(imagedesc) : null; >- for (int i = 0; i < keywords.length; ++i) { >- if (keywords[i].startsWith(prefix)) { >- int repLength = prefix.length(); >- int repOffset = offset - repLength; >- proposals.add(new CCompletionProposal(keywords[i], repOffset, repLength, image, keywords[i], 1, viewer)); >- } >- } >- } >- >- // TODO This is copied from the search completion contributor >- // We should make this common >- private boolean validContext(ASTCompletionNode completionNode) { >- if (completionNode == null) >- // No completion node, assume true >- return true; >- >- boolean valid = true; >- IASTName[] names = completionNode.getNames(); >- for (int i = 0; i < names.length; i++) { >- IASTName name = names[i]; >- >- // not hooked up, not a valid name, ignore >- if (name.getTranslationUnit() == null) >- continue; >- >- // member access currently isn't valid >- if (name.getParent() instanceof IASTFieldReference) { >- valid = false; >- continue; >- } >- >- // found one that was valid >- return true; >- } >- >- // Couldn't find a valid context >- return valid; >- } >- >- /** >- * Check if given offset is inside a preprocessor directive. >- * >- * @param doc the document >- * @param offset the offset to check >- * @return <code>true</code> if offset is inside a preprocessor directive >- */ >- private boolean inPreprocessorDirective(IDocument doc, int offset) { >- if (offset > 0 && offset == doc.getLength()) { >- --offset; >- } >- try { >- return ICPartitions.C_PREPROCESSOR >- .equals(TextUtilities.getContentType(doc, ICPartitions.C_PARTITIONING, offset, false)); >- } catch (BadLocationException exc) { >- } >- return false; >- } >- >- // These are the keywords we complete >- // We only do the ones that are >= 5 characters long >- private static String [] ckeywords = { >- Keywords.BREAK, >- Keywords.CONST, >- Keywords.CONTINUE, >- Keywords.DEFAULT, >- Keywords.DOUBLE, >- Keywords.EXTERN, >- Keywords.FLOAT, >- Keywords.INLINE, >- Keywords.REGISTER, >- Keywords.RESTRICT, >- Keywords.RETURN, >- Keywords.SHORT, >- Keywords.SIGNED, >- Keywords.SIZEOF, >- Keywords.STATIC, >- Keywords.STRUCT, >- Keywords.SWITCH, >- Keywords.TYPEDEF, >- Keywords.UNION, >- Keywords.UNSIGNED, >- Keywords.VOLATILE, >- Keywords.WHILE, >- Keywords._BOOL, >- Keywords._COMPLEX, >- Keywords._IMAGINARY >- }; >- >- private static String [] cppkeywords = { >- Keywords.BREAK, >- Keywords.CATCH, >- Keywords.CLASS, >- Keywords.CONST, >- Keywords.CONST_CAST, >- Keywords.CONTINUE, >- Keywords.DEFAULT, >- Keywords.DELETE, >- Keywords.DOUBLE, >- Keywords.DYNAMIC_CAST, >- Keywords.EXPLICIT, >- Keywords.EXPORT, >- Keywords.EXTERN, >- Keywords.FALSE, >- Keywords.FLOAT, >- Keywords.FRIEND, >- Keywords.INLINE, >- Keywords.MUTABLE, >- Keywords.NAMESPACE, >- Keywords.OPERATOR, >- Keywords.PRIVATE, >- Keywords.PROTECTED, >- Keywords.PUBLIC, >- Keywords.REGISTER, >- Keywords.REINTERPRET_CAST, >- Keywords.RETURN, >- Keywords.SHORT, >- Keywords.SIGNED, >- Keywords.SIZEOF, >- Keywords.STATIC, >- Keywords.STATIC_CAST, >- Keywords.STRUCT, >- Keywords.SWITCH, >- Keywords.TEMPLATE, >- Keywords.THROW, >- Keywords.TYPEDEF, >- Keywords.TYPEID, >- Keywords.TYPENAME, >- Keywords.UNION, >- Keywords.UNSIGNED, >- Keywords.USING, >- Keywords.VIRTUAL, >- Keywords.VOLATILE, >- Keywords.WCHAR_T, >- Keywords.WHILE >- }; >- >- private static String [] preprocessorKeywords = { >- Directives.POUND_DEFINE, >- Directives.POUND_ELIF, >- Directives.POUND_ELSE, >- Directives.POUND_ENDIF, >- Directives.POUND_ERROR, >- Directives.POUND_IF, >- Directives.POUND_IFDEF, >- Directives.POUND_IFNDEF, >- Directives.POUND_INCLUDE, >- Directives.POUND_PRAGMA, >- Directives.POUND_UNDEF, >- }; >-} >Index: src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java >=================================================================== >RCS file: src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java >diff -N src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java >--- src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java 5 Jul 2005 20:32:07 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,104 +0,0 @@ >-/********************************************************************** >- * Copyright (c) 2004, 2005 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 >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.cdt.internal.ui.text.contentassist; >- >-import java.util.List; >- >-import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; >-import org.eclipse.cdt.core.dom.ast.IASTFieldReference; >-import org.eclipse.cdt.core.dom.ast.IASTName; >-import org.eclipse.cdt.core.model.ITranslationUnit; >-import org.eclipse.cdt.core.model.IWorkingCopy; >-import org.eclipse.cdt.internal.ui.CHelpProviderManager; >-import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; >-import org.eclipse.cdt.ui.CUIPlugin; >-import org.eclipse.cdt.ui.IFunctionSummary; >-import org.eclipse.cdt.ui.text.ICHelpInvocationContext; >-import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.jface.text.ITextViewer; >-import org.eclipse.jface.text.contentassist.ContextInformation; >-import org.eclipse.swt.graphics.Image; >- >-public class HelpCompletionContributor implements ICompletionContributor { >- >- public void contributeCompletionProposals(ITextViewer viewer, int offset, >- IWorkingCopy workingCopy, ASTCompletionNode completionNode, String prefix, >- List proposals) >- { >- final IWorkingCopy fWorkingCopy = workingCopy; >- if (completionNode != null) { >- // Find matching functions >- ICHelpInvocationContext context = new ICHelpInvocationContext() { >- >- public IProject getProject() { >- return fWorkingCopy.getCProject().getProject(); >- } >- >- public ITranslationUnit getTranslationUnit() { >- return fWorkingCopy.getTranslationUnit(); >- } >- }; >- >- IASTName[] names = completionNode.getNames(); >- for (int i = 0; i < names.length; ++i) { >- IASTName name = names[i]; >- >- if (name.getTranslationUnit() == null) >- // Not connected >- continue; >- >- // ignore if this is a member access >- if (name.getParent() instanceof IASTFieldReference) >- continue; >- >- IFunctionSummary[] summaries = CHelpProviderManager.getDefault().getMatchingFunctions(context, prefix); >- if (summaries == null ) >- continue; >- >- int repOffset = offset - prefix.length(); >- int repLength = prefix.length(); >- Image image = CUIPlugin.getImageDescriptorRegistry().get(CElementImageProvider.getFunctionImageDescriptor()); >- >- for (int j = 0; j < summaries.length; j++) { >- IFunctionSummary summary = summaries[j]; >- String fname = summary.getName() + "()"; //$NON-NLS-1$ >- String fdesc = summary.getDescription(); >- IFunctionSummary.IFunctionPrototypeSummary fproto = summary.getPrototype(); >- String fargs = fproto.getArguments(); >- >- CCompletionProposal proposal; >- proposal = new CCompletionProposal(fname, >- repOffset, >- repLength, >- image, >- fproto.getPrototypeString(true), >- 2, >- viewer); >- >- if (fdesc != null) { >- proposal.setAdditionalProposalInfo(fdesc); >- } >- >- if (fargs != null && fargs.length() > 0) { >- proposal.setContextInformation(new ContextInformation(fname, fargs)); >- // set the cursor before the closing bracket >- proposal.setCursorPosition(fname.length() - 1); >- } >- >- proposals.add(proposal); >- } >- >- } >- } >- } >- >-} >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/plugin.xml,v >retrieving revision 1.236 >diff -u -r1.236 plugin.xml >--- plugin.xml 21 Feb 2007 13:03:58 -0000 1.236 >+++ plugin.xml 23 Feb 2007 14:32:49 -0000 >@@ -1582,21 +1582,6 @@ > name="%CDTIndexer.domsourceindexer"/> > > </extension> >- <extension >- point="org.eclipse.cdt.ui.completionContributors"> >- <contributor >- class="org.eclipse.cdt.internal.ui.text.contentassist.KeywordCompletionContributor" >- id="Keywords" >- priority="10"/> >- <contributor >- class="org.eclipse.cdt.internal.ui.text.contentassist.HelpCompletionContributor" >- id="Help" >- priority="99"/> >- <!--contributor >- class="org.eclipse.cdt.internal.ui.text.contentassist.PDOMCompletionContributor" >- id="PDOM" >- priority="3"/--> >- </extension> > > <extension > point="org.eclipse.cdt.ui.completionProposalComputer" >@@ -1651,6 +1636,31 @@ > <partition type="__c_preprocessor"/> > </completionProposalComputer> > </extension> >+ <extension >+ id="KeywordCompletionProposalComputer" >+ point="org.eclipse.cdt.ui.completionProposalComputer"> >+ <completionProposalComputer >+ categoryId="org.eclipse.cdt.ui.parserProposalCategory" >+ class="org.eclipse.cdt.internal.ui.text.contentassist.KeywordCompletionProposalComputer"> >+ <partition >+ type="__dftl_partition_content_type"> >+ </partition> >+ <partition >+ type="__c_preprocessor"> >+ </partition> >+ </completionProposalComputer> >+ </extension> >+ <extension >+ id="HelpCompletionProposalComputer" >+ point="org.eclipse.cdt.ui.completionProposalComputer"> >+ <completionProposalComputer >+ categoryId="org.eclipse.cdt.ui.parserProposalCategory" >+ class="org.eclipse.cdt.internal.ui.text.contentassist.HelpCompletionProposalComputer"> >+ <partition >+ type="__dftl_partition_content_type"> >+ </partition> >+ </completionProposalComputer> >+ </extension> > <!-- template proposals --> > <extension > point="org.eclipse.cdt.ui.completionProposalComputer" >Index: src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java >=================================================================== >RCS file: src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java >diff -N src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,236 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Bryan Wilkinson (QNX) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.cdt.internal.ui.text.contentassist; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.text.TextUtilities; >+import org.eclipse.swt.graphics.Image; >+ >+import org.eclipse.cdt.core.model.ITranslationUnit; >+import org.eclipse.cdt.core.parser.Directives; >+import org.eclipse.cdt.core.parser.Keywords; >+import org.eclipse.cdt.ui.CUIPlugin; >+import org.eclipse.cdt.ui.text.ICPartitions; >+import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext; >+import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer; >+ >+import org.eclipse.cdt.internal.ui.text.CHeuristicScanner; >+import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; >+ >+public class KeywordCompletionProposalComputer implements ICompletionProposalComputer { >+ >+ public List computeCompletionProposals( >+ ContentAssistInvocationContext context, IProgressMonitor monitor) { >+ >+ String prefix; >+ try { >+ prefix = getPrefix(context.getViewer(), context >+ .getInvocationOffset()); >+ } catch (BadLocationException e) { >+ return Collections.EMPTY_LIST; >+ } >+ >+ // No prefix, no completions >+ if (prefix.length() == 0) >+ return Collections.EMPTY_LIST; >+ >+ String[] keywords; >+ if(inPreprocessorDirective(context.getDocument(), context.getInvocationOffset())) { >+ keywords= preprocessorKeywords; >+ } else { >+ if (!isValidContext(context) >+ || !(context instanceof CContentAssistInvocationContext)) >+ return Collections.EMPTY_LIST; >+ >+ CContentAssistInvocationContext cContext = (CContentAssistInvocationContext) context; >+ ITranslationUnit tu = cContext.getTranslationUnit(); >+ >+ keywords = cppkeywords; // default to C++ >+ if (tu != null && tu.isCLanguage()) >+ keywords = ckeywords; >+ >+ } >+ >+ List proposals = new ArrayList(); >+ >+ // add matching keyword proposals >+ ImageDescriptor imagedesc = CElementImageProvider.getKeywordImageDescriptor(); >+ Image image = imagedesc != null ? CUIPlugin.getImageDescriptorRegistry().get(imagedesc) : null; >+ for (int i = 0; i < keywords.length; ++i) { >+ if (keywords[i].startsWith(prefix)) { >+ int repLength = prefix.length(); >+ int repOffset = context.getInvocationOffset() - repLength; >+ proposals.add(new CCompletionProposal(keywords[i], repOffset, >+ repLength, image, keywords[i], 1, context.getViewer())); >+ } >+ } >+ >+ return proposals; >+ } >+ >+ private String getPrefix(ITextViewer viewer, int offset) throws BadLocationException { >+ IDocument doc= viewer.getDocument(); >+ if (doc == null || offset > doc.getLength()) >+ return null; >+ >+ int length= 0; >+ while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset))) >+ length++; >+ >+ return doc.get(offset + 1, length); >+ } >+ >+ /** >+ * Checks whether the given invocation context looks valid for template completion. >+ * >+ * @param context the content assist invocation context >+ * @return <code>false</code> if the given invocation context looks like a field reference >+ */ >+ private boolean isValidContext(ContentAssistInvocationContext context) { >+ CHeuristicScanner scanner= new CHeuristicScanner(context.getDocument()); >+ int start= context.getInvocationOffset(); >+ return !scanner.looksLikeFieldReferenceBackward(start, Math.max(0, start-100)); >+ } >+ >+ /** >+ * Check if given offset is inside a preprocessor directive. >+ * >+ * @param doc the document >+ * @param offset the offset to check >+ * @return <code>true</code> if offset is inside a preprocessor directive >+ */ >+ private boolean inPreprocessorDirective(IDocument doc, int offset) { >+ if (offset > 0 && offset == doc.getLength()) { >+ --offset; >+ } >+ try { >+ return ICPartitions.C_PREPROCESSOR >+ .equals(TextUtilities.getContentType(doc, ICPartitions.C_PARTITIONING, offset, false)); >+ } catch (BadLocationException exc) { >+ } >+ return false; >+ } >+ >+ public List computeContextInformation( >+ ContentAssistInvocationContext context, IProgressMonitor monitor) { >+ return Collections.EMPTY_LIST; >+ } >+ >+ public String getErrorMessage() { >+ return null; >+ } >+ >+ public void sessionStarted() { >+ } >+ >+ public void sessionEnded() { >+ } >+ >+ // These are the keywords we complete >+ // We only do the ones that are >= 5 characters long >+ private static String [] ckeywords = { >+ Keywords.BREAK, >+ Keywords.CONST, >+ Keywords.CONTINUE, >+ Keywords.DEFAULT, >+ Keywords.DOUBLE, >+ Keywords.EXTERN, >+ Keywords.FLOAT, >+ Keywords.INLINE, >+ Keywords.REGISTER, >+ Keywords.RESTRICT, >+ Keywords.RETURN, >+ Keywords.SHORT, >+ Keywords.SIGNED, >+ Keywords.SIZEOF, >+ Keywords.STATIC, >+ Keywords.STRUCT, >+ Keywords.SWITCH, >+ Keywords.TYPEDEF, >+ Keywords.UNION, >+ Keywords.UNSIGNED, >+ Keywords.VOLATILE, >+ Keywords.WHILE, >+ Keywords._BOOL, >+ Keywords._COMPLEX, >+ Keywords._IMAGINARY >+ }; >+ >+ private static String [] cppkeywords = { >+ Keywords.BREAK, >+ Keywords.CATCH, >+ Keywords.CLASS, >+ Keywords.CONST, >+ Keywords.CONST_CAST, >+ Keywords.CONTINUE, >+ Keywords.DEFAULT, >+ Keywords.DELETE, >+ Keywords.DOUBLE, >+ Keywords.DYNAMIC_CAST, >+ Keywords.EXPLICIT, >+ Keywords.EXPORT, >+ Keywords.EXTERN, >+ Keywords.FALSE, >+ Keywords.FLOAT, >+ Keywords.FRIEND, >+ Keywords.INLINE, >+ Keywords.MUTABLE, >+ Keywords.NAMESPACE, >+ Keywords.OPERATOR, >+ Keywords.PRIVATE, >+ Keywords.PROTECTED, >+ Keywords.PUBLIC, >+ Keywords.REGISTER, >+ Keywords.REINTERPRET_CAST, >+ Keywords.RETURN, >+ Keywords.SHORT, >+ Keywords.SIGNED, >+ Keywords.SIZEOF, >+ Keywords.STATIC, >+ Keywords.STATIC_CAST, >+ Keywords.STRUCT, >+ Keywords.SWITCH, >+ Keywords.TEMPLATE, >+ Keywords.THROW, >+ Keywords.TYPEDEF, >+ Keywords.TYPEID, >+ Keywords.TYPENAME, >+ Keywords.UNION, >+ Keywords.UNSIGNED, >+ Keywords.USING, >+ Keywords.VIRTUAL, >+ Keywords.VOLATILE, >+ Keywords.WCHAR_T, >+ Keywords.WHILE >+ }; >+ >+ private static String [] preprocessorKeywords = { >+ Directives.POUND_DEFINE, >+ Directives.POUND_ELIF, >+ Directives.POUND_ELSE, >+ Directives.POUND_ENDIF, >+ Directives.POUND_ERROR, >+ Directives.POUND_IF, >+ Directives.POUND_IFDEF, >+ Directives.POUND_IFNDEF, >+ Directives.POUND_INCLUDE, >+ Directives.POUND_PRAGMA, >+ Directives.POUND_UNDEF, >+ }; >+} >Index: src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java >=================================================================== >RCS file: src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java >diff -N src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,126 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Bryan Wilkinson (QNX) - Initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.cdt.internal.ui.text.contentassist; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.swt.graphics.Image; >+ >+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; >+import org.eclipse.cdt.core.dom.ast.IASTFieldReference; >+import org.eclipse.cdt.core.dom.ast.IASTName; >+import org.eclipse.cdt.core.model.ITranslationUnit; >+import org.eclipse.cdt.ui.CUIPlugin; >+import org.eclipse.cdt.ui.IFunctionSummary; >+import org.eclipse.cdt.ui.text.ICHelpInvocationContext; >+ >+import org.eclipse.cdt.internal.ui.CHelpProviderManager; >+import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; >+ >+public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer { >+ >+ protected List computeCompletionProposals( >+ CContentAssistInvocationContext cContext, >+ ASTCompletionNode completionNode, String prefix) >+ throws CoreException { >+ >+ boolean handleHelp = false; >+ if (completionNode != null) { >+ IASTName[] names = completionNode.getNames(); >+ for (int i = 0; i < names.length; ++i) { >+ IASTName name = names[i]; >+ >+ // ignore if not connected >+ if (name.getTranslationUnit() == null) >+ continue; >+ >+ // ignore if this is a member access >+ if (name.getParent() instanceof IASTFieldReference) >+ continue; >+ >+ handleHelp = true; >+ break; >+ } >+ } >+ >+ if (!handleHelp) { >+ return Collections.EMPTY_LIST; >+ } >+ >+ final ITranslationUnit tu = cContext.getTranslationUnit(); >+ // Find matching functions >+ ICHelpInvocationContext helpContext = new ICHelpInvocationContext() { >+ >+ public IProject getProject() { >+ return tu.getCProject().getProject(); >+ } >+ >+ public ITranslationUnit getTranslationUnit() { >+ return tu; >+ } >+ }; >+ >+ IFunctionSummary[] summaries = CHelpProviderManager.getDefault() >+ .getMatchingFunctions(helpContext, prefix); >+ if (summaries == null) >+ return Collections.EMPTY_LIST; >+ >+ int repOffset = cContext.getInvocationOffset() - prefix.length(); >+ int repLength = prefix.length(); >+ Image image = CUIPlugin.getImageDescriptorRegistry().get( >+ CElementImageProvider.getFunctionImageDescriptor()); >+ >+ List proposals = new ArrayList(); >+ >+ for (int j = 0; j < summaries.length; j++) { >+ IFunctionSummary summary = summaries[j]; >+ String fname = summary.getName() + "()"; //$NON-NLS-1$ >+ String fdesc = summary.getDescription(); >+ IFunctionSummary.IFunctionPrototypeSummary fproto = summary >+ .getPrototype(); >+ String fargs = fproto.getArguments(); >+ >+ CCompletionProposal proposal; >+ proposal = new CCompletionProposal( >+ fname, >+ repOffset, >+ repLength, >+ image, >+ fproto.getPrototypeString(true), >+ 2, >+ cContext.getViewer()); >+ >+ if (fdesc != null) { >+ proposal.setAdditionalProposalInfo(fdesc); >+ } >+ >+ if (!cContext.isContextInformationStyle()) { >+ // set the cursor before the closing bracket >+ proposal.setCursorPosition(fname.length() - 1); >+ } >+ >+ if (fargs != null && fargs.length() > 0) { >+ CProposalContextInformation info = new CProposalContextInformation(image, fname, fargs); >+ info.setContextInformationPosition(cContext.getContextInformationOffset()); >+ proposal.setContextInformation(info); >+ >+ } >+ >+ proposals.add(proposal); >+ } >+ >+ return proposals; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 175283
:
59656
|
59707