Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 175151 | Differences between
and this patch

Collapse All | Expand All

(-)browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java (-197 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * 		QNX - Initial API and implementation
10
 * 		IBM Corporation
11
 *******************************************************************************/
12
13
package org.eclipse.cdt.core.browser;
14
15
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.dom.IName;
17
import org.eclipse.cdt.core.dom.ast.DOMException;
18
import org.eclipse.cdt.core.dom.ast.IBinding;
19
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
20
import org.eclipse.cdt.core.index.IIndex;
21
import org.eclipse.cdt.core.model.ICProject;
22
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
23
import org.eclipse.cdt.internal.core.CCoreInternals;
24
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
25
import org.eclipse.cdt.internal.core.pdom.PDOM;
26
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
27
import org.eclipse.core.runtime.CoreException;
28
29
/**
30
 * @author Doug Schaefer
31
 *
32
 */
33
public class PDOMTypeInfo implements ITypeInfo {
34
35
	private final IBinding binding;
36
	private final int elementType;
37
	private final ICProject project;
38
39
	public PDOMTypeInfo(IBinding binding, int elementType, ICProject project) {
40
		this.binding = binding;
41
		this.elementType = elementType;
42
		this.project = project;
43
	}
44
	
45
	public void addDerivedReference(ITypeReference location) {
46
		throw new PDOMNotImplementedError();
47
	}
48
49
	public void addReference(ITypeReference location) {
50
		throw new PDOMNotImplementedError();
51
	}
52
53
	public boolean canSubstituteFor(ITypeInfo info) {
54
		throw new PDOMNotImplementedError();
55
	}
56
57
	public boolean encloses(ITypeInfo info) {
58
		throw new PDOMNotImplementedError();
59
	}
60
61
	public boolean exists() {
62
		throw new PDOMNotImplementedError();
63
	}
64
65
	public int getCElementType() {
66
		return elementType;
67
	}
68
69
	public ITypeReference[] getDerivedReferences() {
70
		throw new PDOMNotImplementedError();
71
	}
72
73
	public ITypeInfo[] getEnclosedTypes() {
74
		throw new PDOMNotImplementedError();
75
	}
76
77
	public ITypeInfo[] getEnclosedTypes(int[] kinds) {
78
		throw new PDOMNotImplementedError();
79
	}
80
81
	public ITypeInfo getEnclosingNamespace(boolean includeGlobalNamespace) {
82
		throw new PDOMNotImplementedError();
83
	}
84
85
	public ICProject getEnclosingProject() {
86
		return project;
87
	}
88
89
	public ITypeInfo getEnclosingType() {
90
		// TODO not sure
91
		return null;
92
	}
93
94
	public ITypeInfo getEnclosingType(int[] kinds) {
95
		throw new PDOMNotImplementedError();
96
	}
97
98
	public String getName() {
99
		return binding.getName();
100
	}
101
102
	public IQualifiedTypeName getQualifiedTypeName() {
103
		String qn;
104
		if(binding instanceof ICPPBinding) {
105
			try {
106
				qn = CPPVisitor.renderQualifiedName(((ICPPBinding)binding).getQualifiedName());
107
			} catch(DOMException de) {
108
				CCorePlugin.log(de); // can't happen when (binding instanceof PDOMBinding)
109
				return null;
110
			}
111
		} else {
112
			qn = binding.getName();
113
		}
114
		
115
		return new QualifiedTypeName(qn);
116
	}
117
118
	public ITypeReference[] getReferences() {
119
		throw new PDOMNotImplementedError();
120
	}
121
122
	public ITypeReference getResolvedReference() {
123
		try {
124
			PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project);
125
			IName[] names= pdom.findNames(binding, IIndex.FIND_DEFINITIONS);
126
			return names != null && names.length > 0 ? new PDOMTypeReference(names[0], project) : null;
127
		} catch (CoreException e) {
128
			CCorePlugin.log(e);
129
			return null;
130
		}
131
	}
132
133
	public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
134
		throw new PDOMNotImplementedError();
135
	}
136
137
	public ITypeInfo[] getSubTypes() {
138
		throw new PDOMNotImplementedError();
139
	}
140
141
	public ASTAccessVisibility getSuperTypeAccess(ITypeInfo subType) {
142
		throw new PDOMNotImplementedError();
143
	}
144
145
	public ITypeInfo[] getSuperTypes() {
146
		throw new PDOMNotImplementedError();
147
	}
148
149
	public boolean hasEnclosedTypes() {
150
		throw new PDOMNotImplementedError();
151
	}
152
153
	public boolean hasSubTypes() {
154
		throw new PDOMNotImplementedError();
155
	}
