Skip to main content
summaryrefslogtreecommitdiffstats
blob: c674f1f199995fc451db52fbe00ff3c00ab9bfb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************
 * Copyright (c) 2000, 2007 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.model;

import java.util.ArrayList;

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.ISourceRoot;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescription;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;

/**
 */
public class CContainerInfo extends OpenableInfo {

	Object[] nonCResources = null;

	/**
	 * Constructs a new C Model Info 
	 */
	protected CContainerInfo(CElement element) {
		super(element);
	}

	/**
	 * @param container
	 * @return
	 */
	public Object[] getNonCResources(IResource res) {
		if (nonCResources != null)
			return nonCResources;

		ArrayList notChildren = new ArrayList();
		ICElement celement = getElement();
		ICProject cproject = celement.getCProject();
		// move back to the sourceroot.
		while (! (celement instanceof ISourceRoot) && celement != null) {
			celement = celement.getParent();
		}
		ISourceRoot root = null;
		if (celement instanceof ISourceRoot) {
			root = (ISourceRoot)celement;
		} else {
			return new Object[0]; // should not be. assert
		}

		try {
			IResource[] resources = null;
			if (res instanceof IContainer) {
				IContainer container = (IContainer)res;
				resources = container.members(false);
			}

//			IPathEntry[] entries = cproject.getResolvedPathEntries();
			ICSourceEntry[] entries = null;
			CProjectDescription des = (CProjectDescription)CProjectDescriptionManager.getInstance().getProjectDescription(cproject.getProject());
			if(des != null){
				ICConfigurationDescription cfg = des.getIndexConfiguration();
				if(cfg != null){
					entries = cfg.getSourceEntries();
				}
			}
			
			if (resources != null) {
				for (int i = 0; i < resources.length; i++) {
					IResource member = resources[i];
					switch(member.getType()) {
						case IResource.FOLDER: {
							// Check if the folder is not itself a sourceEntry.
							IPath resourcePath = member.getFullPath();
							if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries)) {
								continue;
							}
							break;
						}
						case IResource.FILE: {
							String filename = member.getName();
							if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) &&
									root.isOnSourceEntry(member)) {
								continue;
							}
							if (root.isOnSourceEntry(member)) {
								if (cproject.isOnOutputEntry(member) && CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
									continue;
								}
							}
							break;
						}
					}
					notChildren.add(member);
				}
			}
		} catch (CoreException e) {
			//System.out.println (e);
			//CPlugin.log (e);
			//e.printStackTrace();
		}
		setNonCResources(notChildren.toArray());	
		return nonCResources;
	}

	/**
	 * @param container
	 * @return
	 */
	public void setNonCResources(Object[] resources) {
		nonCResources = resources;
	}

	private static boolean isSourceEntry(IPath resourcePath, ICSourceEntry[] entries) {
		if(entries == null)
			return false;
		
		for (int k = 0; k < entries.length; k++) {
			ICSourceEntry entry = entries[k];
//			if (entry.getEntryKind() == IPathEntry.CDT_SOURCE) {
				IPath sourcePath = entry.getFullPath();
				if (resourcePath.equals(sourcePath)) {
					return true;
				}
//			}
		}
		return false;
	}
}

Back to the top