diff --git a/core/org.eclipse.cdt.ui/.classpath b/core/org.eclipse.cdt.ui/.classpath
index d585f114592..539af0d2b37 100644
--- a/core/org.eclipse.cdt.ui/.classpath
+++ b/core/org.eclipse.cdt.ui/.classpath
@@ -4,5 +4,6 @@
OpenTypeSelectionDialog
.
+ * Constructs an instance of OpenTypeDialog
.
* @param parent the parent shell.
* @param context the context.
- * @param scope the C search scope.
*/
- public OpenTypeSelectionDialog(Shell parent, IRunnableContext context, ICSearchScope scope) {
- super(parent, context, scope);
+ public OpenTypeDialog(Shell parent) {
+ super(parent);
+ setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$
+ setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$
+ //setFilter(OpenTypeMessages.getString("OpenTypeDialog.filter")); //$NON-NLS-1$
+ setMatchEmptyString(true);
}
/*
@@ -117,7 +117,6 @@ public class OpenTypeSelectionDialog extends TypeSelectionDialog {
int width= s.getInt("width"); //$NON-NLS-1$
int height= s.getInt("height"); //$NON-NLS-1$
fSize= new Point(width, height);
-
} catch (NumberFormatException e) {
fLocation= null;
fSize= null;
@@ -129,11 +128,9 @@ public class OpenTypeSelectionDialog extends TypeSelectionDialog {
*/
private void writeSettings() {
IDialogSettings s= getDialogSettings();
-
Point location= getShell().getLocation();
s.put("x", location.x); //$NON-NLS-1$
s.put("y", location.y); //$NON-NLS-1$
-
Point size= getShell().getSize();
s.put("width", size.x); //$NON-NLS-1$
s.put("height", size.y); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeMessages.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java
similarity index 89%
rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeMessages.java
rename to core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java
index 42da2ed1238..2a98050f427 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeMessages.java
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.java
@@ -8,15 +8,18 @@
* Contributors:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.ui.opentype;
+package org.eclipse.cdt.internal.ui.browser.opentype;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+/**
+ * OpenTypeMessages
+ */
public class OpenTypeMessages {
- private static final String RESOURCE_BUNDLE= "org.eclipse.cdt.internal.ui.opentype.OpenTypeMessages";//$NON-NLS-1$
+ private static final String RESOURCE_BUNDLE= OpenTypeMessages.class.getName();
private static ResourceBundle fgResourceBundle;
static {
@@ -47,5 +50,5 @@ public class OpenTypeMessages {
public static String getFormattedString(String key, String[] args) {
return MessageFormat.format(getString(key), args);
}
-
+
}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.properties b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.properties
new file mode 100644
index 00000000000..c7cfee12801
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeMessages.properties
@@ -0,0 +1,26 @@
+###############################################################################
+# Copyright (c) 2004 QNX Software Systems Ltd. and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v0.5
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v05.html
+#
+# Contributors:
+# QNX Software Systems - Initial API and implementation
+###############################################################################
+
+OpenTypeAction.exception.title=Exception
+OpenTypeAction.exception.message=Unexpected exception. See log for details.
+OpenTypeAction.notypes.title=Type Selection
+OpenTypeAction.notypes.message=No types available.
+
+OpenTypeAction.description=Open a type in the editor
+OpenTypeAction.tooltip=Open a Type
+OpenTypeAction.label=Open Type...
+OpenTypeAction.errorTitle=Open Type
+OpenTypeAction.errorMessage=Could not uniquely map the type name to a type. Path is {0}
+OpenTypeAction.errorNoPath=Unknown
+
+OpenTypeDialog.title=Open Type
+OpenTypeDialog.message=&Choose a type (? = any character, * = any string):
+OpenTypeDialog.filter=
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/util/ArrayUtil.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/util/ArrayUtil.java
new file mode 100644
index 00000000000..fb8e356999a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/util/ArrayUtil.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.util;
+
+/**
+ * A helper class which allows you to perform some
+ * simple set operations on int arrays.
+ */
+public class ArrayUtil {
+ private ArrayUtil() {
+ }
+
+ // returns true if set contains elem
+ public static boolean contains(int[] set, int elem) {
+ for (int i= 0; i < set.length; ++i) {
+ if (set[i] == elem)
+ return true;
+ }
+ return false;
+ }
+
+ // returns true if set contains all of subset
+ public static boolean containsAll(int[] set, int[] subset) {
+ for (int i= 0; i < subset.length; ++i) {
+ if (!contains(set, subset[i]))
+ return false;
+ }
+ return true;
+ }
+
+ // return a copy of fromSet
+ public static int[] clone(int[] fromSet) {
+ int[] newSet= new int[fromSet.length];
+ for (int i= 0; i < fromSet.length; ++i) {
+ newSet[i]= newSet[i];
+ }
+ return newSet;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/util/ProgressMonitorMultiWrapper.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/util/ProgressMonitorMultiWrapper.java
new file mode 100644
index 00000000000..ddad94f7038
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/util/ProgressMonitorMultiWrapper.java
@@ -0,0 +1,233 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.util;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IProgressMonitorWithBlocking;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * A wrapper around multiple progress monitors which forwards
+ * IProgressMonitor
and IProgressMonitorWithBlocking
+ * methods to the wrapped progress monitors.
+ */
+public class ProgressMonitorMultiWrapper implements IProgressMonitor, IProgressMonitorWithBlocking {
+
+ private double internalWork;
+ private int totalWork;
+ private int work;
+ private String taskName;
+ private String subtaskName;
+ private boolean isCanceled= false;
+ private boolean blocked= false;
+
+ /** The wrapped progress monitors. */
+ private final ArrayList fProgressMonitors= new ArrayList(2);
+
+ /**
+ * Creates a new monitor wrapper.
+ */
+ public ProgressMonitorMultiWrapper() {
+ }
+
+ /**
+ * Creates a new monitor wrapper around the given monitor.
+ */
+ public ProgressMonitorMultiWrapper(IProgressMonitor monitor) {
+ addProgressMonitor(monitor);
+ }
+
+ /*
+ * @see IProgressMonitor#beginTask
+ */
+ public void beginTask(String name, int totalWork) {
+ taskName= name;
+ this.totalWork= totalWork;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.beginTask(name, totalWork);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#setTaskName
+ */
+ public void setTaskName(String name) {
+ taskName= name;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.setTaskName(name);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#subTask
+ */
+ public void subTask(String name) {
+ subtaskName= name;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.subTask(name);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#worked
+ */
+ public void worked(int work) {
+ this.work= work;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.worked(work);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#internalWorked
+ */
+ public void internalWorked(double work) {
+ internalWork= work;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.internalWorked(work);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#done
+ */
+ public void done() {
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.done();
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#setCanceled
+ */
+ public void setCanceled(boolean canceled) {
+ isCanceled= canceled;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ monitor.setCanceled(canceled);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#isCanceled
+ */
+ public boolean isCanceled() {
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ isCanceled |= monitor.isCanceled();
+ }
+ return isCanceled;
+ }
+
+ /*
+ * @see IProgressMonitor#setBlocked
+ */
+ public void setBlocked(IStatus reason) {
+ blocked= true;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ if (monitor instanceof IProgressMonitorWithBlocking)
+ ((IProgressMonitorWithBlocking) monitor).setBlocked(reason);
+ }
+ }
+
+ /*
+ * @see IProgressMonitor#clearBlocked
+ */
+ public void clearBlocked() {
+ blocked= false;
+
+ // Clone the monitors since they could remove themselves when called
+ ArrayList monitors= (ArrayList) fProgressMonitors.clone();
+ for (int i= 0; i < monitors.size(); i++) {
+ IProgressMonitor monitor= (IProgressMonitor) monitors.get(i);
+ if (monitor instanceof IProgressMonitorWithBlocking)
+ ((IProgressMonitorWithBlocking) monitor).clearBlocked();
+ }
+ }
+
+ /*
+ * brings monitor up to date
+ */
+ private void syncUpMonitor(IProgressMonitor monitor) {
+ if (totalWork > 0) {
+ monitor.beginTask(taskName, totalWork);
+ monitor.worked(work);
+ monitor.internalWorked(internalWork);
+ if (subtaskName != null && subtaskName.length() > 0)
+ monitor.subTask(subtaskName);
+ if (blocked && monitor instanceof IProgressMonitorWithBlocking)
+ ((IProgressMonitorWithBlocking) monitor).setBlocked(null);
+ }
+ }
+
+ /**
+ * Adds a monitor to the list of wrapped monitors.
+ */
+ public synchronized void addProgressMonitor(IProgressMonitor monitor) {
+ if (fProgressMonitors.indexOf(monitor) == -1) {
+ syncUpMonitor(monitor);
+ fProgressMonitors.add(monitor);
+ }
+ }
+
+ /**
+ * Removes a monitor from the list of wrapped monitors.
+ */
+ public synchronized void removeProgressMonitor(IProgressMonitor monitor) {
+ int index = fProgressMonitors.indexOf(monitor);
+ if (index != -1) {
+ fProgressMonitors.remove(index);
+ }
+ }
+
+ /**
+ * Returns the wrapped progress monitors.
+ *
+ * @return the wrapped progress monitors
+ */
+ public IProgressMonitor[] getWrappedProgressMonitors() {
+ return (IProgressMonitor[]) fProgressMonitors.toArray();
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java
new file mode 100644
index 00000000000..5684db06e55
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java
@@ -0,0 +1,476 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * QNX Software Systems - adapted for use in CDT
+ *******************************************************************************/
+package org.eclipse.cdt.ui.browser.typeinfo;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ElementChangedEvent;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.IElementChangedListener;
+import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
+import org.eclipse.cdt.core.search.BasicSearchResultCollector;
+import org.eclipse.cdt.core.search.ICSearchConstants;
+import org.eclipse.cdt.core.search.ICSearchPattern;
+import org.eclipse.cdt.core.search.ICSearchScope;
+import org.eclipse.cdt.core.search.IMatch;
+import org.eclipse.cdt.core.search.OrPattern;
+import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil;
+import org.eclipse.cdt.internal.ui.browser.util.ProgressMonitorMultiWrapper;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * Manages a search cache for types in the workspace. Instead of returning objects of type ICElement
+ * the methods of this class returns a list of the lightweight objects TypeInfo
.
+ *
+ * AllTypesCache runs asynchronously using a background job to rebuild the cache as needed. + * If the cache becomes dirty again while the background job is running, the job is restarted. + *
+ * If getAllTypes
is called in response to a user action, a progress dialog is shown.
+ * If called before the background job has finished, getAllTypes waits
+ * for the completion of the background job.
+ */
+public class AllTypesCache {
+
+ /**
+ * Background job for filling the type cache.
+ * @see org.eclipse.core.runtime.jobs.Job
+ * @since 3.0
+ */
+ private static class TypeCacherJob extends Job {
+
+ /**
+ * An "identity rule" that forces jobs to be queued.
+ * @see org.eclipse.core.runtime.jobs.ISchedulingRule
+ * @since 3.0
+ */
+ final static ISchedulingRule MUTEX_RULE= new ISchedulingRule() {
+ public boolean contains(ISchedulingRule rule) {
+ return rule == this;
+ }
+ public boolean isConflicting(ISchedulingRule rule) {
+ return rule == this;
+ }
+ };
+
+ /**
+ * A comparator for simple type names
+ */
+ private static class TypeNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ return ((TypeInfo)o1).getName().compareTo(((TypeInfo)o2).getName());
+ }
+ }
+
+ /**
+ * A search result collector for type info.
+ * @see org.eclipse.cdt.core.search.ICSearchResultCollector
+ */
+ private static class TypeSearchResultCollector extends BasicSearchResultCollector {
+
+ public TypeSearchResultCollector() {
+ super();
+ }
+
+ public TypeSearchResultCollector(IProgressMonitor monitor) {
+ super(monitor);
+ }
+
+ public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node )
+ {
+ TypeInfo result= new TypeInfo();
+ return super.createMatch( result, fileResource, start, end, node );
+ }
+
+ public boolean acceptMatch(IMatch match) throws CoreException {
+ // filter out unnamed structs
+ TypeInfo result= (TypeInfo) match;
+ String name= result.getName();
+ if (name == null || name.length() == 0)
+ return false;
+
+ // make sure we've got a valid type
+ if (!TypeInfo.isValidCElementType(result.getElementType()))
+ return false;
+
+ return super.acceptMatch(match);
+ }
+ }
+
+ /**
+ * Constant identifying the job family identifier for the background job.
+ * @see IJobManager#join(Object, IProgressMonitor)
+ * @since 3.0
+ */
+ public static final Object FAMILY= new Object();
+
+ final static Comparator TYPE_COMPARATOR= new TypeNameComparator();
+
+ private ProgressMonitorMultiWrapper progressMonitor;
+
+ public TypeCacherJob() {
+ super(TypeInfoMessages.getString("TypeCacherJob.jobName")); //$NON-NLS-1$
+ setPriority(BUILD);
+ setSystem(true);
+ //setRule(MUTEX_RULE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.internal.jobs.InternalJob#belongsTo(java.lang.Object)
+ */
+ public boolean belongsTo(Object family) {
+ return family == FAMILY;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#shouldRun()
+ */
+ public boolean shouldRun() {
+ return isCacheDirty();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(IProgressMonitor)
+ */
+ public IStatus run(IProgressMonitor monitor) {
+ progressMonitor= new ProgressMonitorMultiWrapper(monitor);
+ progressMonitor.beginTask(TypeInfoMessages.getString("TypeCacherJob.taskName"), 100); //$NON-NLS-1$
+
+ SubProgressMonitor subMonitor= new SubProgressMonitor(progressMonitor, 100);
+ TypeSearchResultCollector collector= new TypeSearchResultCollector(subMonitor);
+
+ IWorkspace workspace= CCorePlugin.getWorkspace();
+ ICSearchScope scope= SearchEngine.createWorkspaceScope();
+ SearchEngine engine= new SearchEngine();
+
+ ICSearchPattern pattern= createSearchPattern();
+ try {
+ flushCache();
+ // start the search engine
+ engine.search(workspace, pattern, scope, collector, true);
+ if (progressMonitor.isCanceled())
+ throw new InterruptedException();
+ progressMonitor.done();
+ } catch(InterruptedException ex) {
+ return Status.CANCEL_STATUS;
+ } finally {
+ progressMonitor= null;
+ }
+
+ Set searchResults= collector.getSearchResults();
+
+ if (searchResults != null) {
+ TypeInfo[] result= (TypeInfo[]) searchResults.toArray(new TypeInfo[searchResults.size()]);
+ Arrays.sort(result, TYPE_COMPARATOR);
+ setCache(result);
+ }
+ else {
+ TypeInfo[] result= new TypeInfo[0];
+ setCache(result);
+ }
+ return Status.OK_STATUS;
+ }
+
+ /*
+ * creates a search pattern based on the cache types
+ */
+ private ICSearchPattern createSearchPattern() {
+ OrPattern pattern= new OrPattern();
+ int[] types= getCacheTypes();
+ for (int i= 0; i < types.length; ++i) {
+ switch (types[i]) {
+ case ICElement.C_NAMESPACE:
+ pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, false));
+ break;
+
+ case ICElement.C_CLASS: // fall through
+ case ICElement.C_TEMPLATE_CLASS:
+ pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.CLASS, ICSearchConstants.DECLARATIONS, false));
+ break;
+
+ case ICElement.C_STRUCT: // fall through
+ case ICElement.C_TEMPLATE_STRUCT:
+ pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.STRUCT, ICSearchConstants.DECLARATIONS, false));
+ break;
+
+ case ICElement.C_UNION: // fall through
+ case ICElement.C_TEMPLATE_UNION:
+ pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.UNION, ICSearchConstants.DECLARATIONS, false));
+ break;
+
+ case ICElement.C_ENUMERATION:
+ pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false));
+ break;
+
+ case ICElement.C_TYPEDEF:
+ pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, false));
+ break;
+
+ default:
+ break;
+ }
+ }
+ return pattern;
+ }
+
+ /**
+ * Forwards progress info to the progress monitor and
+ * blocks until the job is finished.
+ *
+ * @param monitor Optional progress monitor.
+ * @throws InterruptedException
+ *
+ * @see Job#join
+ */
+ public void join(IProgressMonitor monitor) throws InterruptedException {
+ if (progressMonitor != null)
+ progressMonitor.addProgressMonitor(monitor);
+ super.join();
+ }
+ }
+
+ /**
+ * Listener for changes to CModel.
+ * @see org.eclipse.cdt.core.model.IElementChangedListener
+ * @since 3.0
+ */
+ private static class TypeCacheDeltaListener implements IElementChangedListener {
+ /*
+ * @see IElementChangedListener#elementChanged
+ */
+ public void elementChanged(ElementChangedEvent event) {
+ //TODO optimization: calculate deltas per file and
+ // update the cache selectively
+ boolean needsFlushing= processDelta(event.getDelta());
+ if (needsFlushing) {
+ // mark cache as dirty and reschedule the
+ // background job
+ setCacheDirty();
+ if (fgJob.getState() == Job.RUNNING)
+ fgJob.cancel();
+ fgJob.setPriority(Job.BUILD);
+ fgJob.schedule();
+ }
+ }
+
+ /*
+ * returns true if the cache needs to be flushed
+ */
+ private boolean processDelta(ICElementDelta delta) {
+ ICElement elem= delta.getElement();
+ int pathEntryChanged= ICElementDelta.F_ADDED_PATHENTRY_SOURCE | ICElementDelta.F_REMOVED_PATHENTRY_SOURCE |
+ ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE | ICElementDelta.F_CHANGED_PATHENTRY_MACRO;
+ boolean isAddedOrRemoved= (delta.getKind() != ICElementDelta.CHANGED)
+ || ((delta.getFlags() & pathEntryChanged) != 0);
+
+ switch (elem.getElementType()) {
+ case ICElement.C_MODEL:
+ case ICElement.C_PROJECT:
+ case ICElement.C_CCONTAINER:
+ case ICElement.C_NAMESPACE:
+ case ICElement.C_TEMPLATE_CLASS:
+ case ICElement.C_CLASS:
+ case ICElement.C_STRUCT:
+ case ICElement.C_UNION:
+ case ICElement.C_ENUMERATION:
+ case ICElement.C_TYPEDEF:
+ case ICElement.C_INCLUDE:
+ case ICElement.C_UNIT:
+ if (isAddedOrRemoved) {
+ return true;
+ }
+ return processChildrenDelta(delta);
+ default:
+ // fields, methods, imports ect
+ return false;
+ }
+ }
+
+ private boolean isPossibleStructuralChange(int flags) {
+ return (flags & (ICElementDelta.F_CONTENT | ICElementDelta.F_FINE_GRAINED)) == ICElementDelta.F_CONTENT;
+ }
+
+ private boolean processChildrenDelta(ICElementDelta delta) {
+ ICElementDelta[] children= delta.getAffectedChildren();
+ for (int i= 0; i < children.length; i++) {
+ if (processDelta(children[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ private static final int INITIAL_DELAY= 5000;
+ private static final TypeCacherJob fgJob= new TypeCacherJob();
+ private static final TypeCacheDeltaListener fgDeltaListener= new TypeCacheDeltaListener();
+ private static int[] fgCacheTypes= TypeInfo.getAllCElementTypes();
+ private static TypeInfo[] fgCacheData;
+ private static int fgNumberOfCacheFlushes;
+ private static boolean cacheIsDirty= true;
+
+ /**
+ * Initializes the AllTypesCache service.
+ */
+ public static void initialize() {
+ // add delta listener
+ CoreModel.getDefault().addElementChangedListener(fgDeltaListener);
+
+ // schedule job to run after INITIAL_DELAY
+ if (fgJob.getState() != Job.RUNNING) {
+ fgJob.setPriority(Job.BUILD);
+ fgJob.schedule(INITIAL_DELAY);
+ }
+ }
+
+ /**
+ * Terminates the service provided by AllTypesCache.
+ */
+ public static void terminate() {
+ // remove delta listener
+ CoreModel.getDefault().removeElementChangedListener(fgDeltaListener);
+
+ // terminate background job
+ fgJob.cancel();
+ }
+
+ /*
+ * Sets the cache contents.
+ */
+ private static synchronized void setCache(TypeInfo[] cache) {
+ fgCacheData= cache;
+ cacheIsDirty= false;
+ }
+
+ /*
+ * Gets the cache contents.
+ */
+ private static synchronized TypeInfo[] getCache() {
+ return fgCacheData;
+ }
+
+ /*
+ * Clears the cache.
+ */
+ private static synchronized void flushCache() {
+ fgCacheData= null;
+ ++fgNumberOfCacheFlushes;
+ cacheIsDirty= true;
+ }
+
+ /*
+ * Marks cache as dirty.
+ */
+ private static synchronized void setCacheDirty() {
+ cacheIsDirty= true;
+ }
+
+ /*
+ * Tests if cache is dirty.
+ */
+ private static synchronized boolean isCacheDirty() {
+ return cacheIsDirty;
+ }
+
+ /*
+ * Sets which types are stored in the cache.
+ */
+ private static synchronized void setCacheTypes(int[] cElementTypes) {
+ fgCacheTypes= ArrayUtil.clone(cElementTypes);
+ }
+
+ /*
+ * Gets types stored in the cache.
+ */
+ private static synchronized int[] getCacheTypes() {
+ return fgCacheTypes;
+ }
+
+ /**
+ * Returns all types in the given scope, matching the given filter.
+ * @param filter Filter for the type info.
+ * @param monitor Progress monitor.
+ * @param typesFound The resulting TypeInfo
elements are added to this collection
+ */
+ public static void getTypes(ICSearchScope scope, ITypeInfoFilter filter, IProgressMonitor monitor, Collection typesFound) {
+ TypeInfo[] allTypes= getAllTypes(filter, monitor);
+ if (allTypes != null) {
+ boolean isWorkspaceScope= scope.equals(SearchEngine.createWorkspaceScope());
+ for (int i= 0; i < allTypes.length; i++) {
+ TypeInfo info= allTypes[i];
+ if (isWorkspaceScope || info.isEnclosed(scope)) {
+ if (filter.match(info))
+ typesFound.add(info);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns all types in the workspace. The returned array must not be
+ * modified. The elements in the array are sorted by simple type name.
+ */
+ public static TypeInfo[] getAllTypes(ITypeInfoFilter filter, IProgressMonitor monitor) {
+
+ // check if requested types are in cache
+ if (!ArrayUtil.containsAll(getCacheTypes(), filter.getCElementTypes()))
+ {
+ // mark cache dirty and cancel the running job
+ setCacheDirty();
+ if (fgJob.getState() == Job.RUNNING)
+ fgJob.cancel();
+ setCacheTypes(filter.getCElementTypes());
+ }
+
+ if (isCacheDirty()) {
+ // start job if not already running
+ if (fgJob.getState() != Job.RUNNING) {
+ // boost priority since action was user-initiated
+ fgJob.setPriority(Job.SHORT);
+ fgJob.schedule();
+ }
+
+ // wait for job to finish
+ try {
+ fgJob.join(monitor);
+ if (monitor != null)
+ monitor.done();
+ } catch (InterruptedException ex) {
+ return null;
+ }
+ }
+ return getCache();
+ }
+
+ /**
+ * Returns true if the type cache is up to date.
+ */
+ public static boolean isCacheUpToDate(ITypeInfoFilter filter) {
+ // check if requested types are in cache
+ if (!ArrayUtil.containsAll(getCacheTypes(), filter.getCElementTypes()))
+ return false;
+ return !isCacheDirty();
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfo.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfo.java
new file mode 100644
index 00000000000..2621ab982a4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfo.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.typeinfo;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.search.ICSearchScope;
+import org.eclipse.cdt.core.search.IMatch;
+
+/**
+ * Type information.
+ */
+public interface ITypeInfo extends IMatch {
+
+ /**
+ * Returns true if type is enclosed in the given scope
+ */
+ public boolean isEnclosed(ICSearchScope scope);
+
+ /**
+ * Returns true if the type is a low-level system type.
+ * e.g. __FILE
+ */
+ public boolean isSystemType();
+
+ /**
+ * Gets the enclosing type names.
+ */
+ public String[] getEnclosingNames();
+
+ /**
+ * Gets the filename where this type is located.
+ */
+ public String getFileName();
+
+ /**
+ * Gets the file path where this type is located.
+ */
+ public String getFilePath();
+
+ /**
+ * Gets the extension of the file where this type is located.
+ */
+ public String getFileExtension();
+
+ /**
+ * Gets the type qualified name: Includes enclosing type names, but
+ * not filename. Identifiers are separated by colons.
+ */
+ public String getQualifiedName();
+
+ /**
+ * Gets the fully qualified type container name: Filename or
+ * enclosing type name with filename.
+ * All identifiers are separated by colons.
+ */
+ public String getQualifiedParentName();
+
+ /**
+ * Gets the fully qualified type name: Includes enclosing type names and
+ * filename. All identifiers are separated by colons.
+ */
+ public String getFullyQualifiedName();
+
+ /**
+ * Gets the CElement which corresponds to this type.
+ */
+ public ICElement getCElement();
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfoFilter.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfoFilter.java
new file mode 100644
index 00000000000..e4895d22ab7
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfoFilter.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.typeinfo;
+
+/**
+ * Filter for type info.
+ */
+public interface ITypeInfoFilter {
+
+ /**
+ * Gets the C types handled by this filter.
+ *
+ * @return An array of ICElement types.
+ *
+ */
+ public int[] getCElementTypes();
+
+ /**
+ * Matches type info against filter.
+ *
+ * @param info The object to filter.
+ * @return true
if successful match.
+ */
+ public boolean match(ITypeInfo info);
+ /**
+ * Returns true
if info
matches the filter.
+ */
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfo.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfo.java
new file mode 100644
index 00000000000..1bd7d00848d
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfo.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.typeinfo;
+
+import java.util.ArrayList;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IParent;
+import org.eclipse.cdt.core.search.BasicSearchMatch;
+import org.eclipse.cdt.core.search.ICSearchScope;
+import org.eclipse.cdt.internal.core.index.StringMatcher;
+import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+
+
+/**
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TypeInfo extends BasicSearchMatch implements ITypeInfo
+{
+ private final static int[] cElementTypes= {
+ ICElement.C_NAMESPACE,
+ ICElement.C_CLASS,
+ ICElement.C_TEMPLATE_CLASS,
+ ICElement.C_STRUCT,
+ ICElement.C_TEMPLATE_STRUCT,
+ ICElement.C_UNION,
+ ICElement.C_TEMPLATE_UNION,
+ ICElement.C_ENUMERATION,
+ ICElement.C_TYPEDEF
+ };
+
+ public static int[] getAllCElementTypes() {
+ return cElementTypes;
+ }
+
+ public static boolean isValidCElementType(int type) {
+ return ArrayUtil.contains(cElementTypes, type);
+ }
+
+ private final static String scopeResolutionOperator= "::"; //$NON-NLS-1$
+ private final static String fileScopeSeparator= " : "; //$NON-NLS-1$
+ private static final StringMatcher fSystemTypeMatcher= new StringMatcher("_*", true, false); //$NON-NLS-1$
+
+ public TypeInfo() {
+ super();
+ }
+
+ public boolean isEnclosed(ICSearchScope scope) {
+ return scope.encloses(getFilePath());
+ }
+
+ public boolean isSystemType() {
+ // recognized low-level system types eg __FILE
+ String[] names= getEnclosingNames();
+ if (names != null) {
+ for (int i= 0; i < names.length; ++i) {
+ if (fSystemTypeMatcher.match(names[i]))
+ return true;
+ }
+ }
+ return fSystemTypeMatcher.match(getName());
+ }
+
+ public String getFileName() {
+ if (resource != null)
+ return resource.getName();
+ else if (path != null)
+ return path.lastSegment();
+ else
+ return null;
+ }
+
+ public String getFilePath() {
+ if (resource != null)
+ return resource.getFullPath().toString();
+ else if (path != null)
+ return path.toString();
+ else
+ return null;
+ }
+
+ public String getFileExtension() {
+ if (resource != null)
+ return resource.getFileExtension();
+ else if (path != null)
+ return path.getFileExtension();
+ else
+ return null;
+ }
+
+ public String getQualifiedParentName() {
+ StringBuffer buf= new StringBuffer();
+ String fileName = getFileName();
+ if (fileName != null && fileName.length() > 0)
+ buf.append(fileName);
+ String parentName = getParentName();
+ if (parentName != null && parentName.length() > 0) {
+ buf.append(fileScopeSeparator); //$NON-NLS-1$
+ buf.append(parentName);
+ }
+ return buf.toString();
+ }
+
+ public String getFullyQualifiedName() {
+ StringBuffer buf= new StringBuffer();
+ String fileName = getFileName();
+ if (fileName != null && fileName.length() > 0)
+ buf.append(fileName);
+ String parentName = getParentName();
+ if (parentName != null && parentName.length() > 0) {
+ buf.append(fileScopeSeparator); //$NON-NLS-1$
+ buf.append(parentName);
+ buf.append(scopeResolutionOperator); //$NON-NLS-1$
+ }
+ String name = getName();
+ if (name != null && name.length() > 0)
+ buf.append(name);
+ return buf.toString();
+ }
+
+ public String getQualifiedName() {
+ StringBuffer buf= new StringBuffer();
+ String parentName = getParentName();
+ if (parentName != null && parentName.length() > 0) {
+ buf.append(parentName);
+ buf.append(scopeResolutionOperator); //$NON-NLS-1$
+ }
+ String name = getName();
+ if (name != null && name.length() > 0)
+ buf.append(name);
+ return buf.toString();
+ }
+
+ public String[] getEnclosingNames() {
+ //TODO pull up this method into BasicSearchMatch
+ //since it already has access to this info
+ String parentName= getParentName();
+ if (parentName == null)
+ return null;
+
+ ArrayList names= new ArrayList(5);
+ int lastIndex= 0;
+ String nextName;
+ int qualifierIndex= parentName.indexOf(scopeResolutionOperator, 0);
+ while (qualifierIndex >= 0) {
+ nextName= parentName.substring(lastIndex, qualifierIndex);
+ lastIndex= qualifierIndex + scopeResolutionOperator.length();
+ names.add(nextName);
+ qualifierIndex= parentName.indexOf(scopeResolutionOperator, lastIndex);
+ }
+ nextName= parentName.substring(lastIndex);
+ names.add(nextName);
+
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ public String toString() {
+ return getFullyQualifiedName();
+ }
+
+ private boolean matchesCType(ICElement celement, String name) {
+ if (isValidCElementType(celement.getElementType()))
+ return celement.getElementName().equals(name);
+ return false;
+ }
+
+ private ICElement findCElement(ICElement celement, String name) {
+ if (matchesCType(celement, name))
+ return celement;
+ else if (celement instanceof IParent) {
+ ICElement[] children = ((IParent)celement).getChildren();
+ for (int i = 0; i < children.length; i++) {
+ if (matchesCType(children[i], name))
+ return children[i];
+ }
+ }
+ return null;
+ }
+
+ public ICElement getCElement() {
+ if (resource != null && resource.getType() == IResource.FILE) {
+ ICElement parentElement= CoreModel.getDefault().create((IFile)resource);
+ if (parentElement instanceof IParent) {
+ String[] names= getEnclosingNames();
+ if (names != null) {
+ for (int i= 0; i < names.length; ++i) {
+ parentElement= findCElement(parentElement, names[i]);
+ if (parentElement == null)
+ break;
+ }
+ }
+ if (parentElement != null)
+ return findCElement(parentElement, getName());
+ }
+ }
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoFilter.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoFilter.java
new file mode 100644
index 00000000000..81a24f9209b
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoFilter.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.typeinfo;
+
+import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil;
+
+/**
+ * The default type filter.
+ */
+public class TypeInfoFilter implements ITypeInfoFilter {
+
+ public int[] getCElementTypes() {
+ return TypeInfo.getAllCElementTypes();
+ }
+
+ public TypeInfoFilter() {
+ }
+
+ protected boolean hideSystemTypes() {
+ return true;
+ }
+
+ public boolean match(ITypeInfo info) {
+ // check if type is handled
+ if (!ArrayUtil.contains(getCElementTypes(), info.getElementType()))
+ return false;
+
+ // filter out low-level system types eg __FILE
+ //TODO make this a preferences option
+ if (hideSystemTypes() && info.isSystemType())
+ return false;
+
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java
similarity index 86%
rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java
rename to core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java
index 8465e13af6a..12a69c9f0fc 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000,2003,2004 IBM Corporation and others.
+ * Copyright (c) 2004 IBM Corporation 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
* QNX Software Systems - adapted for use in CDT
*******************************************************************************/
-package org.eclipse.cdt.internal.ui.opentype;
+package org.eclipse.cdt.ui.browser.typeinfo;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
@@ -17,9 +17,7 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
-
-
-public class TypeSearchMatchLabelProvider extends LabelProvider {
+public class TypeInfoLabelProvider extends LabelProvider {
public static final int SHOW_FULLYQUALIFIED= 0x01;
public static final int SHOW_FILENAME_POSTFIX= 0x02;
@@ -40,7 +38,7 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
private int fFlags;
- public TypeSearchMatchLabelProvider(int flags) {
+ public TypeInfoLabelProvider(int flags) {
fFlags= flags;
}
@@ -52,10 +50,10 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
* @see ILabelProvider#getText
*/
public String getText(Object element) {
- if (! (element instanceof TypeSearchMatch))
+ if (! (element instanceof ITypeInfo))
return super.getText(element);
- TypeSearchMatch typeRef= (TypeSearchMatch) element;
+ ITypeInfo typeRef= (ITypeInfo) element;
StringBuffer buf= new StringBuffer();
if (isSet(SHOW_TYPE_ONLY)) {
@@ -85,7 +83,7 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
if (isSet(SHOW_FILENAME_POSTFIX)) {
String name= typeRef.getFileName();
if (name != null && name.length() > 0) {
- buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash")); //$NON-NLS-1$
+ buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.dash")); //$NON-NLS-1$
buf.append(name);
}
}
@@ -94,14 +92,14 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
if (isSet(SHOW_ROOT_POSTFIX)) {
String path= typeRef.getFilePath();
if (path != null && path.length() > 0) {
- buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$
+ buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$
buf.append(path);
}
}
return buf.toString();
}
- private Image getFileIcon(TypeSearchMatch typeRef)
+ private Image getFileIcon(ITypeInfo typeRef)
{
String ext = typeRef.getFileExtension();
if (ext != null) {
@@ -115,9 +113,9 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
return SOURCE_ICON;
}
- private Image getIcon(TypeSearchMatch typeRef)
+ private Image getIcon(ITypeInfo typeRef)
{
- switch (typeRef.getType())
+ switch (typeRef.getElementType())
{
case ICElement.C_NAMESPACE:
return NAMESPACE_ICON;
@@ -149,10 +147,10 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
* @see ILabelProvider#getImage
*/
public Image getImage(Object element) {
- if (!(element instanceof TypeSearchMatch))
+ if (!(element instanceof ITypeInfo))
return super.getImage(element);
- TypeSearchMatch typeRef= (TypeSearchMatch) element;
+ ITypeInfo typeRef= (ITypeInfo) element;
if (isSet(SHOW_TYPE_CONTAINER_ONLY)) {
return getFileIcon(typeRef);
} else if (isSet(SHOW_FILENAME_ONLY)) {
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java
new file mode 100644
index 00000000000..3dc7b568cfc
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 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.browser.typeinfo;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class TypeInfoMessages {
+
+ private static final String RESOURCE_BUNDLE= TypeInfoMessages.class.getName();
+
+ private static ResourceBundle fgResourceBundle;
+ static {
+ try {
+ fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
+ } catch (MissingResourceException x) {
+ fgResourceBundle = null;
+ }
+ }
+
+ private TypeInfoMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ } catch (NullPointerException e) {
+ return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public static String getFormattedString(String key, String arg) {
+ return getFormattedString(key, new String[] { arg });
+ }
+
+ public static String getFormattedString(String key, String[] args) {
+ return MessageFormat.format(getString(key), args);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties
new file mode 100644
index 00000000000..544dfe5a680
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties
@@ -0,0 +1,19 @@
+###############################################################################
+# Copyright (c) 2004 QNX Software Systems Ltd. and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v0.5
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v05.html
+#
+# Contributors:
+# QNX Software Systems - Initial API and implementation
+###############################################################################
+
+TypeCacherJob.jobName=TypeCache
+TypeCacherJob.taskName=Updating Type Info...
+
+TypeSelectionDialog.lowerLabel=&Qualifier:
+TypeSelectionDialog.upperLabel=&Matching types:
+
+TypeInfoLabelProvider.default_filename=default
+TypeInfoLabelProvider.dash=\ -
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java
new file mode 100644
index 00000000000..f9a1bf36c73
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * QNX Software Systems - adapted for use in CDT
+ *******************************************************************************/
+package org.eclipse.cdt.ui.browser.typeinfo;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.cdt.internal.ui.util.StringMatcher;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.FilteredList;
+import org.eclipse.ui.dialogs.TwoPaneElementSelector;
+
+
+/**
+ * A dialog to select a type from a list of types.
+ */
+public class TypeSelectionDialog extends TwoPaneElementSelector {
+
+ private static class TypeFilterMatcher implements FilteredList.FilterMatcher {
+
+ private static final char END_SYMBOL= '<';
+ private static final char ANY_STRING= '*';
+ private final static String scopeResolutionOperator= "::";
+
+ private StringMatcher fMatcher;
+ private StringMatcher fQualifierMatcher;
+ private StringMatcher fScopedQualifierMatcher;
+
+ /*
+ * @see FilteredList.FilterMatcher#setFilter(String, boolean)
+ */
+ public void setFilter(String pattern, boolean ignoreCase, boolean ignoreWildCards) {
+ int qualifierIndex= pattern.lastIndexOf(scopeResolutionOperator); //$NON-NLS-1$
+
+ // type
+ if (qualifierIndex == -1) {
+ fQualifierMatcher= null;
+ fScopedQualifierMatcher= null;
+ fMatcher= new StringMatcher(adjustPattern(pattern), ignoreCase, ignoreWildCards);
+
+ // qualified type
+ } else {
+ String pattern1 = pattern.substring(0, qualifierIndex + scopeResolutionOperator.length());
+ fQualifierMatcher= new StringMatcher(adjustPattern(pattern1), ignoreCase, ignoreWildCards);
+ StringBuffer buf = new StringBuffer();
+ buf.append(ANY_STRING);
+ buf.append(scopeResolutionOperator);
+ buf.append(pattern1);
+ String pattern2= buf.toString();
+ fScopedQualifierMatcher= new StringMatcher(adjustPattern(pattern2), ignoreCase, ignoreWildCards);
+ String pattern3 = pattern.substring(qualifierIndex + scopeResolutionOperator.length());
+ fMatcher= new StringMatcher(adjustPattern(pattern3), ignoreCase, ignoreWildCards);
+ }
+ }
+
+ /*
+ * @see FilteredList.FilterMatcher#match(Object)
+ */
+ public boolean match(Object element) {
+ if (!(element instanceof ITypeInfo))
+ return false;
+
+ TypeInfo type= (TypeInfo) element;
+
+ if (!fMatcher.match(type.getName()))
+ return false;
+
+ if (fQualifierMatcher == null)
+ return true;
+
+ if (fQualifierMatcher.match(type.getQualifiedName()))
+ return true;
+ else
+ return fScopedQualifierMatcher.match(type.getQualifiedName());
+ }
+
+ private String adjustPattern(String pattern) {
+ int length= pattern.length();
+ if (length > 0) {
+ switch (pattern.charAt(length - 1)) {
+ case END_SYMBOL:
+ pattern= pattern.substring(0, length - 1);
+ break;
+ case ANY_STRING:
+ break;
+ default:
+ pattern= pattern + ANY_STRING;
+ }
+ }
+ return pattern;
+ }
+ }
+
+ private static class StringComparator implements Comparator {
+ public int compare(Object left, Object right) {
+ String leftString= (String) left;
+ String rightString= (String) right;
+
+ int result= leftString.compareToIgnoreCase(rightString);
+ if (result == 0)
+ result= leftString.compareTo(rightString);
+
+ return result;
+ }
+ }
+
+ /**
+ * Constructs a type selection dialog.
+ * @param parent the parent shell.
+ * @param context the runnable context.
+ * @param scope the C search scope.
+ */
+ public TypeSelectionDialog(Shell parent) {
+ super(parent, new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY),
+ new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_CONTAINER_ONLY + TypeInfoLabelProvider.SHOW_ROOT_POSTFIX));
+ setUpperListLabel(TypeInfoMessages.getString("TypeSelectionDialog.upperLabel")); //$NON-NLS-1$
+ setLowerListLabel(TypeInfoMessages.getString("TypeSelectionDialog.lowerLabel")); //$NON-NLS-1$
+ }
+
+ /*
+ * @see AbstractElementListSelectionDialog#createFilteredList(Composite)
+ */
+ protected FilteredList createFilteredList(Composite parent) {
+ FilteredList list= super.createFilteredList(parent);
+
+ fFilteredList.setFilterMatcher(new TypeFilterMatcher());
+ fFilteredList.setComparator(new StringComparator());
+
+ return list;
+ }
+
+ /*
+ * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
+ */
+ protected void computeResult() {
+ ITypeInfo selection= (ITypeInfo) getLowerSelectedElement();
+ if (selection == null)
+ return;
+
+ List result= new ArrayList(1);
+ result.add(selection);
+ setResult(result);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 6af11e5bd12..43db1bb2e98 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -490,14 +490,14 @@
id="org.eclipse.cdt.ui.actions.OpenCSearchPage">