156
157
	public boolean hasSuperTypes() {
158
		throw new PDOMNotImplementedError();
159
	}
160
161
	public boolean isClass() {
162
		throw new PDOMNotImplementedError();
163
	}
164
165
	public boolean isEnclosed(ITypeInfo info) {
166
		throw new PDOMNotImplementedError();
167
	}
168
169
	public boolean isEnclosed(ITypeSearchScope scope) {
170
		throw new PDOMNotImplementedError();
171
	}
172
173
	public boolean isEnclosedType() {
174
		throw new PDOMNotImplementedError();
175
	}
176
177
	public boolean isEnclosingType() {
178
		throw new PDOMNotImplementedError();
179
	}
180
181
	public boolean isReferenced(ITypeSearchScope scope) {
182
		throw new PDOMNotImplementedError();
183
	}
184
185
	public boolean isUndefinedType() {
186
		throw new PDOMNotImplementedError();
187
	}
188
189
	public void setCElementType(int type) {
190
		throw new PDOMNotImplementedError();
191
	}
192
193
	public int compareTo(Object arg0) {
194
		throw new PDOMNotImplementedError();
195
	}
196
197
}
(-)browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java (-94 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * QNX - Initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.core.browser;
13
14
import org.eclipse.cdt.core.dom.IName;
15
import org.eclipse.cdt.core.model.CoreModel;
16
import org.eclipse.cdt.core.model.ICElement;
17
import org.eclipse.cdt.core.model.ICProject;
18
import org.eclipse.cdt.core.model.ITranslationUnit;
19
import org.eclipse.cdt.core.model.IWorkingCopy;
20
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.Path;
25
26
/**
27
 * @author Doug Schaefer
28
 *
29
 */
30
public class PDOMTypeReference implements ITypeReference {
31
	
32
	private final IName name;
33
	private final ICProject project;
34
	private final IPath path; 
35
	
36
	public PDOMTypeReference(IName name, ICProject project) {
37
		this.name = name;
38
		this.project = project;
39
		this.path = new Path(name.getFileLocation().getFileName());
40
	}
41
42
	public ICElement[] getCElements() {
43
		throw new PDOMNotImplementedError();
44
	}
45
46
	public int getLength() {
47
		return name.getFileLocation().getNodeLength();
48
	}
49
50
	public IPath getLocation() {
51
		return path;
52
	}
53
54
	public int getOffset() {
55
		return name.getFileLocation().getNodeOffset();
56
	}
57
58
	public IPath getPath() {
59
		return path;
60
	}
61
62
	public IProject getProject() {
63
		throw new PDOMNotImplementedError();
64
	}
65
66
	public IPath getRelativeIncludePath(IProject project) {
67
		throw new PDOMNotImplementedError();
68
	}
69
70
	public IPath getRelativePath(IPath relativeToPath) {
71
		throw new PDOMNotImplementedError();
72
	}
73
74
	public IResource getResource() {
75
		throw new PDOMNotImplementedError();
76
	}
77
78
	public ITranslationUnit getTranslationUnit() {
79
		ICElement element = CoreModel.getDefault().create(path);
80
		if (element != null && element instanceof ITranslationUnit)
81
			return (ITranslationUnit)element;
82
		else
83
			return CoreModel.getDefault().createTranslationUnitFrom(project, path);
84
	}
85
86
	public IWorkingCopy getWorkingCopy() {
87
		throw new PDOMNotImplementedError();
88
	}
89
90
	public boolean isLineNumber() {
91
		return name.getFileLocation().getNodeLength() == -1;
92
	}
93
94
}
(-)browser/org/eclipse/cdt/core/browser/AllTypesCache.java (-133 / +56 lines)
Lines 7-39 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     QNX Software Systems - initial API and implementation
9
 *     QNX Software Systems - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.core.browser;
12
package org.eclipse.cdt.core.browser;
12
13
13
import java.util.ArrayList;
14
import java.util.regex.Pattern;
14
import java.util.List;
15
15
16
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.CCorePlugin;
17
import org.eclipse.cdt.core.dom.ILinkage;
18
import org.eclipse.cdt.core.dom.IPDOMNode;
19
import org.eclipse.cdt.core.dom.IPDOMVisitor;
20
import org.eclipse.cdt.core.dom.ast.DOMException;
21
import org.eclipse.cdt.core.dom.ast.IBinding;
17
import org.eclipse.cdt.core.dom.ast.IBinding;
22
import org.eclipse.cdt.core.dom.ast.ICompositeType;
18
import org.eclipse.cdt.core.index.IIndex;
23
import org.eclipse.cdt.core.dom.ast.IEnumeration;
19
import org.eclipse.cdt.core.index.IIndexBinding;
24
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
20
import org.eclipse.cdt.core.index.IndexFilter;
25
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
26
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
27
import org.eclipse.cdt.core.model.CoreModel;
21
import org.eclipse.cdt.core.model.CoreModel;
28
import org.eclipse.cdt.core.model.ICElement;
22
import org.eclipse.cdt.core.model.ICElement;
29
import org.eclipse.cdt.core.model.ICProject;
23
import org.eclipse.cdt.core.model.ICProject;
30
import org.eclipse.cdt.internal.core.CCoreInternals;
24
import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil;
31
import org.eclipse.cdt.internal.core.pdom.PDOM;
32
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
33
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
34
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
35
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCStructure;
36
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.NullProgressMonitor;
37
28
38
/**
29
/**
39
 * Manages a search cache for types in the workspace. Instead of returning
30
 * Manages a search cache for types in the workspace. Instead of returning
Lines 49-185 Link Here
49
 * waits for the completion of the background job.
40
 * waits for the completion of the background job.
50
 */
41
 */
51
public class AllTypesCache {
42
public class AllTypesCache {
52
43
	private static final boolean DEBUG = false;
53
	private abstract static class TypesCollector implements IPDOMVisitor {
54
		private final int[] kinds;
55
		protected final List types;
56
		protected final ICProject project;
57
		
58
		protected TypesCollector(int[] kinds, List types, ICProject project) {
59
			this.kinds = kinds;
60
			this.types = types;
61
			this.project = project;
62
		}
63
		
64
		protected abstract void visitKind(IPDOMNode node, int kind);
65
		
66
		public boolean visit(IPDOMNode node) throws CoreException {
67
			for (int i = 0; i < kinds.length; ++i)
68
				visitKind(node, kinds[i]);
69
			return true;
70
		}
71
		
72
		public void leave(IPDOMNode node) throws CoreException {
73
		}
74
		
75
		public List getTypes() {
76
			return types;
77
		}
78
	}
79
	
44
	
80
	private static class CTypesCollector extends TypesCollector {
45
	private static ITypeInfo[] getTypes(ICProject[] projects, final int[] kinds, IProgressMonitor monitor) throws CoreException {
81
		public CTypesCollector(int[] kinds, List types, ICProject project) {
46
		IIndex index = CCorePlugin.getIndexManager().getIndex(projects);
82
			super(kinds, types, project);
83
		}
84
		
47
		
85
		protected void visitKind(IPDOMNode node, int kind) {
48
		try {
86
			switch (kind) {
49
			index.acquireReadLock();
87
			case ICElement.C_NAMESPACE:
50
			
88
				return;
51
			long start = System.currentTimeMillis();
89
			case ICElement.C_CLASS:
52
			
90
				return;
53
			IIndexBinding[] all =
91
			case ICElement.C_STRUCT:
54
				index.findBindings(Pattern.compile(".*"), false, new IndexFilter() { //$NON-NLS-1$
92
				if (node instanceof PDOMCStructure)
55
					public boolean acceptBinding(IBinding binding) {
93
					types.add(new PDOMTypeInfo((IBinding)node, kind, project));
56
						return IndexModelUtil.bindingHasCElementType(binding, kinds);
94
				return;
57
					}},
95
			case ICElement.C_UNION:
58
					monitor
96
				return;
59
				);
97
			case ICElement.C_ENUMERATION:
60
			
98
				return;
61
			if(DEBUG) {
99
			case ICElement.C_TYPEDEF:
62
				System.out.println("Index search took "+(System.currentTimeMillis() - start)); //$NON-NLS-1$
100
				return;
63
				start = System.currentTimeMillis();
101
			}
64
			}
102
		}
65
			
103
	}
66
			ITypeInfo[] result = new ITypeInfo[all.length];
104
	
67
			for(int i=0; i<all.length; i++) {
105
	private static class CPPTypesCollector extends TypesCollector {
68
				IIndexBinding ib = (IIndexBinding) all[i];				
106
		public CPPTypesCollector(int[] kinds, List types, ICProject project) {
69
				result[i] = new IndexTypeInfo(ib.getQualifiedName(), IndexModelUtil.getElementType(ib), index);
107
			super(kinds, types, project);
108
		}
109
		
110
		protected void visitKind(IPDOMNode node, int kind) {
111
			try {
112
				switch (kind) {
113
				case ICElement.C_NAMESPACE:
114
					if (node instanceof ICPPNamespace || node instanceof ICPPNamespaceAlias)
115
						types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
116
					return;
117
				case ICElement.C_CLASS:
118
					if (node instanceof ICPPClassType
119
							&& ((ICPPClassType)node).getKey() == ICPPClassType.k_class)
120
						types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
121
					return;
122
				case ICElement.C_STRUCT:
123
					if (node instanceof ICPPClassType
124
							&& ((ICPPClassType)node).getKey() == ICompositeType.k_struct)
125
						types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
126
					return;
127
				case ICElement.C_UNION:
128
					if (node instanceof ICPPClassType
129
							&& ((ICPPClassType)node).getKey() == ICompositeType.k_union)
130
						types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
131
					return;
132
				case ICElement.C_ENUMERATION:
133
					if (node instanceof IEnumeration
134
							/*&& node instanceof ICPPBinding*/)
135
							types.add(new PDOMTypeInfo((IEnumeration)node, kind, project));
136
					return;
137
				case ICElement.C_TYPEDEF:
138
					return;
139
				}
140
			} catch (DOMException e) {
141
				CCorePlugin.log(e);
142
			}
70
			}
143
		}
71
144
	}
72
			if(DEBUG) {
145
	
73
				System.out.println("Wrapping as ITypeInfo took "+(System.currentTimeMillis() - start)); //$NON-NLS-1$
146
	private static ITypeInfo[] getTypes(ICProject[] projects, int[] kinds) throws CoreException {
74
				start = System.currentTimeMillis();
147
		List types = new ArrayList();
148
		PDOMManager pdomManager = CCoreInternals.getPDOMManager();
149
		
150
		for (int i = 0; i < projects.length; ++i) {
151
			ICProject project = projects[i];
152
			CTypesCollector cCollector = new CTypesCollector(kinds, types, project);
153
			CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types, project);
154
				
155
			PDOM pdom = (PDOM)pdomManager.getPDOM(project);
156
			PDOMLinkage linkage= pdom.getLinkage(ILinkage.C_LINKAGE_ID);
157
			if (linkage != null) {
158
				linkage.accept(cCollector);
159
			}
75
			}
160
			
76
			
161
			linkage= pdom.getLinkage(ILinkage.CPP_LINKAGE_ID);
77
			return result;
162
			if (linkage != null) {
78
		} catch(InterruptedException ie) {
163
				linkage.accept(cppCollector);
79
			ie.printStackTrace();
164
			}
80
		} finally {
81
			index.releaseReadLock();
165
		}
82
		}
166
			
83
		return new ITypeInfo[0];
167
		return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]);
168
	}
84
	}
