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:
parent
42f4d8f013
commit
55bd838834
9 changed files with 378 additions and 99 deletions
|
@ -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
|
||||
|
||||
Duplication in the CView.
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
<import plugin="org.eclipse.ui.console"/>
|
||||
<import plugin="org.eclipse.core.filebuffers"/>
|
||||
<import plugin="org.eclipse.core.runtime"/>
|
||||
<import plugin="org.eclipse.core.expressions"/>
|
||||
</requires>
|
||||
|
||||
|
||||
|
|
|
@ -12,15 +12,17 @@ package org.eclipse.cdt.internal.ui;
|
|||
|
||||
|
||||
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.ICCompletionContributor;
|
||||
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.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.ISafeRunnable;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
/**
|
||||
|
@ -30,9 +32,10 @@ import org.eclipse.core.runtime.Platform;
|
|||
|
||||
public class CCompletionContributorManager {
|
||||
|
||||
static private List fCompletionContributors;
|
||||
static boolean fContributorsLoaded = false;
|
||||
public static final String CONTRIBUTION_EXTENSION = "CCompletionContributor"; //$NON-NLS-1$
|
||||
private static CCompletionContributorDescriptor[] fCCompletionContributorDescriptors = null;
|
||||
|
||||
|
||||
static private CCompletionContributorManager fInstance;
|
||||
|
||||
private CCompletionContributorManager() {
|
||||
|
@ -46,79 +49,88 @@ public class CCompletionContributorManager {
|
|||
return fInstance;
|
||||
}
|
||||
|
||||
public IFunctionSummary getFunctionInfo(String name) {
|
||||
if (!fContributorsLoaded)
|
||||
loadExtensions();
|
||||
|
||||
for (int i = 0; i < fCompletionContributors.size(); i++) {
|
||||
ICCompletionContributor c = (ICCompletionContributor) fCompletionContributors.get(i);
|
||||
IFunctionSummary f = c.getFunctionInfo(name);
|
||||
|
||||
if (f != null)
|
||||
return f;
|
||||
public IFunctionSummary getFunctionInfo(ICCompletionInvocationContext context, String name) {
|
||||
CCompletionContributorDescriptor[] desc = getCCompletionContributorDescriptors();
|
||||
for (int i = 0; i < desc.length; i++) {
|
||||
try {
|
||||
ICCompletionContributor c = null;
|
||||
ITranslationUnit unit = context.getTranslationUnit();
|
||||
if (unit != null) {
|
||||
c = desc[i].getCCompletionContributor(unit);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
public IFunctionSummary[] getMatchingFunctions(String frag) {
|
||||
if (!fContributorsLoaded)
|
||||
loadExtensions();
|
||||
public IFunctionSummary[] getMatchingFunctions(ICCompletionInvocationContext context, String frag) {
|
||||
|
||||
IFunctionSummary[] fs = null;
|
||||
|
||||
for (int i = 0; i < fCompletionContributors.size(); i++) {
|
||||
ICCompletionContributor c = (ICCompletionContributor) fCompletionContributors.get(i);
|
||||
IFunctionSummary[] f = c.getMatchingFunctions(frag);
|
||||
if (f != null) {
|
||||
if (fs != null) {
|
||||
int length = f.length + fs.length;
|
||||
IFunctionSummary[] ft = new IFunctionSummary[length];
|
||||
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;
|
||||
CCompletionContributorDescriptor[] desc = getCCompletionContributorDescriptors();
|
||||
for (int i = 0; i < desc.length; i++) {
|
||||
try {
|
||||
ICCompletionContributor c = null;
|
||||
ITranslationUnit unit = context.getTranslationUnit();
|
||||
if (unit != null) {
|
||||
c = desc[i].getCCompletionContributor(unit);
|
||||
} 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;
|
||||
}
|
||||
|
||||
private void loadExtensions() {
|
||||
fContributorsLoaded = true;
|
||||
fCompletionContributors = new ArrayList(2);
|
||||
private static CCompletionContributorDescriptor[] getCCompletionContributorDescriptors() {
|
||||
if (fCCompletionContributorDescriptors == null) {
|
||||
fCCompletionContributorDescriptors= getCCompletionContributorDescriptors(CONTRIBUTION_EXTENSION);
|
||||
}
|
||||
return fCCompletionContributorDescriptors;
|
||||
}
|
||||
|
||||
// populate list
|
||||
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "CCompletionContributor"); //$NON-NLS-1$
|
||||
if (extensionPoint != null) {
|
||||
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
if (elements[i].getName().equals("provider")) { //$NON-NLS-1$
|
||||
try {
|
||||
final ICCompletionContributor c;
|
||||
// Instantiate the class
|
||||
c = (ICCompletionContributor) elements[i].createExecutableExtension("class"); //$NON-NLS-1$
|
||||
ISafeRunnable runnable = new ISafeRunnable() {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
private static CCompletionContributorDescriptor[] getCCompletionContributorDescriptors(String contributionId) {
|
||||
IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(CUIPlugin.PLUGIN_ID, contributionId);
|
||||
ArrayList res= new ArrayList(elements.length);
|
||||
for (int i= 0; i < elements.length; i++) {
|
||||
CCompletionContributorDescriptor desc= new CCompletionContributorDescriptor(elements[i]);
|
||||
IStatus status= desc.checkSyntax();
|
||||
if (status.isOK()) {
|
||||
res.add(desc);
|
||||
} else {
|
||||
CUIPlugin.getDefault().log(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (CCompletionContributorDescriptor[]) res.toArray(new CCompletionContributorDescriptor[res.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||
import org.eclipse.cdt.ui.IRequiredInclude;
|
||||
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.runtime.IProgressMonitor;
|
||||
|
||||
|
@ -219,7 +220,22 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
|||
final IFunctionSummary[] fs = new IFunctionSummary[1];
|
||||
IRunnableWithProgress op = new IRunnableWithProgress() {
|
||||
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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,15 +11,20 @@
|
|||
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.editor.CEditorMessages;
|
||||
import org.eclipse.cdt.internal.ui.text.CWordFinder;
|
||||
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.text.ICCompletionInvocationContext;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
|
||||
public class CDocHover extends AbstractCEditorTextHover {
|
||||
|
||||
|
@ -35,7 +40,7 @@ public class CDocHover extends AbstractCEditorTextHover {
|
|||
public String getHoverInfo(ITextViewer viewer, IRegion region) {
|
||||
String expression = null;
|
||||
|
||||
if(getEditor() == null)
|
||||
if (getEditor() == null)
|
||||
return null;
|
||||
try {
|
||||
expression = viewer.getDocument().get(region.getOffset(), region.getLength());
|
||||
|
@ -45,9 +50,25 @@ public class CDocHover extends AbstractCEditorTextHover {
|
|||
|
||||
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) {
|
||||
buffer.append(CEditorMessages.getString("DefaultCEditorTextHover.html.name")); //$NON-NLS-1$
|
||||
buffer.append(HTMLPrinter.convertToHTMLContent(fs.getName()));
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
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.parser.ast.ASTAccessVisibility;
|
||||
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.text.CParameterListValidator;
|
||||
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.FunctionPrototypeSummary;
|
||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
@ -108,7 +109,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
private TemplateEngine[] fFunctionContextTemplateEngine;
|
||||
private TemplateEngine[] fStructureContextTemplateEngine;
|
||||
|
||||
private boolean fRestrictToMatchingCase;
|
||||
//private boolean fRestrictToMatchingCase;
|
||||
private boolean fAllowAddIncludes;
|
||||
|
||||
private BasicSearchResultCollector searchResultCollector = null;
|
||||
|
@ -116,10 +117,11 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
private CompletionEngine completionEngine = null;
|
||||
|
||||
private SearchEngine searchEngine = null;
|
||||
private CSearchResultLabelProvider labelProvider = null;
|
||||
//private CSearchResultLabelProvider labelProvider = null;
|
||||
|
||||
IWorkingCopy fCurrentSourceUnit = null;
|
||||
|
||||
private int fCurrentOffset = 0;
|
||||
private IWorkingCopy fCurrentSourceUnit = null;
|
||||
private IASTCompletionNode fCurrentCompletionNode = null;
|
||||
private int fNumberOfComputedResults= 0;
|
||||
private ITextViewer fTextViewer;
|
||||
|
@ -128,7 +130,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
fEditor = (CEditor) editor;
|
||||
|
||||
// Needed for search
|
||||
labelProvider = new CSearchResultLabelProvider();
|
||||
//labelProvider = new CSearchResultLabelProvider();
|
||||
searchResultCollector = new BasicSearchResultCollector ();
|
||||
resultCollector = new ResultCollector();
|
||||
completionEngine = new CompletionEngine(resultCollector);
|
||||
|
@ -136,7 +138,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
searchEngine.setWaitingPolicy( ICSearchConstants.FORCE_IMMEDIATE_SEARCH );
|
||||
setupTemplateEngine();
|
||||
|
||||
fRestrictToMatchingCase = false;
|
||||
//fRestrictToMatchingCase = false;
|
||||
fAllowAddIncludes = true;
|
||||
|
||||
fComparator = new CCompletionProposalComparator();
|
||||
|
@ -163,10 +165,9 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
//Defer to the nature of the project
|
||||
IFile file = fEditor.getInputFile();
|
||||
if (file != null && CoreModel.hasCCNature(file.getProject())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,10 +399,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
|
||||
return order ( (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]) );
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addProposalsFromTemplates(ITextViewer viewer, IASTCompletionNode completionNode, List completions){
|
||||
|
@ -453,7 +451,17 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
@ -485,19 +493,19 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private FunctionPrototypeSummary getPrototype (BasicSearchMatch match) {
|
||||
switch(match.getElementType()){
|
||||
case ICElement.C_FUNCTION:
|
||||
case ICElement.C_FUNCTION_DECLARATION:
|
||||
case ICElement.C_METHOD:
|
||||
case ICElement.C_METHOD_DECLARATION:
|
||||
{
|
||||
return (new FunctionPrototypeSummary ( match.getReturnType() + " " + match.getName() )); //$NON-NLS-1$
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// private FunctionPrototypeSummary getPrototype (BasicSearchMatch match) {
|
||||
// switch(match.getElementType()){
|
||||
// case ICElement.C_FUNCTION:
|
||||
// case ICElement.C_FUNCTION_DECLARATION:
|
||||
// case ICElement.C_METHOD:
|
||||
// case ICElement.C_METHOD_DECLARATION:
|
||||
// {
|
||||
// return (new FunctionPrototypeSummary ( match.getReturnType() + " " + match.getName() )); //$NON-NLS-1$
|
||||
// }
|
||||
// default:
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
private IASTCompletionNode addProposalsFromModel(List completions){
|
||||
|
@ -517,7 +525,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
|
||||
// figure out the search scope
|
||||
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);
|
||||
ICSearchScope scope = null;
|
||||
|
||||
|
@ -530,7 +538,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
List elementsFound = new LinkedList();
|
||||
|
||||
ICElement[] projectScopeElement = new ICElement[1];
|
||||
projectScopeElement[0] = (ICElement)fCurrentSourceUnit.getCProject();
|
||||
projectScopeElement[0] = fCurrentSourceUnit.getCProject();
|
||||
scope = SearchEngine.createCSearchScope(projectScopeElement, true);
|
||||
|
||||
// search for global variables, functions, classes, structs, unions, enums, macros, and namespaces
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICCompletionInvocationContext;
|
||||
|
||||
|
||||
public interface ICCompletionContributor {
|
||||
|
||||
|
@ -21,11 +23,11 @@ public interface ICCompletionContributor {
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
IFunctionSummary[] getMatchingFunctions(String prefix);
|
||||
IFunctionSummary[] getMatchingFunctions(ICCompletionInvocationContext context, String prefix);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue