Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] revised class wizard patch

Here is the latest revised class wizard patch which fixes the no classes
problem and the base class inclusion problem.

Strategy for resolving the #include "path/to/base_class.h" is now:

(1) Check against known include paths for the project, and if found,
compute the path relative to the longest matching prefix. (Also, use angle brackets < > if the include path is outside the project).

e.g. (a) Creating class NewClass as a subclass of ExternalClass in
"{workspace}/my_project", where ExternalClass is found in
"/usr/include/ExternalClass.h" and the my_project properties has
"/usr/include" listed as an include directory.

The generated header file would be "{workspace}/my_project/NewClass.h" :

  #include <ExternalClass.h>

  class NewClass : public ExternalClass
  {
  ....
  };

e.g. (b) Creating class NewClass as a subclass of ExternalClass in
"{workspace}/my_project", where ExternalClass is found in
"/usr/include/blah/ExternalClass.h" and the my_project properties has
"/usr/include" listed as an include directory.

The generated header file would be "{workspace}/my_project/NewClass.h" :

  #include <blah/ExternalClass.h>

  class NewClass : public ExternalClass
  {
  ....
  };


(2) Check if the base class is in the same project as the newly created
class.  If so, compute the path relative to the newly created header file.

e.g. (a) Creating class NewClass as a subclass of OldClass in
"{workspace}/my_project", where OldClass is found in
"{workspace}/my_project/OldClass.h".

The generated header file would be "{workspace}/my_project/NewClass.h" :

  #include "OldClass.h"

  class NewClass : public OldClass
  {
  ....
  };

e.g. (b) Creating class NewClass as a subclass of OldClass in
"{workspace}/my_project/source", where OldClass is found in
"{workspace}/my_project/headers/OldClass.h".

The generated header file would be "{workspace}/my_project/source/NewClass.h" :

  #include "../headers/OldClass.h"

  class NewClass : public OldClass
  {
  ....
  };

(3) Fall back to the absolute path.

e.g. Creating class NewClass as a subclass of ExternalClass in
"{workspace}/my_project", where ExternalClass is found in
"/some/path/to/ExternalClass.h".

The generated header file would be "{workspace}/my_project/NewClass.h" :

  #include "/some/path/to/ExternalClass.h"

  class NewClass : public ExternalClass
  {
  ....
  };

The problem with strategy (2) above is the case (b) where you have relative include paths. What happens if you move a header file in your project? Right now this breaks your build since it's no longer able to locate the include.

Ideally, renaming a source or header file should automatically update all the #include references appropriately. This needs to be done as part of the refactoring feature.

Longer term, I think a better solution is, if the include path doesn't already exist, prompt the user and ask if they want to add it to their project properties. Alain promises that IScannerInfo will eventually allow setting of include paths. :)

-Chris

Index: src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties,v
retrieving revision 1.5
diff -u -r1.5 NewWizardMessages.properties
--- src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	26 Mar 2004 22:05:27 -0000	1.5
+++ src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	8 Apr 2004 23:04:09 -0000
@@ -164,22 +164,27 @@
 NewClassWizardPage.operations.getProjectClasses=Looking for classes in project
 
 NewClassWizardPage.error.NotAvailableForNonCppProjects= The wizard is not available for non C++ projects.
-# ------- BaseClassSelectionDialog -----
 
-BaseClassSelectionDialog.title=Classes in this project
-BaseClassSelectionDialog.message=Select a base class:
+NewClassWizardPage.getProjectClasses.exception.title=Exception
+NewClassWizardPage.getProjectClasses.exception.message=Unexpected exception. See log for details.
+NewClassWizardPage.getProjectClasses.noclasses.title=Class Selection
+NewClassWizardPage.getProjectClasses.noclasses.message=No classes available.
 
-# ------- NewClassWizardPage ------- 
+# ------- BaseClassSelectionDialog -----
 
-NewClassCreationWizard.title=New Java Class
+BaseClassSelectionDialog.title=Choose Base Class
+BaseClassSelectionDialog.message=&Choose a class (? = any character, * = any string):
+BaseClassSelectionDialog.filter=
 
-NewClassWizardPage.title=Java Class
-NewClassWizardPage.description=Create a new Java class.
+# ------- NewClassWizardPage ------- 
 