169
	
85
170
	/**
86
	/**
171
	 * Returns all types in the workspace.
87
	 * Returns all types in the workspace.
172
	 */
88
	 */
173
	public static ITypeInfo[] getAllTypes() {
89
	public static ITypeInfo[] getAllTypes() {
90
		return getAllTypes(new NullProgressMonitor());
91
	}
92
	
93
	/**
94
	 * Returns all types in the workspace.
95
	 */
96
	public static ITypeInfo[] getAllTypes(IProgressMonitor monitor) {
174
		try {
97
		try {
175
			ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
98
			ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
176
			return getTypes(projects, ITypeInfo.KNOWN_TYPES);
99
			return getTypes(projects, ITypeInfo.KNOWN_TYPES, monitor);
177
		} catch (CoreException e) {
100
		} catch (CoreException e) {
178
			CCorePlugin.log(e);
101
			CCorePlugin.log(e);
179
			return new ITypeInfo[0];
102
			return new ITypeInfo[0];
180
		}
103
		}
181
	}
104
	}
182
	
105
183
	/**
106
	/**
184
	 * Returns all types in the given scope.
107
	 * Returns all types in the given scope.
185
	 * 
108
	 * 
Lines 189-201 Link Here
189
	 */
112
	 */
190
	public static ITypeInfo[] getTypes(ITypeSearchScope scope, int[] kinds) {
113
	public static ITypeInfo[] getTypes(ITypeSearchScope scope, int[] kinds) {
191
		try {
114
		try {
192
			return getTypes(scope.getEnclosingProjects(), kinds);
115
			return getTypes(scope.getEnclosingProjects(), kinds, new NullProgressMonitor());
193
		} catch (CoreException e) {
116
		} catch (CoreException e) {
194
			CCorePlugin.log(e);
117
			CCorePlugin.log(e);
195
			return new ITypeInfo[0];
118
			return new ITypeInfo[0];
196
		}
119
		}
197
	}
120
	}
