Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] FIXED: 100858, 101133, 101134, 101259


FIXED 100858- New C++ Class wizard creates broken code and adds an include to the project to compensate
FIXED 101133- [New Class Wizard] appends included paths to the projects path indefinitely
FIXED 101134- [New Class Wizard] does not display classes from other projects for base class options
FIXED 101259- [New Class Wizard] displays duplicates in the Qualifier list

Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada


Index: src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java,v
retrieving revision 1.15
diff -u -r1.15 NewClassCodeGenerator.java
--- src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java	30 Mar 2005 00:58:50 -0000	1.15
+++ src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java	22 Jun 2005 15:38:27 -0000
@@ -444,6 +444,9 @@
             if (includePath == null)
                 includePath = baseClassLocation;
             
+            // make the new #include path in the source file only point to a relative file (i.e. now that the path has been included above in the project)
+            includePath = includePath.removeFirstSegments(includePath.segmentCount() - 1);
+            
             if (isSystemIncludePath)
                 systemIncludes.add(includePath);
             else
@@ -506,6 +509,11 @@
             }
             for (Iterator ipIter = newIncludePaths.iterator(); ipIter.hasNext(); ) {
                 IPath folderToAdd = (IPath) ipIter.next();
+                
+                // do not add any #includes that are local to the project
+                if (cProject.getPath().segment(0).equals(folderToAdd.segment(0)))
+                	continue;
+                
                 IPath basePath = null;
                 IPath includePath = folderToAdd;
                 IProject includeProject = PathUtil.getEnclosingProject(folderToAdd);
@@ -515,7 +523,9 @@
                     basePath = includeProject.getFullPath().makeRelative();
                 }
                 IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, basePath, includePath, isSystemInclude);
-                pathEntryList.add(entry);
+                
+                if (!pathEntryList.contains(entry)) // if the path already exists in the #includes then don't add it
+                	pathEntryList.add(entry);
             }
             pathEntries = (IPathEntry[]) pathEntryList.toArray(new IPathEntry[pathEntryList.size()]);
             cProject.setRawPathEntries(pathEntries, new SubProgressMonitor(monitor, 80));
Index: src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java,v
retrieving revision 1.1
diff -u -r1.1 NewClassWizardUtil.java
--- src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java	30 Mar 2005 00:17:45 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java	22 Jun 2005 15:38:27 -0000
@@ -1,10 +1,7 @@
 package org.eclipse.cdt.internal.ui.wizards.classwizard;
 
 import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
 
-import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.browser.AllTypesCache;
 import org.eclipse.cdt.core.browser.ITypeInfo;
 import org.eclipse.cdt.core.browser.ITypeReference;
@@ -16,8 +13,6 @@
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.ICProject;
 import org.eclipse.cdt.core.model.ISourceRoot;
-import org.eclipse.cdt.core.parser.IScannerInfo;
-import org.eclipse.cdt.core.parser.IScannerInfoProvider;
 import org.eclipse.cdt.internal.ui.editor.CEditor;
 import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
 import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
@@ -333,34 +328,36 @@
     private static final int[] CLASS_TYPES = { ICElement.C_CLASS, ICElement.C_STRUCT };
     
     /**
-     * Returns all classes/structs which are accessible from the include
-     * paths of the given project.
+     * Returns all classes/structs which are accessible.
      * 
      * @param project the given project
      * @return array of classes/structs
      */
     public static ITypeInfo[] getReachableClasses(IProject project) {
         ITypeInfo[] elements = AllTypesCache.getTypes(new TypeSearchScope(true), CLASS_TYPES);
-        if (elements != null && elements.length > 0) {
-            if (project != null) {
-                IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
-                if (provider != null) {
-                    //TODO get the scanner info for the actual source folder
-                    IScannerInfo info = provider.getScannerInformation(project);
-                    if (info != null) {
-                        String[] includePaths = info.getIncludePaths();
-                        List filteredTypes = new ArrayList();
-                        for (int i = 0; i < elements.length; ++i) {
-                            ITypeInfo baseType = elements[i];
-                            if (isTypeReachable(baseType, project, includePaths)) {
-                                filteredTypes.add(baseType);
-                            }
-                        }
-                        return (ITypeInfo[]) filteredTypes.toArray(new ITypeInfo[filteredTypes.size()]);
-                    }
-                }
-            }
-        }
+        
+        // fix for 101134, do not filter the found elements
+//        if (elements != null && elements.length > 0) {
+//            if (project != null) {
+//                IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
+//                if (provider != null) {
+//                    //TODO get the scanner info for the actual source folder
+//                    IScannerInfo info = provider.getScannerInformation(project);
+//                    if (info != null) {
+//                        String[] includePaths = info.getIncludePaths();
+//                        List filteredTypes = new ArrayList();
+//                        for (int i = 0; i < elements.length; ++i) {
+//                            ITypeInfo baseType = elements[i];
+//                            if (isTypeReachable(baseType, project, includePaths)) {
+//                                filteredTypes.add(baseType);
+//                            }
+//                        }
+//                        return (ITypeInfo[]) filteredTypes.toArray(new ITypeInfo[filteredTypes.size()]);
+//                    }
+//                }
+//            }
+//        }
+        
         return elements;
     }
     
