mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
run the init of completion contributor in a ISafeRunnable
This commit is contained in:
parent
67b40d2e68
commit
fd3e1ebcc0
1 changed files with 50 additions and 45 deletions
|
@ -5,18 +5,18 @@ package org.eclipse.cdt.internal.ui;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import org.eclipse.cdt.ui.*;
|
|
||||||
import org.eclipse.cdt.ui.ICCompletionContributor;
|
|
||||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.ICCompletionContributor;
|
||||||
|
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||||
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.IExtensionPoint;
|
||||||
|
import org.eclipse.core.runtime.ISafeRunnable;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages external plugins that contribute completion and function
|
* Manages external plugins that contribute completion and function
|
||||||
* info through the CCompletionContributor extension point
|
* info through the CCompletionContributor extension point
|
||||||
|
@ -28,86 +28,91 @@ public class CCompletionContributorManager {
|
||||||
static boolean fContributorsLoaded = false;
|
static boolean fContributorsLoaded = false;
|
||||||
public static final String CONTRIBUTION_EXTENSION = "CCompletionContributor";
|
public static final String CONTRIBUTION_EXTENSION = "CCompletionContributor";
|
||||||
static private CCompletionContributorManager fInstance;
|
static private CCompletionContributorManager fInstance;
|
||||||
|
|
||||||
|
|
||||||
private CCompletionContributorManager() {
|
private CCompletionContributorManager() {
|
||||||
// Initialize and scan the extension points
|
// Initialize and scan the extension points
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CCompletionContributorManager getDefault() {
|
public static CCompletionContributorManager getDefault() {
|
||||||
if(fInstance == null) {
|
if (fInstance == null) {
|
||||||
fInstance = new CCompletionContributorManager();
|
fInstance = new CCompletionContributorManager();
|
||||||
}
|
}
|
||||||
return fInstance;
|
return fInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFunctionSummary getFunctionInfo(String name) {
|
public IFunctionSummary getFunctionInfo(String name) {
|
||||||
if(!fContributorsLoaded)
|
if (!fContributorsLoaded)
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
|
|
||||||
for (int i= 0; i < fCompletionContributors.size(); i++) {
|
for (int i = 0; i < fCompletionContributors.size(); i++) {
|
||||||
ICCompletionContributor c = (ICCompletionContributor)fCompletionContributors.get(i);
|
ICCompletionContributor c = (ICCompletionContributor) fCompletionContributors.get(i);
|
||||||
IFunctionSummary f = c.getFunctionInfo(name);
|
IFunctionSummary f = c.getFunctionInfo(name);
|
||||||
|
|
||||||
if(f != null)
|
if (f != null)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFunctionSummary[] getMatchingFunctions(String frag) {
|
public IFunctionSummary[] getMatchingFunctions(String frag) {
|
||||||
if(!fContributorsLoaded)
|
if (!fContributorsLoaded)
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
IFunctionSummary[] fs = null;
|
IFunctionSummary[] fs = null;
|
||||||
|
|
||||||
for (int i= 0; i < fCompletionContributors.size(); i++) {
|
for (int i = 0; i < fCompletionContributors.size(); i++) {
|
||||||
ICCompletionContributor c = (ICCompletionContributor)fCompletionContributors.get(i);
|
ICCompletionContributor c = (ICCompletionContributor) fCompletionContributors.get(i);
|
||||||
IFunctionSummary[] f = c.getMatchingFunctions(frag);
|
IFunctionSummary[] f = c.getMatchingFunctions(frag);
|
||||||
if(f != null) {
|
if (f != null) {
|
||||||
if(fs != null) {
|
if (fs != null) {
|
||||||
int length = f.length + fs.length;
|
int length = f.length + fs.length;
|
||||||
IFunctionSummary[] ft = new IFunctionSummary[length];
|
IFunctionSummary[] ft = new IFunctionSummary[length];
|
||||||
int j;
|
int j;
|
||||||
for(j = 0; j < fs.length; j++) ft[j] = fs[j];
|
for (j = 0; j < fs.length; j++)
|
||||||
for(j = 0; j < f.length; j++) ft[j + fs.length] = f[j];
|
ft[j] = fs[j];
|
||||||
|
for (j = 0; j < f.length; j++)
|
||||||
|
ft[j + fs.length] = f[j];
|
||||||
fs = ft;
|
fs = ft;
|
||||||
} else {
|
} else {
|
||||||
fs = f;
|
fs = f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(f != null)
|
//if(f != null)
|
||||||
//return f;
|
//return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadExtensions() {
|
private void loadExtensions() {
|
||||||
fContributorsLoaded = true;
|
fContributorsLoaded = true;
|
||||||
fCompletionContributors= new ArrayList(2);
|
fCompletionContributors = new ArrayList(2);
|
||||||
|
|
||||||
// populate list
|
// populate list
|
||||||
IExtensionPoint extensionPoint= Platform.getPluginRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "CCompletionContributor"); //$NON-NLS-1$
|
IExtensionPoint extensionPoint = Platform.getPluginRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "CCompletionContributor"); //$NON-NLS-1$
|
||||||
if (extensionPoint != null) {
|
if (extensionPoint != null) {
|
||||||
IConfigurationElement[] elements= extensionPoint.getConfigurationElements();
|
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
|
||||||
for (int i= 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
if(elements[i].getName().equals("provider")) {
|
if (elements[i].getName().equals("provider")) {
|
||||||
ICCompletionContributor c;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
final ICCompletionContributor c;
|
||||||
// Instantiate the classe
|
// Instantiate the classe
|
||||||
c = (ICCompletionContributor)elements[i].createExecutableExtension("class");
|
c = (ICCompletionContributor) elements[i].createExecutableExtension("class");
|
||||||
// Initialize
|
ISafeRunnable runnable = new ISafeRunnable() {
|
||||||
c.initialize();
|
public void run() throws Exception {
|
||||||
// Add to contributor list
|
// Initialize
|
||||||
fCompletionContributors.add(c);
|
c.initialize();
|
||||||
|
// Add to contributor list
|
||||||
|
fCompletionContributors.add(c);
|
||||||
|
}
|
||||||
|
public void handleException(Throwable exception) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Platform.run(runnable);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
System.out.println("Unable to instantiate ContributionManager extension");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue