1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2004-08-12 Alain Magloire

Fix for PR 71667.
	Changes to the CCompletionContributor to pass
	a context.

	* src/org/eclipse/cdt/internal/ui/CCompletionContributorManager.java
	* src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSlectionAction.java
	* src/org/eclipse/cdt/internal/ui/text/CCompletionContributorDescriptor.java
	* src/org/eclipse/cdt/internal/ui/text/hover/CDocHover.java
	* src/org/eclipse/cdt/internal/ui/t4xt/CCompletionProcessor.java
	* src/org/eclipse/cdt/ui/ICCompletionContributor.java
	* src/org/eclipse/cdt/ui/text/ICCompletionInvocationContext.java
	* plugin.xml
This commit is contained in:
Alain Magloire 2004-08-12 19:17:42 +00:00
parent 42f4d8f013
commit 55bd838834
9 changed files with 378 additions and 99 deletions

View file

@ -1,3 +1,18 @@
2004-08-12 Alain Magloire
Fix for PR 71667.
Changes to the CCompletionContributor to pass
a context.
* src/org/eclipse/cdt/internal/ui/CCompletionContributorManager.java
* src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSlectionAction.java
* src/org/eclipse/cdt/internal/ui/text/CCompletionContributorDescriptor.java
* src/org/eclipse/cdt/internal/ui/text/hover/CDocHover.java
* src/org/eclipse/cdt/internal/ui/t4xt/CCompletionProcessor.java
* src/org/eclipse/cdt/ui/ICCompletionContributor.java
* src/org/eclipse/cdt/ui/text/ICCompletionInvocationContext.java
* plugin.xml
2004-08-11 Alain Magloire 2004-08-11 Alain Magloire
Duplication in the CView. Duplication in the CView.

View file

@ -26,6 +26,7 @@
<import plugin="org.eclipse.ui.console"/> <import plugin="org.eclipse.ui.console"/>
<import plugin="org.eclipse.core.filebuffers"/> <import plugin="org.eclipse.core.filebuffers"/>
<import plugin="org.eclipse.core.runtime"/> <import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.core.expressions"/>
</requires> </requires>

View file