-NewClassWizardPage.methods.label=Which method stubs would you like to create?
-NewClassWizardPage.methods.main=public static void main(Strin&g[] args)
-NewClassWizardPage.methods.constructors=&Constructors from superclass
-NewClassWizardPage.methods.inherited=In&herited abstract methods
+# these are UNUSED by the CDT
+# NewClassWizardPage.title=Java Class
+# NewClassWizardPage.description=Create a new Java class.
+# NewClassWizardPage.methods.label=Which method stubs would you like to create?
+# NewClassWizardPage.methods.main=public static void main(Strin&g[] args)
+# NewClassWizardPage.methods.constructors=&Constructors from superclass
+# NewClassWizardPage.methods.inherited=In&herited abstract methods
 
 
 # ------- NewInterfaceWizardPage -------
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java,v
retrieving revision 1.13
diff -u -r1.13 NewClassWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	26 Feb 2004 19:30:35 -0000	1.13
+++ src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	8 Apr 2004 23:04:12 -0000
@@ -15,28 +15,30 @@
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
 import java.util.List;
 
 import org.eclipse.cdt.core.CConventions;
+import org.eclipse.cdt.core.browser.AllTypesCache;
+import org.eclipse.cdt.core.browser.ITypeInfo;
+import org.eclipse.cdt.core.browser.TypeInfo;
 import org.eclipse.cdt.core.model.CModelException;
 import org.eclipse.cdt.core.model.CoreModel;
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.ICProject;
 import org.eclipse.cdt.core.model.IOpenable;
-import org.eclipse.cdt.core.model.IParent;
 import org.eclipse.cdt.core.model.IStructure;
 import org.eclipse.cdt.core.model.ITranslationUnit;
 import org.eclipse.cdt.core.model.IWorkingCopy;
-import org.eclipse.cdt.core.search.BasicSearchMatch;
-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.SearchEngine;
 import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
 import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
+import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
+import org.eclipse.cdt.internal.ui.wizards.*;
 import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;
 import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
 import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
@@ -49,7 +51,6 @@
 import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator;
 import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
 import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
-import org.eclipse.cdt.ui.CSearchResultLabelProvider;
 import org.eclipse.cdt.ui.CUIPlugin;
 import org.eclipse.cdt.ui.CodeGeneration;
 import org.eclipse.cdt.ui.PreferenceConstants;
@@ -68,6 +69,7 @@
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -81,7 +83,6 @@
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.ui.actions.WorkspaceModifyOperation;
 import org.eclipse.ui.dialogs.ContainerGenerator;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
 import org.eclipse.ui.internal.WorkbenchMessages;
 import org.eclipse.ui.internal.WorkbenchPlugin;
 
@@ -111,7 +112,7 @@
 	// the created class element
 	private /*IStructure*/ ICElement createdClass = null;
 	
-	private List elementsOfTypeClassInProject = null;
+	private ITypeInfo[] elementsOfTypeClassInProject = null;
 	
 	// Controls
 	private StringDialogField fClassNameDialogField;
@@ -129,8 +130,6 @@
 
 	private boolean hasCppNature = false;
 	
