1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import net.sourceforge.phpdt.core.IClasspathEntry;
14 import net.sourceforge.phpdt.core.IJavaProject;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.internal.core.util.Util;
18 import org.eclipse.core.resources.IContainer;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
24 * Info for IJavaProject.
26 * Note: <code>getChildren()</code> returns all of the
27 * <code>IPackageFragmentRoots</code> specified on the classpath for the
28 * project. This can include roots external to the project. See
29 * <code>JavaProject#getAllPackageFragmentRoots()</code> and
30 * <code>JavaProject#getPackageFragmentRoots()</code>. To get only the
31 * <code>IPackageFragmentRoots</code> that are internal to the project, use
32 * <code>JavaProject#getChildren()</code>.
36 class JavaProjectElementInfo extends OpenableElementInfo {
39 * The name lookup facility to use with this project.
41 protected NameLookup fNameLookup = null;
44 * The searchable builder environment facility used with this project
45 * (doubles as the builder environment).
47 // protected SearchableEnvironment fSearchableEnvironment = null;
49 * A array with all the non-java resources contained by this PackageFragment
51 private Object[] fNonJavaResources;
54 * Create and initialize a new instance of the receiver
56 public JavaProjectElementInfo() {
57 fNonJavaResources = null;
61 * Compute the non-java resources contained in this java project.
63 private Object[] computeNonJavaResources(JavaProject project) {
65 // determine if src == project and/or if bin == project
66 IPath projectPath = project.getProject().getFullPath();
67 boolean srcIsProject = false;
68 boolean binIsProject = false;
69 char[][] exclusionPatterns = null;
70 IClasspathEntry[] classpath = null;
71 IPath projectOutput = null;
74 .getResolvedClasspath(true/* ignore unresolved variable */);
75 for (int i = 0; i < classpath.length; i++) {
76 IClasspathEntry entry = classpath[i];
77 if (projectPath.equals(entry.getPath())) {
79 exclusionPatterns = ((ClasspathEntry) entry)
80 .fullExclusionPatternChars();
84 projectOutput = project.getOutputLocation();
85 binIsProject = projectPath.equals(projectOutput);
86 } catch (JavaModelException e) {
90 Object[] nonJavaResources = new IResource[5];
91 int nonJavaResourcesCounter = 0;
93 IResource[] members = ((IContainer) project.getResource())
95 for (int i = 0, max = members.length; i < max; i++) {
96 IResource res = members[i];
97 switch (res.getType()) {
99 IPath resFullPath = res.getFullPath();
100 String resName = res.getName();
102 // ignore a jar file on the classpath
103 // if (ProjectPrefUtil.isArchiveFileName(resName) &&
104 // this.isClasspathEntryOrOutputLocation(resFullPath,
105 // classpath, projectOutput)) {
108 // ignore .java file if src == project
110 // && ProjectPrefUtil.isValidCompilationUnitName(resName)
111 && !Util.isExcluded(res, exclusionPatterns)) {
114 // ignore .class file if bin == project
115 // if (binIsProject &&
116 // ProjectPrefUtil.isValidClassFileName(resName)) {
119 // else add non java resource
120 if (nonJavaResources.length == nonJavaResourcesCounter) {
126 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
127 0, nonJavaResourcesCounter);
129 nonJavaResources[nonJavaResourcesCounter++] = res;
131 case IResource.FOLDER:
132 resFullPath = res.getFullPath();
134 // ignore non-excluded folders on the classpath or that
135 // correspond to an output location
137 && !Util.isExcluded(res, exclusionPatterns) && Util
138 .isValidFolderNameForPackage(res.getName()))
139 || this.isClasspathEntryOrOutputLocation(
140 resFullPath, classpath, projectOutput)) {
143 // else add non java resource
144 if (nonJavaResources.length == nonJavaResourcesCounter) {
150 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
151 0, nonJavaResourcesCounter);
153 nonJavaResources[nonJavaResourcesCounter++] = res;
156 if (nonJavaResources.length != nonJavaResourcesCounter) {
161 (nonJavaResources = new IResource[nonJavaResourcesCounter]),
162 0, nonJavaResourcesCounter);
164 } catch (CoreException e) {
165 nonJavaResources = NO_NON_JAVA_RESOURCES;
166 nonJavaResourcesCounter = 0;
168 return nonJavaResources;
174 protected NameLookup getNameLookup() {
180 * Returns an array of non-java resources contained in the receiver.
182 Object[] getNonJavaResources(JavaProject project) {
184 Object[] nonJavaResources = fNonJavaResources;
185 if (nonJavaResources == null) {
186 nonJavaResources = computeNonJavaResources(project);
187 fNonJavaResources = nonJavaResources;
189 return nonJavaResources;
195 // protected SearchableEnvironment getSearchableEnvironment() {
197 // return fSearchableEnvironment;
200 * Returns whether the given path is a classpath entry or an output
203 private boolean isClasspathEntryOrOutputLocation(IPath path,
204 IClasspathEntry[] resolvedClasspath, IPath projectOutput) {
205 if (projectOutput.equals(path))
207 for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
208 IClasspathEntry entry = resolvedClasspath[i];
209 if (entry.getPath().equals(path)) {
213 if ((output = entry.getOutputLocation()) != null
214 && output.equals(path)) {
221 protected void setNameLookup(NameLookup newNameLookup) {
223 fNameLookup = newNameLookup;
225 // Reinitialize the searchable name environment since it caches
227 // fSearchableEnvironment = null;
231 * Set the fNonJavaResources to res value
233 synchronized void setNonJavaResources(Object[] resources) {
235 fNonJavaResources = resources;
238 // protected void setSearchableEnvironment(SearchableEnvironment
239 // newSearchableEnvironment) {
241 // fSearchableEnvironment = newSearchableEnvironment;