Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351422 - CModelUtil.getSourceFolder returns non-source folders
Summary: CModelUtil.getSourceFolder returns non-source folders
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-07 07:15 EDT by Mohamed Hussein CLA
Modified: 2012-05-22 20:22 EDT (History)
2 users (show)

See Also:


Attachments
Patch to make getSourceFolder only returns source folders (677 bytes, application/octet-stream)
2011-07-07 07:15 EDT, Mohamed Hussein CLA
no flags Details
Patch to make getSourceFolder only returns source folders only (1.57 KB, patch)
2011-07-13 14:22 EDT, Mohamed Hussein CLA
cdtdoug: iplog+
Details | Diff
Modified patch. (1.14 KB, patch)
2011-08-09 20:00 EDT, Nobody - feel free to take it CLA
cdtdoug: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mohamed Hussein CLA 2011-07-07 07:15:53 EDT
Created attachment 199245 [details]
Patch to make getSourceFolder only returns source folders

The method org.eclipse.cdt.internal.corext.util.CModelUtil.getSourceFolder(ICElement) will return the passed folder even if it is not a source folder.

The Java doc of the method says:
	/**
	 * Returns the source folder of <code>ICElement</code>. If the given
	 * element is already a source folder, the element itself is returned.
	 */
	public static ICContainer getSourceFolder(ICElement element) {

Though inside the method it allows returning the first folder using the check:
if (curr instanceof ICContainer && folder == null) {
    folder = (ICContainer)curr;
}

Changing the condition to
if (curr instanceof ISourceRoot) {

ensures that the method always returns source folders only.
Comment 1 Doug Schaefer CLA 2011-07-13 11:14:30 EDT
The patch you've provided isn't in a format I can work with. It has to be generated from egit and in a format so I can Apply patch with it.
Comment 2 Mohamed Hussein CLA 2011-07-13 14:22:35 EDT
Created attachment 199610 [details]
Patch to make getSourceFolder only returns source folders only

git format patch
Comment 3 Nobody - feel free to take it CLA 2011-08-09 20:00:37 EDT
Created attachment 201201 [details]
Modified patch.
Comment 4 Nobody - feel free to take it CLA 2011-08-09 20:03:25 EDT
Mohamed, I modified your patch a little bit. I'll commit it if my modifications are OK with you.
Comment 5 Mohamed Hussein CLA 2011-08-11 05:22:06 EDT
(In reply to comment #4)
> Mohamed, I modified your patch a little bit. I'll commit it if my modifications
> are OK with you.

Hi Mikhail, Your change performs the same function, so I am ok with using it instead of mine.

Minor point:
I understand you want to minimize the code changes, but I guess you can also move
foundSourceRoot = (curr instanceof ISourceRoot);
Inside the if condition and change it to =true
Comment 6 Nobody - feel free to take it CLA 2011-08-11 10:44:26 EDT
(In reply to comment #5)
> Minor point:
> I understand you want to minimize the code changes, but I guess you can also
> move
> foundSourceRoot = (curr instanceof ISourceRoot);
> Inside the if condition and change it to =true

It's not my intention to minimize the code changes, I just want to simplify the old code. I don't think we need 'foundSourceRoot' flag, we can simply check 'curr instanceof ISourceRoot' directly in the while condition.
Comment 7 Nobody - feel free to take it CLA 2011-08-15 12:32:58 EDT
Applied to the HEAD branch.
Comment 8 CDT Genie CLA 2011-08-15 13:23:02 EDT
*** cdt git genie on behalf of Mohamed Hussein ***

    Bug 351422 - CModelUtil.getSourceFolder returns non-source folders.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=e0b1937020793057ce96ee45591a9c35d1fe8704