blob: 3b786b2899bdebaab86786423e537f788b0c8cbe (
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
|
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems 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:
* 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.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.cdt.core.model.IPathEntry;
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();
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 (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, IPathEntry[] entries) {
for (int k = 0; k < entries.length; k++) {
IPathEntry entry = entries[k];
if (entry.getEntryKind() == IPathEntry.CDT_SOURCE) {
IPath sourcePath = entry.getPath();
if (resourcePath.equals(sourcePath)) {
return true;
}
}
}
return false;
}
}
|