-	BasicSearchResultCollector  resultCollector;
-	SearchEngine searchEngine;
 
 	// -------------------- Initialization ------------------
 	public NewClassWizardPage(IStructuredSelection selection) {
@@ -181,9 +180,6 @@
 
 		fClassNameStatus=  new StatusInfo();
 		fBaseClassStatus=  new StatusInfo();
-
-		resultCollector = new BasicSearchResultCollector ();
-		searchEngine = new SearchEngine();		
 	}
 	
 	public void init() {
@@ -330,9 +326,9 @@
 	
 	private void classPageChangeControlPressed(DialogField field) {
 		if (field == fBaseClassDialogField) {
-			BasicSearchMatch element= (BasicSearchMatch)chooseBaseClass();
-			if (element != null) {
-				fBaseClassDialogField.setText(element.getName());
+			ITypeInfo info= chooseBaseClass();
+			if (info != null) {
+				fBaseClassDialogField.setText(info.getQualifiedName());
 			}
 		}
 	}
@@ -398,8 +394,8 @@
 	}
 	
 	private ICElement getSelectionCElement(IStructuredSelection sel) {
-		if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
-			List list= ((IStructuredSelection)sel).toList();
+		if (!sel.isEmpty()) {
+			List list= sel.toList();
 			if (list.size() == 1) {
 				Object element= list.get(0);
 				if (element instanceof ICElement) {
@@ -411,8 +407,8 @@
 	}
 
 	private IResource getSelectionResourceElement(IStructuredSelection sel) {
-		if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
-			List list= ((IStructuredSelection)sel).toList();
+		if (!sel.isEmpty()) {
+			List list= sel.toList();
 			if (list.size() == 1) {
 				Object element= list.get(0);
 				if (element instanceof IResource) {
@@ -428,90 +424,74 @@
 		return null;
 	}
 	
-	private void getChildrenOfTypeClass(IParent parent, List elementsFound, IProgressMonitor monitor, int worked){
-		ICElement[] elements = parent.getChildren();
-		monitor.worked( worked );
-		
-		for (int i = 0; i< elements.length; i++){
-			ICElement element = (ICElement)elements[i];
-			if(element.getElementType() == ICElement.C_CLASS){
-				elementsFound.add(element);
-			}
-			if(element instanceof IParent){
-				getChildrenOfTypeClass((IParent)element, elementsFound, monitor, worked+1);
-			}
-		}
-	}
-	
-	private void searchForClasses(ICProject cProject, List elementsFound, IProgressMonitor monitor, int worked){
-		ICSearchPattern pattern = SearchEngine.createSearchPattern( "*", ICSearchConstants.CLASS, ICSearchConstants.DECLARATIONS, false ); //$NON-NLS-1$
-		ICElement[] elements = new ICElement[1];
-		elements[0] = cProject;
-		ICSearchScope scope = SearchEngine.createCSearchScope(elements, true);
-
-		try {
-			searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector, false);
-		} catch (InterruptedException e) {
-		}
-		elementsFound.addAll(resultCollector.getSearchResults());
-	}
-	
-	private List getClassElementsInProject(){
-		return elementsOfTypeClassInProject;
-	}
-	
-	private List findClassElementsInProject(){		
+	private ITypeInfo[] findClassElementsInProject(){		
 		if(eSelection == null){
-			return new LinkedList();			
+			return null;
 		}
 
 		if(	elementsOfTypeClassInProject != null ){
 			return elementsOfTypeClassInProject;
 		}
-
-		elementsOfTypeClassInProject = new LinkedList();		
-		IRunnableWithProgress runnable= new IRunnableWithProgress() {
-			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
-				if (monitor == null) {
-					monitor= new NullProgressMonitor();
-				}				
-				monitor.beginTask(NewWizardMessages.getString("NewClassWizardPage.operations.getProjectClasses"), 5); //$NON-NLS-1$
-				try{
-					ICProject cProject = eSelection.getCProject();
-					searchForClasses(cProject, elementsOfTypeClassInProject, monitor, 1);
-					//getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
-					monitor.worked(5);
-				} finally{
-					monitor.done();
+		
+		ICProject cProject= eSelection.getCProject();
+		ICElement[] elements= new ICElement[] { cProject };
+		final ICSearchScope scope= SearchEngine.createCSearchScope(elements, true);
+		final int[] kinds= { ICElement.C_CLASS, ICElement.C_STRUCT };
+		final Collection typeList= new ArrayList();
+
+		if (AllTypesCache.isCacheUpToDate()) {
+			// run without progress monitor
+			AllTypesCache.getTypes(scope, kinds, null, typeList);
+		} else {
+			IRunnableWithProgress runnable= new IRunnableWithProgress() {
+				public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+					AllTypesCache.getTypes(scope, kinds, monitor, typeList);
+					if (monitor.isCanceled()) {
+						throw new InterruptedException();
+					}
 				}
+			};
+
+			try {
+				getContainer().run(true, true, runnable);
+			} catch (InvocationTargetException e) {
+				String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.exception.title"); //$NON-NLS-1$
+				String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.exception.message"); //$NON-NLS-1$
+				ExceptionHandler.handle(e, title, message);
+				return null;
+			} catch (InterruptedException e) {
+				// cancelled by user
+				return null;
 			}
-		};
+		}
 		
-		try {
-			getWizard().getContainer().run(false, true, runnable);
-		} catch (InvocationTargetException e) {				
-		} catch (InterruptedException e) {
-		} 
-		finally {
+		if (typeList.isEmpty()) {
+			elementsOfTypeClassInProject= new ITypeInfo[0];
+		} else {
+			elementsOfTypeClassInProject= (ITypeInfo[]) typeList.toArray(new ITypeInfo[typeList.size()]);
+			Arrays.sort(elementsOfTypeClassInProject, TYPE_NAME_COMPARATOR);
 		}
+
 		return elementsOfTypeClassInProject;				
 	}
 	
-	protected Object chooseBaseClass(){
-		// find the available classes in this project
-		List elementsFound = findClassElementsInProject();
-		
-		ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new CSearchResultLabelProvider());
-		dialog.setTitle(NewWizardMessages.getString("BaseClassSelectionDialog.title")); //$NON-NLS-1$
-		dialog.setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
-		dialog.setElements(elementsFound.toArray());
-		dialog.setFilter("*"); //$NON-NLS-1$
-		
-		if (dialog.open() == ElementListSelectionDialog.OK) {
-			Object element= dialog.getFirstResult();
-			return element;
-		}		
-		return null;
+	protected ITypeInfo chooseBaseClass(){
+		ITypeInfo[] elementsFound= findClassElementsInProject();
+		if (elementsFound == null || elementsFound.length == 0) {
+			String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.title"); //$NON-NLS-1$
+			String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.message"); //$NON-NLS-1$
+			MessageDialog.openInformation(getShell(), title, message);
+			return null;
+		}
+
+		BaseClassSelectionDialog dialog= new BaseClassSelectionDialog(getShell());
+		dialog.setElements(elementsFound);
+
+		int result= dialog.open();
+		if (result != IDialogConstants.OK_ID)
+			return null;
+		
+		return (ITypeInfo)dialog.getFirstResult();
 	}
 	
 	// ------------- getter methods for dialog controls ------------- 			
@@ -578,7 +558,7 @@
 			monitor.worked(1);
 	
 			if(parentHeaderTU != null){
-				String header = constructHeaderFileContent(lineDelimiter);
+				String header = constructHeaderFileContent(parentHeaderTU, lineDelimiter);
 				IWorkingCopy headerWC = parentHeaderTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getDocumentProvider().getBufferFactory());
 				headerWC.getBuffer().append(header);
 				synchronized(headerWC)	{
@@ -587,6 +567,7 @@
 				}
 				//createdClass= (IStructure)headerWC.getElement(getNewClassName());				
 				createdClass= headerWC.getElement(getNewClassName());				
+				headerWC.destroy();
 			}
 			if(parentBodyTU != null){
 				String body = constructBodyFileContent(lineDelimiter);
@@ -596,6 +577,7 @@
 					bodyWC.reconcile();
 					bodyWC.commit(true, monitor);
 				}
+				bodyWC.destroy();
 			}
 		
 			return true;	
@@ -798,24 +780,41 @@
 	}
 
 	// ------------ Constructing File Contents -----------------
-	protected String constructHeaderFileContent(String lineDelimiter){
+	protected String constructHeaderFileContent(ITranslationUnit header, String lineDelimiter){
 		StringBuffer text = new StringBuffer();
 		boolean extendingBase = false;
 		String baseClassName = getBaseClassName();
 		String baseClassFileName = ""; //$NON-NLS-1$
+		boolean systemIncludePath= false;
+
 		if((baseClassName != null) && (baseClassName.length() > 0))
 		{
 			extendingBase = true;
-			List classElements = findClassElementsInProject();
-			BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, null, classElements);
+			
+			ITypeInfo[] classElements = findClassElementsInProject();
+			ITypeInfo baseClass = findInList(baseClassName, null, classElements);
+
+			if (baseClass != null) {
+				IPath projectPath= null;
+				IPath baseClassPath= null;
+				ICProject cProject= eSelection.getCProject();
+				if (cProject != null) {
+					projectPath= cProject.getPath();
+					baseClassPath= baseClass.resolveIncludePath(cProject);
+					if (baseClassPath != null && projectPath != null && !projectPath.isPrefixOf(baseClassPath)) {
+						systemIncludePath= true;
+					}
+				}
+				if (baseClassPath == null)
+					baseClassPath= resolveRelativePath(baseClass.getPath(), header.getPath(), projectPath);
 
-//			if(baseClass != null){
-//				IPath baseClassFileLocation = baseClass.getLocation();
-//				IPath newFilePath = getContainerFullPath(linkedResourceGroupForHeader);
-//				baseClassFileName = baseClassName + HEADER_EXT;
-//			} else {
+				if (baseClassPath != null)
+					baseClassFileName= baseClassPath.toString();
+				else
+					baseClassFileName= baseClass.getFileName();
+			} else {
 				baseClassFileName = baseClassName + HEADER_EXT;
-//			}
+			}
 		}
 		
 		if(isIncludeGuard()){
@@ -831,9 +830,16 @@
 		}
 		
 		if(extendingBase){
-			text.append("#include \""); //$NON-NLS-1$
+			text.append("#include "); //$NON-NLS-1$
+			if (systemIncludePath)
+				text.append('<'); //$NON-NLS-1$
+			else
+				text.append('\"'); //$NON-NLS-1$
 			text.append(baseClassFileName);
-			text.append('\"');
+			if (systemIncludePath)
+				text.append('>'); //$NON-NLS-1$
+			else
+				text.append('\"'); //$NON-NLS-1$
 			text.append(lineDelimiter);			
 			text.append(lineDelimiter);			
 		}
@@ -893,6 +899,25 @@
 		return text.toString();	 		
 	}
 		
+	private IPath resolveRelativePath(IPath baseClassPath, IPath headerPath, IPath projectPath) {
+		if (baseClassPath == null || headerPath == null || projectPath == null)
+			return baseClassPath;
+		
+		if (projectPath.isPrefixOf(baseClassPath) && projectPath.isPrefixOf(headerPath)) {
+			int segments= headerPath.matchingFirstSegments(baseClassPath);
+			if (segments > 0) {
+				IPath headerPrefix= headerPath.removeFirstSegments(segments).removeLastSegments(1);
+				IPath baseClassSuffix= baseClassPath.removeFirstSegments(segments);
+				IPath relativeBaseClassPath= new Path(""); //$NON-NLS-1$
+				for (int i= 0; i < headerPrefix.segmentCount(); ++i) {
+					relativeBaseClassPath= relativeBaseClassPath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$
+				}
+				return relativeBaseClassPath.append(baseClassSuffix);
+			}
+		}
+		return baseClassPath;
+	}
+
 	protected String constructBodyFileContent(String lineDelimiter){
 		StringBuffer text = new StringBuffer();
 		text.append("#include \""); //$NON-NLS-1$
@@ -923,7 +948,6 @@
 		text.append(lineDelimiter);				
 		return text.toString();
 	}
-	
 
 	// ------ validation --------
 	protected void doStatusUpdate() {
@@ -983,7 +1007,7 @@
 		}		
 
 		// must not exist
-		List elementsFound = findClassElementsInProject();
+		ITypeInfo[] elementsFound= findClassElementsInProject();
 		if(foundInList(getNewClassName(), getContainerPath(linkedResourceGroupForHeader), elementsFound)){
 			status.setWarning(NewWizardMessages.getString("NewClassWizardPage.error.ClassNameExists")); //$NON-NLS-1$
 		}
@@ -1014,35 +1038,29 @@
 		} 
 
 		// if class does not exist, give warning 
-		List elementsFound = findClassElementsInProject();
+		ITypeInfo[] elementsFound = findClassElementsInProject();
 		if(!foundInList(baseClassName, null, elementsFound)){
 			status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
 		}
 		return status;		
 	}
 		
-	private Object findInList(String name, IPath path, List elements){
-		Iterator i = elements.iterator();
-		while (i.hasNext()){
-			BasicSearchMatch element = (BasicSearchMatch)i.next();
-			if(path != null){
-				// check both the name and the path
-				if ((name.equals(element.getName())) && (path.makeAbsolute().equals(element.getLocation())))
-					return element;
-			} else {
-				// we don't care about the path
-				if (name.equals(element.getName()))
-					return element;				
-			}
-		}
-		return null;
+	/**
+	 * A comparator for simple type names
+	 */
+	final static private Comparator TYPE_NAME_COMPARATOR= new Comparator() {
+		public int compare(Object o1, Object o2) {
+			return ((ITypeInfo)o1).getName().compareTo(((ITypeInfo)o2).getName());
+		}
+	};
+	private ITypeInfo findInList(String name, IPath path, ITypeInfo[] elements) {
+		if (elements == null || elements.length == 0)
+			return null;
+		return TypeInfo.findType(name, path, elements);
 	}
 	
-	private boolean foundInList(String name, IPath path, List elements){
-		if(findInList(name, path, elements) != null)
-			return true;
-		else
-			return false;
+	private boolean foundInList(String name, IPath path, ITypeInfo[] elements){
+		return (findInList(name, path, elements) != null);
 	}
 
 }
Index: src/org/eclipse/cdt/internal/ui/wizards/BaseClassSelectionDialog.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/wizards/BaseClassSelectionDialog.java
diff -N src/org/eclipse/cdt/internal/ui/wizards/BaseClassSelectionDialog.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/wizards/BaseClassSelectionDialog.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.internal.ui.wizards;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A dialog to select a type from a list of types. The selected type will be
+ * opened in the editor.
+ */
+public class BaseClassSelectionDialog extends TypeSelectionDialog {
+
+	private static final String DIALOG_SETTINGS= BaseClassSelectionDialog.class.getName();
+	private static final int[] fVisibleTypes= {ICElement.C_CLASS, ICElement.C_STRUCT};
+
+	/**
+	 * Constructs an instance of <code>OpenTypeDialog</code>.
+	 * @param parent  the parent shell.
+	 */
+	public BaseClassSelectionDialog(Shell parent) {
+		super(parent);
+		setTitle(NewWizardMessages.getString("BaseClassSelectionDialog.title")); //$NON-NLS-1$
+		setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
+		setDialogSettings(DIALOG_SETTINGS);
+		setVisibleTypes(fVisibleTypes);
+	}
+}

Back to the top