blob: c6933316c64ae947a102ab93611784c9771a51f8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package org.eclipse.cdt.internal.ui;
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
import java.util.ArrayList;
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.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
/**
* Manages external plugins that contribute completion and function
* info through the CCompletionContributor extension point
*/
public class CCompletionContributorManager {
static private List fCompletionContributors;
static boolean fContributorsLoaded = false;
public static final String CONTRIBUTION_EXTENSION = "CCompletionContributor"; //$NON-NLS-1$
static private CCompletionContributorManager fInstance;
private CCompletionContributorManager() {
// Initialize and scan the extension points
}
public static CCompletionContributorManager getDefault() {
if (fInstance == null) {
fInstance = new 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;
}
return null;
}
public IFunctionSummary[] getMatchingFunctions(String frag) {
if (!fContributorsLoaded)
loadExtensions();
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;
} else {
fs = f;
}
}
//if(f != null)
//return f;
}
return fs;
}
private void loadExtensions() {
fContributorsLoaded = true;
fCompletionContributors = new ArrayList(2);
// populate list
IExtensionPoint extensionPoint = Platform.getPluginRegistry().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 classe
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) {
}
}
}
}
}
}
|