@ -12,15 +12,17 @@ package org.eclipse.cdt.internal.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.text.CCompletionContributorDescriptor;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICCompletionContributor; import org.eclipse.cdt.ui.ICCompletionContributor;
import org.eclipse.cdt.ui.IFunctionSummary; import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
/** /**
@ -30,9 +32,10 @@ import org.eclipse.core.runtime.Platform;
public class CCompletionContributorManager { public class CCompletionContributorManager {
static private List fCompletionContributors;
static boolean fContributorsLoaded = false;
public static final String CONTRIBUTION_EXTENSION = "CCompletionContributor"; //$NON-NLS-1$ public static final String CONTRIBUTION_EXTENSION = "CCompletionContributor"; //$NON-NLS-1$
private static CCompletionContributorDescriptor[] fCCompletionContributorDescriptors = null;
static private CCompletionContributorManager fInstance; static private CCompletionContributorManager fInstance;
private CCompletionContributorManager() { private CCompletionContributorManager() {
@ -46,79 +49,88 @@ public class CCompletionContributorManager {
return fInstance; return fInstance;
} }
public IFunctionSummary getFunctionInfo(String name) { public IFunctionSummary getFunctionInfo(ICCompletionInvocationContext context, String name) {
if (!fContributorsLoaded) CCompletionContributorDescriptor[] desc = getCCompletionContributorDescriptors();
loadExtensions(); for (int i = 0; i < desc.length; i++) {
try {
for (int i = 0; i < fCompletionContributors.size(); i++) { ICCompletionContributor c = null;
ICCompletionContributor c = (ICCompletionContributor) fCompletionContributors.get(i); ITranslationUnit unit = context.getTranslationUnit();
IFunctionSummary f = c.getFunctionInfo(name); if (unit != null) {
c = desc[i].getCCompletionContributor(unit);
if (f != null) } else {
return f; IProject project = context.getProject();
c = desc[i].getCCompletionContributor(project);
}
IFunctionSummary f = c.getFunctionInfo(context, name);
if (f != null) {
return f;
}
} catch (CoreException e) {
//
}
} }
return null; return null;
} }
public IFunctionSummary[] getMatchingFunctions(String frag) { public IFunctionSummary[] getMatchingFunctions(ICCompletionInvocationContext context, String frag) {
if (!fContributorsLoaded)
loadExtensions();
IFunctionSummary[] fs = null; IFunctionSummary[] fs = null;
for (int i = 0; i < fCompletionContributors.size(); i++) { CCompletionContributorDescriptor[] desc = getCCompletionContributorDescriptors();
ICCompletionContributor c = (ICCompletionContributor) fCompletionContributors.get(i); for (int i = 0; i < desc.length; i++) {
IFunctionSummary[] f = c.getMatchingFunctions(frag); try {
if (f != null) { ICCompletionContributor c = null;
if (fs != null) { ITranslationUnit unit = context.getTranslationUnit();
int length = f.length + fs.length; if (unit != null) {
IFunctionSummary[] ft = new IFunctionSummary[length]; c = desc[i].getCCompletionContributor(unit);
int j;
for (j = 0; j < fs.length; j++)
ft[j] = fs[j];
for (j = 0; j < f.length; j++)
ft[j + fs.length] = f[j];
fs = ft;
} else { } else {
fs = f; IProject project = context.getProject();
c = desc[i].getCCompletionContributor(project);
} }
if (c == null) {
continue;
}
IFunctionSummary[] f = c.getMatchingFunctions(context, frag);
if (f != null) {
if (fs == null) {
fs = f;
} else {
IFunctionSummary[] dest = new IFunctionSummary[fs.length + f.length];
System.arraycopy(fs, 0, dest, 0, fs.length);
System.arraycopy(f, 0, dest, fs.length, f.length);
fs = dest;
}
}
} catch (CoreException e) {
//
} }
//if(f != null)
//return f;
} }
return fs; return fs;
} }
private void loadExtensions() { private static CCompletionContributorDescriptor[] getCCompletionContributorDescriptors() {
fContributorsLoaded = true; if (fCCompletionContributorDescriptors == null) {
fCompletionContributors = new ArrayList(2); fCCompletionContributorDescriptors= getCCompletionContributorDescriptors(CONTRIBUTION_EXTENSION);
}
return fCCompletionContributorDescriptors;
}
// populate list
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "CCompletionContributor"); //$NON-NLS-1$ private static CCompletionContributorDescriptor[] getCCompletionContributorDescriptors(String contributionId) {
if (extensionPoint != null) { IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(CUIPlugin.PLUGIN_ID, contributionId);
IConfigurationElement[] elements = extensionPoint.getConfigurationElements(); ArrayList res= new ArrayList(elements.length);
for (int i = 0; i < elements.length; i++) { for (int i= 0; i < elements.length; i++) {
if (elements[i].getName().equals("provider")) { //$NON-NLS-1$ CCompletionContributorDescriptor desc= new CCompletionContributorDescriptor(elements[i]);
try { IStatus status= desc.checkSyntax();
final ICCompletionContributor c; if (status.isOK()) {
// Instantiate the class res.add(desc);
c = (ICCompletionContributor) elements[i].createExecutableExtension("class"); //$NON-NLS-1$ } else {
ISafeRunnable runnable = new ISafeRunnable() { CUIPlugin.getDefault().log(status);
public void run() throws Exception {
// Initialize
c.initialize();
// Add to contributor list
fCompletionContributors.add(c);
}
public void handleException(Throwable exception) {
}
};
Platform.run(runnable);
} catch (CoreException e) {
}
}
} }
} }
return (CCompletionContributorDescriptor[]) res.toArray(new CCompletionContributorDescriptor[res.size()]);
} }
} }

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IFunctionSummary; import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IRequiredInclude; import org.eclipse.cdt.ui.IRequiredInclude;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider; import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -219,7 +220,22 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
final IFunctionSummary[] fs = new IFunctionSummary[1]; final IFunctionSummary[] fs = new IFunctionSummary[1];
IRunnableWithProgress op = new IRunnableWithProgress() { IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
fs[0] = CCompletionContributorManager.getDefault().getFunctionInfo(name); ICCompletionInvocationContext context = new ICCompletionInvocationContext() {
public IProject getProject() {
ITranslationUnit u = getTranslationUnit();
if (u != null) {
return u.getCProject().getProject();
}
return null;
}
public ITranslationUnit getTranslationUnit() {
return AddIncludeOnSelectionAction.this.getTranslationUnit();
}
};
fs[0] = CCompletionContributorManager.getDefault().getFunctionInfo(context, name);
} }
}; };
try { try {

View file

@ -0,0 +1,172 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import java.util.Arrays;
import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.ExpressionConverter;
import org.eclipse.core.expressions.ExpressionTagNames;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICCompletionContributor;
/**
* @author alain
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CCompletionContributorDescriptor {
private IConfigurationElement fConfigurationElement;
private ICCompletionContributor fContributorInstance;
private ITranslationUnit fLastUnit;
private Boolean fStatus;
private boolean fLastResult;
private static final String ID= "id"; //$NON-NLS-1$
private static final String CLASS= "class"; //$NON-NLS-1$
public CCompletionContributorDescriptor(IConfigurationElement element) {
fConfigurationElement= element;
fContributorInstance= null;
fLastUnit= null;
fStatus= null; // undefined
if (fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT).length == 0) {
fStatus= Boolean.TRUE;
}
}
public IStatus checkSyntax() {
IConfigurationElement[] children= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
if (children.length > 1) {
String id= fConfigurationElement.getAttribute(ID);
return new StatusInfo(IStatus.ERROR, "Only one <enablement> element allowed. Disabling " + id); //$NON-NLS-1$
}
return new StatusInfo(IStatus.OK, "Syntactically correct quick assist/fix processor"); //$NON-NLS-1$
}
private boolean matches(ITranslationUnit unit) {
if (fStatus != null) {
return fStatus.booleanValue();
}
IConfigurationElement[] children= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
if (children.length == 1) {
if (unit.equals(fLastUnit)) {
return fLastResult;
}
try {
ExpressionConverter parser= ExpressionConverter.getDefault();
Expression expression= parser.perform(children[0]);
EvaluationContext evalContext= new EvaluationContext(null, unit);
evalContext.addVariable("translationUnit", unit); //$NON-NLS-1$
String[] natures= unit.getCProject().getProject().getDescription().getNatureIds();
evalContext.addVariable("projectNatures", Arrays.asList(natures)); //$NON-NLS-1$
fLastResult= !(expression.evaluate(evalContext) != EvaluationResult.TRUE);
fLastUnit= unit;
return fLastResult;
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
fStatus= Boolean.FALSE;
return false;
}
public ICCompletionContributor getCCompletionContributor(ITranslationUnit cunit) throws CoreException {
if (matches(cunit)) {
if (fContributorInstance == null) {
try {
fContributorInstance= (ICCompletionContributor)fConfigurationElement.createExecutableExtension(CLASS);
final ICCompletionContributor c = fContributorInstance;
// Run the initialiser the class
ISafeRunnable runnable = new ISafeRunnable() {
public void run() throws Exception {
// Initialize
c.initialize();
}
public void handleException(Throwable exception) {
}
};
Platform.run(runnable);
} catch (ClassCastException e) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "", e)); //$NON-NLS-1$
}
}
return fContributorInstance;
}
return null;
}
private boolean matches(IProject project) {
if (fStatus != null) {
return fStatus.booleanValue();
}
IConfigurationElement[] children= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
if (children.length == 1 && project != null) {
try {
ExpressionConverter parser= ExpressionConverter.getDefault();
Expression expression= parser.perform(children[0]);
EvaluationContext evalContext= new EvaluationContext(null, project);
String[] natures= project.getDescription().getNatureIds();
evalContext.addVariable("projectNatures", Arrays.asList(natures)); //$NON-NLS-1$
fLastResult= !(expression.evaluate(evalContext) != EvaluationResult.TRUE);
return fLastResult;
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
fStatus= Boolean.FALSE;
return false;
}
public ICCompletionContributor getCCompletionContributor(IProject project) throws CoreException {
if (matches(project)) {
if (fContributorInstance == null) {
try {
fContributorInstance= (ICCompletionContributor)fConfigurationElement.createExecutableExtension(CLASS);
final ICCompletionContributor c = fContributorInstance;
// Run the initialiser the class
ISafeRunnable runnable = new ISafeRunnable() {
public void run() throws Exception {
// Initialize
c.initialize();
}
public void handleException(Throwable exception) {
}
};
Platform.run(runnable);
} catch (ClassCastException e) {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "", e)); //$NON-NLS-1$
}
}
return fContributorInstance;
}
return null;
}
}

View file

@ -11,15 +11,20 @@
package org.eclipse.cdt.internal.ui.text.c.hover; package org.eclipse.cdt.internal.ui.text.c.hover;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.CCompletionContributorManager; import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.internal.ui.text.CWordFinder; import org.eclipse.cdt.internal.ui.text.CWordFinder;
import org.eclipse.cdt.internal.ui.text.HTMLPrinter; import org.eclipse.cdt.internal.ui.text.HTMLPrinter;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IFunctionSummary; import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region; import org.eclipse.jface.text.Region;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorInput;
public class CDocHover extends AbstractCEditorTextHover { public class CDocHover extends AbstractCEditorTextHover {
@ -35,7 +40,7 @@ public class CDocHover extends AbstractCEditorTextHover {
public String getHoverInfo(ITextViewer viewer, IRegion region) { public String getHoverInfo(ITextViewer viewer, IRegion region) {
String expression = null; String expression = null;
if(getEditor() == null) if (getEditor() == null)
return null; return null;
try { try {
expression = viewer.getDocument().get(region.getOffset(), region.getLength()); expression = viewer.getDocument().get(region.getOffset(), region.getLength());
@ -45,9 +50,25 @@ public class CDocHover extends AbstractCEditorTextHover {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
// We are just doing some C, call the Help to get info // call the Help to get info
IFunctionSummary fs = CCompletionContributorManager.getDefault().getFunctionInfo(expression); ICCompletionInvocationContext context = new ICCompletionInvocationContext() {
public IProject getProject() {
ITranslationUnit unit = getTranslationUnit();
if (unit != null) {
return unit.getCProject().getProject();
}
return null;
}
public ITranslationUnit getTranslationUnit() {
IEditorInput editorInput= getEditor().getEditorInput();
return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
}
};
IFunctionSummary fs = CCompletionContributorManager.getDefault().getFunctionInfo(context, expression);
if (fs != null) { if (fs != null) {
buffer.append(CEditorMessages.getString("DefaultCEditorTextHover.html.name")); //$NON-NLS-1$ buffer.append(CEditorMessages.getString("DefaultCEditorTextHover.html.name")); //$NON-NLS-1$
buffer.append(HTMLPrinter.convertToHTMLContent(fs.getName())); buffer.append(HTMLPrinter.convertToHTMLContent(fs.getName()));

View file

@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
@ -31,13 +32,13 @@ import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.CParameterListValidator; import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
import org.eclipse.cdt.internal.ui.text.template.TemplateEngine; import org.eclipse.cdt.internal.ui.text.template.TemplateEngine;
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.FunctionPrototypeSummary;
import org.eclipse.cdt.ui.IFunctionSummary; import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
import org.eclipse.cdt.ui.text.ICCompletionProposal; import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -108,7 +109,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
private TemplateEngine[] fFunctionContextTemplateEngine; private TemplateEngine[] fFunctionContextTemplateEngine;
private TemplateEngine[] fStructureContextTemplateEngine; private TemplateEngine[] fStructureContextTemplateEngine;
private boolean fRestrictToMatchingCase; //private boolean fRestrictToMatchingCase;
private boolean fAllowAddIncludes; private boolean fAllowAddIncludes;
private BasicSearchResultCollector searchResultCollector = null; private BasicSearchResultCollector searchResultCollector = null;
@ -116,10 +117,11 @@ public class CCompletionProcessor implements IContentAssistProcessor {
private CompletionEngine completionEngine = null; private CompletionEngine completionEngine = null;
private SearchEngine searchEngine = null; private SearchEngine searchEngine = null;
private CSearchResultLabelProvider labelProvider = null; //private CSearchResultLabelProvider labelProvider = null;
IWorkingCopy fCurrentSourceUnit = null;
private int fCurrentOffset = 0; private int fCurrentOffset = 0;
private IWorkingCopy fCurrentSourceUnit = null;
private IASTCompletionNode fCurrentCompletionNode = null; private IASTCompletionNode fCurrentCompletionNode = null;
private int fNumberOfComputedResults= 0; private int fNumberOfComputedResults= 0;
private ITextViewer fTextViewer; private ITextViewer fTextViewer;
@ -128,7 +130,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
fEditor = (CEditor) editor; fEditor = (CEditor) editor;
// Needed for search // Needed for search
labelProvider = new CSearchResultLabelProvider(); //labelProvider = new CSearchResultLabelProvider();
searchResultCollector = new BasicSearchResultCollector (); searchResultCollector = new BasicSearchResultCollector ();
resultCollector = new ResultCollector(); resultCollector = new ResultCollector();
completionEngine = new CompletionEngine(resultCollector); completionEngine = new CompletionEngine(resultCollector);
@ -136,7 +138,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
searchEngine.setWaitingPolicy( ICSearchConstants.FORCE_IMMEDIATE_SEARCH ); searchEngine.setWaitingPolicy( ICSearchConstants.FORCE_IMMEDIATE_SEARCH );
setupTemplateEngine(); setupTemplateEngine();
fRestrictToMatchingCase = false; //fRestrictToMatchingCase = false;
fAllowAddIncludes = true; fAllowAddIncludes = true;
fComparator = new CCompletionProposalComparator(); fComparator = new CCompletionProposalComparator();
@ -163,10 +165,9 @@ public class CCompletionProcessor implements IContentAssistProcessor {
//Defer to the nature of the project //Defer to the nature of the project
IFile file = fEditor.getInputFile(); IFile file = fEditor.getInputFile();
if (file != null && CoreModel.hasCCNature(file.getProject())) { if (file != null && CoreModel.hasCCNature(file.getProject())) {
return true; return true;
} else {
return false;
} }
return false;
} }
} }
@ -398,10 +399,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
return order ( (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]) ); return order ( (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]) );
} }
else{ return null;
return null;
}
} }
private void addProposalsFromTemplates(ITextViewer viewer, IASTCompletionNode completionNode, List completions){ private void addProposalsFromTemplates(ITextViewer viewer, IASTCompletionNode completionNode, List completions){
@ -453,7 +451,17 @@ public class CCompletionProcessor implements IContentAssistProcessor {
IFunctionSummary[] summary; IFunctionSummary[] summary;
summary = CCompletionContributorManager.getDefault().getMatchingFunctions(prefix); ICCompletionInvocationContext context = new ICCompletionInvocationContext() {
public IProject getProject() {
return fCurrentSourceUnit.getCProject().getProject();
}
public ITranslationUnit getTranslationUnit() {
return fCurrentSourceUnit;
}
};
summary = CCompletionContributorManager.getDefault().getMatchingFunctions(context, prefix);
if(summary == null) { if(summary == null) {
return; return;
} }
@ -485,19 +493,19 @@ public class CCompletionProcessor implements IContentAssistProcessor {
} }
} }
private FunctionPrototypeSummary getPrototype (BasicSearchMatch match) { // private FunctionPrototypeSummary getPrototype (BasicSearchMatch match) {
switch(match.getElementType()){ // switch(match.getElementType()){
case ICElement.C_FUNCTION: // case ICElement.C_FUNCTION:
case ICElement.C_FUNCTION_DECLARATION: // case ICElement.C_FUNCTION_DECLARATION:
case ICElement.C_METHOD: // case ICElement.C_METHOD:
case ICElement.C_METHOD_DECLARATION: // case ICElement.C_METHOD_DECLARATION:
{ // {
return (new FunctionPrototypeSummary ( match.getReturnType() + " " + match.getName() )); //$NON-NLS-1$ // return (new FunctionPrototypeSummary ( match.getReturnType() + " " + match.getName() )); //$NON-NLS-1$
} // }
default: // default:
return null; // return null;
} // }
} // }
private IASTCompletionNode addProposalsFromModel(List completions){ private IASTCompletionNode addProposalsFromModel(List completions){
@ -517,7 +525,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
// figure out the search scope // figure out the search scope
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE); //boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE);
boolean projectScope = store.getBoolean(ContentAssistPreference.PROJECT_SEARCH_SCOPE); boolean projectScope = store.getBoolean(ContentAssistPreference.PROJECT_SEARCH_SCOPE);
ICSearchScope scope = null; ICSearchScope scope = null;
@ -530,7 +538,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
List elementsFound = new LinkedList(); List elementsFound = new LinkedList();
ICElement[] projectScopeElement = new ICElement[1]; ICElement[] projectScopeElement = new ICElement[1];
projectScopeElement[0] = (ICElement)fCurrentSourceUnit.getCProject(); projectScopeElement[0] = fCurrentSourceUnit.getCProject();
scope = SearchEngine.createCSearchScope(projectScopeElement, true); scope = SearchEngine.createCSearchScope(projectScopeElement, true);
// search for global variables, functions, classes, structs, unions, enums, macros, and namespaces // search for global variables, functions, classes, structs, unions, enums, macros, and namespaces

View file

@ -10,6 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui; package org.eclipse.cdt.ui;
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
public interface ICCompletionContributor { public interface ICCompletionContributor {
@ -21,11 +23,11 @@ public interface ICCompletionContributor {
/** /**
* get the matching function of a given name * get the matching function of a given name
*/ */
IFunctionSummary getFunctionInfo(String name); IFunctionSummary getFunctionInfo(ICCompletionInvocationContext context, String name);
/** /**
* Get array of matching functions starting with this prefix * Get array of matching functions starting with this prefix
*/ */
IFunctionSummary[] getMatchingFunctions(String prefix); IFunctionSummary[] getMatchingFunctions(ICCompletionInvocationContext context, String prefix);
} }

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.text;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IProject;
/**
* Invocation context for the ICCompletionContributor
*/
public interface ICCompletionInvocationContext {
/**
* @return the project
*/
IProject getProject();
/**
* @return ITranslationUnit or null
*/
ITranslationUnit getTranslationUnit();
}