Index: src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java,v
retrieving revision 1.1
diff -u -r1.1 NewClassCreationWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java	30 Mar 2005 00:17:45 -0000	1.1
+++ src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java	22 Jun 2005 15:38:27 -0000
@@ -1688,14 +1688,15 @@
             //TODO get the scanner info for the actual source folder
             IScannerInfo info = provider.getScannerInformation(project);
             if (info != null) {
-                String[] includePaths = info.getIncludePaths();
+//                String[] includePaths = info.getIncludePaths();
                 for (int i = 0; i < baseClasses.length; ++i) {
-                    IBaseClassInfo baseClass = baseClasses[i];
-                    ITypeInfo baseType = baseClass.getType();
+//                    IBaseClassInfo baseClass = baseClasses[i];
+//                    ITypeInfo baseType = baseClass.getType();
                     StatusInfo baseClassStatus = new StatusInfo();
-                    if (!NewClassWizardUtil.isTypeReachable(baseType, project, includePaths)) {
-                        baseClassStatus.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.BaseClassNotExistsInProject", baseType.getQualifiedTypeName().toString())); //$NON-NLS-1$
-                    }
+                    // fix for 101134, allow classes from other projects to be used as base classes
+//                    if (!NewClassWizardUtil.isTypeReachable(baseType, project, includePaths)) {
+//                        baseClassStatus.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.BaseClassNotExistsInProject", baseType.getQualifiedTypeName().toString())); //$NON-NLS-1$
+//                    }
                     status.add(baseClassStatus);
                 }
             }
Index: browser/org/eclipse/cdt/core/browser/AllTypesCache.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java,v
retrieving revision 1.12
diff -u -r1.12 AllTypesCache.java
--- browser/org/eclipse/cdt/core/browser/AllTypesCache.java	2 Sep 2004 21:57:29 -0000	1.12
+++ browser/org/eclipse/cdt/core/browser/AllTypesCache.java	22 Jun 2005 15:38:12 -0000
@@ -12,6 +12,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 
 import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.browser.typehierarchy.ITypeHierarchy;
@@ -161,10 +162,27 @@
 			public boolean visit(ITypeInfo info) {
 				if (ArrayUtil.contains(fKinds, info.getCElementType())
 					&& (fScope != null && info.isEnclosed(fScope))) {
-					fTypesFound.add(info);
+					if (!containsInfo(info)) // fix for 101259, do not add duplicates relative to qualified name and source code references
+						fTypesFound.add(info);
 				}
 				return true;
 			}
+			
+			public boolean containsInfo(ITypeInfo info) {
+				Iterator itr = fTypesFound.iterator();
+				Object o = null;
+				while (itr.hasNext()) {
+					o = itr.next();
+					if (o instanceof TypeInfo) {
+						if (((TypeInfo)o).sameSourceReference(info))
+							return true;
+					} else {
+						continue;
+					}
+				}
+				return false;
+			}
+			
 			public boolean shouldContinue() { return true; }
 		};
 		for (int i = 0; i < projects.length; ++i) {
Index: browser/org/eclipse/cdt/core/browser/TypeInfo.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java,v
retrieving revision 1.14
diff -u -r1.14 TypeInfo.java
--- browser/org/eclipse/cdt/core/browser/TypeInfo.java	15 Jun 2005 19:04:18 -0000	1.14
+++ browser/org/eclipse/cdt/core/browser/TypeInfo.java	22 Jun 2005 15:38:12 -0000
@@ -327,4 +327,23 @@
 		return (fElementType == ICElement.C_CLASS
 				|| fElementType == ICElement.C_STRUCT);
 	}
+	
+	/**
+	 * Returns true if the qualified name and the source references of the info parameter are the same
+	 * as this TypeInfo's qualified name and source references. 
+	 * @param info the ITypeInfo being compared
+	 * @return
+	 */
+	public boolean sameSourceReference(ITypeInfo info) {
+		ITypeReference[] refs = info.getReferences();
+		if (fQualifiedName.equals(info.getQualifiedTypeName()) && fSourceRefs.length == refs.length) {
+			for(int i=0; i<fSourceRefs.length; i++) {
+				if (!fSourceRefs[i].equals(refs[i])) {
+					return false;
+				}
+			}
+			return true;
+		}
+		return false;
+	}
 }

Back to the top