198
	
121
199
	/**
122
	/**
200
	 * Returns all namespaces in the given scope.
123
	 * Returns all namespaces in the given scope.
201
	 * 
124
	 * 
Lines 204-216 Link Here
204
	 */
127
	 */
205
	public static ITypeInfo[] getNamespaces(ITypeSearchScope scope, boolean includeGlobalNamespace) {
128
	public static ITypeInfo[] getNamespaces(ITypeSearchScope scope, boolean includeGlobalNamespace) {
206
		try {
129
		try {
207
			return getTypes(scope.getEnclosingProjects(), new int[] {ICElement.C_NAMESPACE});
130
			return getTypes(scope.getEnclosingProjects(), new int[] {ICElement.C_NAMESPACE}, new NullProgressMonitor());
208
		} catch (CoreException e) {
131
		} catch (CoreException e) {
209
			CCorePlugin.log(e);
132
			CCorePlugin.log(e);
210
			return new ITypeInfo[0];
133
			return new ITypeInfo[0];
211
		}
134
		}
212
	}
135
	}
213
	
136
214
	/** Returns first type in the cache which matches the given
137
	/** Returns first type in the cache which matches the given
215
	 *  type and name.  If no type is found, <code>null</code>
138
	 *  type and name.  If no type is found, <code>null</code>
216
	 *  is returned.
139
	 *  is returned.
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 36-42 Link Here
36
 org.eclipse.cdt.core.settings.model.extension.impl,
36
 org.eclipse.cdt.core.settings.model.extension.impl,
37
 org.eclipse.cdt.core.settings.model.util,
37
 org.eclipse.cdt.core.settings.model.util,
38
 org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
38
 org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
39
 org.eclipse.cdt.internal.core.browser.util;x-internal:=true,
39
 org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
40
 org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
40
 org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
41
 org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
41
 org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
42
 org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
42
 org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
(-)browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * 		QNX - Initial API and implementation
10
 * 		IBM Corporation
11
 *      Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
package org.eclipse.cdt.internal.core.browser.util;
14
15
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.dom.ast.DOMException;
17
import org.eclipse.cdt.core.dom.ast.IBinding;
18
import org.eclipse.cdt.core.dom.ast.ICompositeType;
19
import org.eclipse.cdt.core.dom.ast.IEnumeration;
20
import org.eclipse.cdt.core.dom.ast.ITypedef;
21
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
22
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
23
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
24
import org.eclipse.cdt.core.model.ICElement;
25
26
/**
27
 * Convenience class for bridging the model gap between binding types and CModel types
28
 * 
29
 * This is internal in case some IBinding's do not have ICElement constants in future
30
 */
