Skip to main content

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


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

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.16
diff -u -r1.16 NewClassCodeGenerator.java
--- src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java	23 Jun 2005 16:01:25 -0000	1.16
+++ src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java	23 Jun 2005 19:58:53 -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
@@ -498,24 +501,34 @@
         IPath addToResourcePath = cProject.getPath();
         try {
             List pathEntryList = new ArrayList();
+            List checkEntryList = new ArrayList();
+            
+            IPathEntry[] checkEntries = cProject.getResolvedPathEntries();
             IPathEntry[] pathEntries = cProject.getRawPathEntries();
             if (pathEntries != null) {
                 for (int i = 0; i < pathEntries.length; ++i) {
-                    pathEntryList.add(pathEntries[i]);
+                	pathEntryList.add(pathEntries[i]);
                 }
             }
+            for (int i=0; i < checkEntries.length; i++) {
+            	if (checkEntries[i] instanceof IIncludeEntry)
+            		checkEntryList.add(checkEntries[i]);
+            }
+            
             for (Iterator ipIter = newIncludePaths.iterator(); ipIter.hasNext(); ) {
                 IPath folderToAdd = (IPath) ipIter.next();
-                IPath basePath = null;
-                IPath includePath = folderToAdd;
+                
+                // do not add any #includes that are local to the project
+                if (cProject.getPath().segment(0).equals(folderToAdd.segment(0)))
+                	continue;
+                
                 IProject includeProject = PathUtil.getEnclosingProject(folderToAdd);
-                boolean isSystemInclude = (includeProject == null);
-                if (includeProject != null) {
-                    includePath = PathUtil.makeRelativePath(folderToAdd, includeProject.getLocation());
-                    basePath = includeProject.getFullPath().makeRelative();
-                }
-                IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, basePath, includePath, isSystemInclude);
-                pathEntryList.add(entry);
+
+                // make sure that the include is made the same way that build properties for projects makes them, so .contains below is a valid check
+                IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, null, includeProject.getLocation(), true);
+                
+                if (!checkEntryList.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));

Back to the top