31
public class IndexModelUtil {
32
	/**
33
	 * Returns whether the binding is of any of the specified CElement type constants
34
	 * @param binding
35
	 * @param kinds
36
	 * @return whether the binding is of any of the specified CElement type constants
37
	 */
38
	public static boolean bindingHasCElementType(IBinding binding, int[] kinds) {
39
		try {
40
			for(int i=0; i<kinds.length; i++) {
41
				switch(kinds[i]) {
42
				case ICElement.C_STRUCT:
43
					if (binding instanceof ICompositeType
44
							&& ((ICompositeType)binding).getKey() == ICompositeType.k_struct)
45
						return true;
46
					break;
47
				case ICElement.C_UNION:
48
					if (binding instanceof ICompositeType
49
							&& ((ICompositeType)binding).getKey() == ICompositeType.k_union)
50
						return true;
51
					break;
52
				case ICElement.C_CLASS:
53
					if (binding instanceof ICompositeType
54
							&& ((ICompositeType)binding).getKey() == ICPPClassType.k_class)
55
						return true;
56
					break;
57
				case ICElement.C_NAMESPACE:
58
					if (binding instanceof ICPPNamespace || binding instanceof ICPPNamespaceAlias)
59
						return true;
60
					break;
61
				case ICElement.C_ENUMERATION:
62
					if (binding instanceof IEnumeration)
63
						return true;
64
					break;
65
				case ICElement.C_TYPEDEF:
66
					if(binding instanceof ITypedef)
67
						return true;
68
					break;
69
				}
70
			}
71
		} catch(DOMException de) {
72
			CCorePlugin.log(de);
73
		}
74
		return false;
75
	}
76
	
77
	/**
78
	 * Returns the CElement type constant for the specified binding
79
	 * @param binding
80
	 * @return the CElement type constant for the specified binding
81
	 */
82
	public static int getElementType(IBinding binding) {
83
		int elementType = Integer.MIN_VALUE;
84
85
		if (binding instanceof ICompositeType) {
86
			ICompositeType classType = (ICompositeType) binding;
87
			try {
88
				if(classType.getKey() == ICPPClassType.k_class) {
89
					elementType = ICElement.C_CLASS;
90
				} else if(classType.getKey() == ICPPClassType.k_struct) {
91
					elementType = ICElement.C_STRUCT;
92
				} else if(classType.getKey() == ICPPClassType.k_union) {
93
					elementType = ICElement.C_UNION;
94
				}
95
			} catch(DOMException de) {
96
				CCorePlugin.log(de);
97
			}
98
		}
99
100
		if (binding instanceof ICPPNamespace || binding instanceof ICPPNamespaceAlias) {
101
			elementType = ICElement.C_NAMESPACE;
102
		}
103
104
		if (binding instanceof IEnumeration) {
105
			elementType = ICElement.C_ENUMERATION; 		
106
		}
107
		return elementType;
108
	}
109
}
(-)browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java (+233 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * 		QNX - Initial API and implementation
10
 * 		IBM Corporation
11
 *      Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
package org.eclipse.cdt.core.browser;
14
15
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.dom.ast.IBinding;
17
import org.eclipse.cdt.core.index.IIndex;
18
import org.eclipse.cdt.core.index.IIndexBinding;
19
import org.eclipse.cdt.core.index.IIndexFileLocation;
20
import org.eclipse.cdt.core.index.IIndexName;
21
import org.eclipse.cdt.core.index.IndexFilter;
22
import org.eclipse.cdt.core.model.ICProject;
23
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
24
import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil;
25
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
26
import org.eclipse.core.filesystem.URIUtil;
27
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IPath;
32
import org.eclipse.core.runtime.NullProgressMonitor;
33
import org.eclipse.core.runtime.Path;
34
35
/**
36
 * @author Doug Schaefer
37
 *
38
 */
39
public class IndexTypeInfo implements ITypeInfo {
40
	private final String[] fqn;
41
	private final int elementType;
42
	private final IIndex index;
43
	private ITypeReference reference; // lazily constructed
44
	
45
	public IndexTypeInfo(String[] fqn, int elementType, IIndex index) {
46
		this.fqn = fqn;
47
		this.elementType = elementType;
48
		this.index = index;
49
	}
50
51
	public void addDerivedReference(ITypeReference location) {
52
		throw new PDOMNotImplementedError();
53
	}
54
55
	public void addReference(ITypeReference location) {
56
		throw new PDOMNotImplementedError();
57
	}
58
59
	public boolean canSubstituteFor(ITypeInfo info) {
60
		throw new PDOMNotImplementedError();
61
	}
62
63
	public boolean encloses(ITypeInfo info) {
64
		throw new PDOMNotImplementedError();
65
	}
66
67
	public boolean exists() {
68
		throw new PDOMNotImplementedError();
69
	}
70
71
	public int getCElementType() {
72
		return elementType;
73
	}
74
75
	public ITypeReference[] getDerivedReferences() {
76
		throw new PDOMNotImplementedError();
77
	}
78
79
	public ITypeInfo[] getEnclosedTypes() {
80
		throw new PDOMNotImplementedError();
81
	}
82
83
	public ITypeInfo[] getEnclosedTypes(int[] kinds) {
84
		throw new PDOMNotImplementedError();
85
	}
86
87
	public ITypeInfo getEnclosingNamespace(boolean includeGlobalNamespace) {
88
		throw new PDOMNotImplementedError();
89
	}
90
91
	public ICProject getEnclosingProject() {
92
		if(getResolvedReference()!=null) {
93
			IProject project = reference.getProject();
94
			if(project!=null) {
95
				return CCorePlugin.getDefault().getCoreModel().getCModel().getCProject(project.getName());
96
			}
97
		}
98
		return null;
99
	}
100
101
	public ITypeInfo getEnclosingType() {
102
		// TODO not sure
103
		return null;
104
	}
105
106
	public ITypeInfo getEnclosingType(int[] kinds) {
107
		throw new PDOMNotImplementedError();
108
	}
109
110
	public String getName() {
111
		return fqn[fqn.length-1];
112
	}
113
114
	public IQualifiedTypeName getQualifiedTypeName() {
115
		return new QualifiedTypeName(fqn);
116
	}
117
118
	public ITypeReference[] getReferences() {
119
		throw new PDOMNotImplementedError();
120
	}
121
122
	public ITypeReference getResolvedReference() {
123
		if(reference==null) {
124
			try {
125
				index.acquireReadLock();
126
127
				char[][] cfqn = new char[fqn.length][];
128
				for(int i=0; i<fqn.length; i++)
129
					cfqn[i] = fqn[i].toCharArray();
130
131
				IIndexBinding[] ibs = index.findBindings(cfqn, new IndexFilter() {
132
					public boolean acceptBinding(IBinding binding) {
133
						return IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
134
					}
135
				}, new NullProgressMonitor());
136
				if(ibs.length>0) {
137
					IIndexName[] names = index.findNames(ibs[0], IIndex.FIND_DEFINITIONS);
138
					if(names.length>0) {
139
						IIndexFileLocation ifl = names[0].getFile().getLocation();
140
						String fullPath = ifl.getFullPath();
141
						if(fullPath!=null) {
142
							IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
143
							if(file!=null) {
144
								reference = new TypeReference(
145
										file, file.getProject(), names[0].getNodeOffset(), names[0].getNodeLength()
146
								);
147
							}
148
						} else {
149
							IPath path = URIUtil.toPath(ifl.getURI());
150
							if(path!=null) {
151
								reference = new TypeReference(
152
										path, null, names[0].getNodeOffset(), names[0].getNodeLength()
153
								);
154
							}
155
						}
156
					}
157
				}
158
			} catch(CoreException ce) {
159
				CCorePlugin.log(ce);				
160
			} catch (InterruptedException ie) {
161
				CCorePlugin.log(ie);
162
			} finally {
163
				index.releaseReadLock();
164
			}
165
		}
166
		return reference;
167
	}
168
169
	public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
170
		throw new PDOMNotImplementedError();
171
	}
172
173
	public ITypeInfo[] getSubTypes() {
174
		throw new PDOMNotImplementedError();
175
	}
176
177
	public ASTAccessVisibility getSuperTypeAccess(ITypeInfo subType) {
178
		throw new PDOMNotImplementedError();
179
	}
180
181
	public ITypeInfo[] getSuperTypes() {
182
		throw new PDOMNotImplementedError();
183
	}
184
185
	public boolean hasEnclosedTypes() {
186
		throw new PDOMNotImplementedError();
187
	}
188
189
	public boolean hasSubTypes() {
190
		throw new PDOMNotImplementedError();
191
	}
192
193
	public boolean hasSuperTypes() {
194
		throw new PDOMNotImplementedError();
195
	}
196
197
	public boolean isClass() {
198
		throw new PDOMNotImplementedError();
199
	}
200
201
	public boolean isEnclosed(ITypeInfo info) {
202
		throw new PDOMNotImplementedError();
203
	}
204
205
	public boolean isEnclosed(ITypeSearchScope scope) {
206
		throw new PDOMNotImplementedError();
207
	}
208
209
	public boolean isEnclosedType() {
210
		throw new PDOMNotImplementedError();
211
	}
212
213
	public boolean isEnclosingType() {
214
		throw new PDOMNotImplementedError();
215
	}
216
217
	public boolean isReferenced(ITypeSearchScope scope) {
218
		throw new PDOMNotImplementedError();
219
	}
220
221
	public boolean isUndefinedType() {
222
		throw new PDOMNotImplementedError();
223
	}
224
225
	public void setCElementType(int type) {
226
		throw new PDOMNotImplementedError();
227
	}
228
229
	public int compareTo(Object arg0) {
230
		throw new PDOMNotImplementedError();
231
	}
232
233
}
(-)browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java (-10 / +1 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     QNX Software Systems - initial API and implementation
9
 *     QNX Software Systems - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.browser.opentype;
12
package org.eclipse.cdt.internal.ui.browser.opentype;
12
13
Lines 23-29 Link Here
23
import org.eclipse.ui.PartInitException;
24
import org.eclipse.ui.PartInitException;
24
import org.eclipse.ui.texteditor.ITextEditor;
25
import org.eclipse.ui.texteditor.ITextEditor;
25
26
26
import org.eclipse.cdt.core.browser.AllTypesCache;
27
import org.eclipse.cdt.core.browser.ITypeInfo;
27
import org.eclipse.cdt.core.browser.ITypeInfo;
28
import org.eclipse.cdt.core.browser.ITypeReference;
28
import org.eclipse.cdt.core.browser.ITypeReference;
29
import org.eclipse.cdt.core.model.CModelException;
29
import org.eclipse.cdt.core.model.CModelException;
Lines 44-59 Link Here
44
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
44
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
45
	 */
45
	 */
46
	public void run(IAction action) {
46
	public void run(IAction action) {
47
		ITypeInfo[] elements = AllTypesCache.getAllTypes();
48
		if (elements.length == 0) {
49
			String title = OpenTypeMessages.getString("OpenTypeAction.notypes.title"); //$NON-NLS-1$
50
			String message = OpenTypeMessages.getString("OpenTypeAction.notypes.message"); //$NON-NLS-1$
51
			MessageDialog.openInformation(getShell(), title, message);
52
			return;
53
		}
54
		
55
		OpenTypeDialog dialog = new OpenTypeDialog(getShell());
47
		OpenTypeDialog dialog = new OpenTypeDialog(getShell());
56
		dialog.setElements(elements);
57
		int result = dialog.open();
48
		int result = dialog.open();
58
		if (result != IDialogConstants.OK_ID)
49
		if (result != IDialogConstants.OK_ID)
59
			return;
50
			return;
(-)browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java (-2 / +99 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-18 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software Systems - adapted for use in CDT
10
 *     QNX Software Systems - adapted for use in CDT
11
 *     Andrew Ferguson (Symbian)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.ui.browser.opentype;
13
package org.eclipse.cdt.internal.ui.browser.opentype;
13
14
14
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Listener;
15
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.Text;
25
26
import org.eclipse.cdt.core.CCorePlugin;
27
import org.eclipse.cdt.core.browser.ITypeInfo;
28
import org.eclipse.cdt.core.browser.IndexTypeInfo;
29
import org.eclipse.cdt.core.dom.ast.DOMException;
30
import org.eclipse.cdt.core.dom.ast.IBinding;
31
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
32
import org.eclipse.cdt.core.index.IIndex;
33
import org.eclipse.cdt.core.index.IndexFilter;
34
import org.eclipse.cdt.core.model.CoreModel;
35
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
36
37
import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil; 
16
38
17
/**
39
/**
18
 * A dialog to select a type from a list of types. The selected type will be
40
 * A dialog to select a type from a list of types. The selected type will be
Lines 31-35 Link Here
31
		setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$
53
		setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$
32
		setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$
54
		setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$
33
		setDialogSettings(DIALOG_SETTINGS);
55
		setDialogSettings(DIALOG_SETTINGS);
56
		
57
	}
58
	
59
60
	char[] toPrefix(String userFilter) {
61
		userFilter= userFilter.trim().replaceAll("^(\\*)*", "");  //$NON-NLS-1$//$NON-NLS-2$
62
		int asterix= userFilter.indexOf("*"); //$NON-NLS-1$
63
		return (asterix==-1 ? userFilter : userFilter.substring(0, asterix)).toCharArray();		
64
	}
65
	
66
	/**
67
	 * Update the list of elements in AbstractElementListSelectionDialog
68
	 * 
69
	 * Filtering on wildcards and types is done by the superclass - we just provide
70
	 * a good starting point
71
	 * @param userFilter
72
	 */
73
	public void update(String userFilter) {
74
		char[] prefix = toPrefix(userFilter);
75
		List types = new ArrayList();
76
		if(prefix.length>0)
77
		try {
78
			IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
79
			try {
80
				index.acquireReadLock();
81
				IBinding[] bindings= index.findBindingsForPrefix(prefix, IndexFilter.ALL, false);
82
				for(int i=0; i<bindings.length; i++) {
83
					IBinding binding = bindings[i];
84
					try {
85
						String[] fqn;
86
87
						if(binding instanceof ICPPBinding) {
88
							fqn= ((ICPPBinding)binding).getQualifiedName();
89
						} else {
90
							fqn = new String[] {binding.getName()};
91
						}
92
						types.add(new IndexTypeInfo(fqn, IndexModelUtil.getElementType(binding), index));
93
					} catch(DOMException de) {
94
95
					}
96
				}
97
			} finally {
98
				index.releaseReadLock();
99
			}
100
		} catch(CoreException ce) {
101
			CCorePlugin.log(ce);
102
		} catch(InterruptedException ie) {
103
			CCorePlugin.log(ie);
104
		}
105
		setListElements(types.toArray(new ITypeInfo[types.size()]));
106
	}
107
	
108
	protected void setListElements(Object[] elements) {
109
		super.setListElements(elements);
110
	}
111
	
112
	/**
113
	 * @deprecated
114
	 */
115
	public void setElements(Object[] elements) {
116
	}
117
	
118
	protected void handleEmptyList() {
119
		// override super-class behaviour with no-op
120
	}
121
	
122
	protected Text createFilterText(Composite parent) {
123
		final Text result = super.createFilterText(parent);
124
		Listener listener = new Listener() {
125
            public void handleEvent(Event e) {
126
                update(result.getText());
127
            }
128
        };
129
        result.addListener(SWT.Modify, listener);
130
        return result;
34
	}
131
	}
35
}
132
}

Return to bug 175151