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.JavaModelException;
15 import net.sourceforge.phpdt.internal.core.util.Util;
17 import org.eclipse.core.resources.IContainer;
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IPath;
23 * Info for IJavaProject.
25 * Note: <code>getChildren()</code> returns all of the <code>IPackageFragmentRoots</code>
26 * specified on the classpath for the project. This can include roots external to the
27 * project. See <code>JavaProject#getAllPackageFragmentRoots()</code> and
28 * <code>JavaProject#getPackageFragmentRoots()</code>. To get only the <code>IPackageFragmentRoots</code>
29 * that are internal to the project, use <code>JavaProject#getChildren()</code>.
33 class JavaProjectElementInfo extends OpenableElementInfo {
36 * The name lookup facility to use with this project.
38 protected NameLookup fNameLookup = null;
41 * The searchable builder environment facility used
42 * with this project (doubles as the builder environment).
44 protected SearchableEnvironment fSearchableEnvironment = null;
47 * A array with all the non-java resources contained by this PackageFragment
49 private Object[] fNonJavaResources;
52 * Create and initialize a new instance of the receiver
54 public JavaProjectElementInfo() {
55 fNonJavaResources = null;
59 * Compute the non-java resources contained in this java project.
61 private Object[] computeNonJavaResources(JavaProject project) {
63 // determine if src == project and/or if bin == project
64 IPath projectPath = project.getProject().getFullPath();
65 boolean srcIsProject = false;
66 boolean binIsProject = false;
67 char[][] exclusionPatterns = null;
68 IClasspathEntry[] classpath = null;
69 IPath projectOutput = null;
71 classpath = project.getResolvedClasspath(true/*ignore unresolved variable*/);
72 for (int i = 0; i < classpath.length; i++) {
73 IClasspathEntry entry = classpath[i];
74 if (projectPath.equals(entry.getPath())) {
76 exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars();
80 projectOutput = project.getOutputLocation();
81 binIsProject = projectPath.equals(projectOutput);
82 } catch (JavaModelException e) {
86 Object[] nonJavaResources = new IResource[5];
87 int nonJavaResourcesCounter = 0;
89 IResource[] members = ((IContainer) project.getResource()).members();
90 for (int i = 0, max = members.length; i < max; i++) {
91 IResource res = members[i];
92 switch (res.getType()) {
94 IPath resFullPath = res.getFullPath();
95 String resName = res.getName();
97 // ignore a jar file on the classpath
98 // if (Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
101 // ignore .java file if src == project
103 // && Util.isValidCompilationUnitName(resName)
104 && !Util.isExcluded(res, exclusionPatterns)) {
107 // ignore .class file if bin == project
108 // if (binIsProject && Util.isValidClassFileName(resName)) {
111 // else add non java resource
112 if (nonJavaResources.length == nonJavaResourcesCounter) {
117 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
119 nonJavaResourcesCounter);
121 nonJavaResources[nonJavaResourcesCounter++] = res;
123 case IResource.FOLDER :
124 resFullPath = res.getFullPath();
126 // ignore non-excluded folders on the classpath or that correspond to an output location
127 if ((srcIsProject && !Util.isExcluded(res, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName()))
128 || this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
131 // else add non java resource
132 if (nonJavaResources.length == nonJavaResourcesCounter) {
137 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
139 nonJavaResourcesCounter);
141 nonJavaResources[nonJavaResourcesCounter++] = res;
144 if (nonJavaResources.length != nonJavaResourcesCounter) {
148 (nonJavaResources = new IResource[nonJavaResourcesCounter]),
150 nonJavaResourcesCounter);
152 } catch (CoreException e) {
153 nonJavaResources = NO_NON_JAVA_RESOURCES;
154 nonJavaResourcesCounter = 0;
156 return nonJavaResources;
162 protected NameLookup getNameLookup() {
168 * Returns an array of non-java resources contained in the receiver.
170 Object[] getNonJavaResources(JavaProject project) {
172 Object[] nonJavaResources = fNonJavaResources;
173 if (nonJavaResources == null) {
174 nonJavaResources = computeNonJavaResources(project);
175 fNonJavaResources = nonJavaResources;
177 return nonJavaResources;
183 protected SearchableEnvironment getSearchableEnvironment() {
185 return fSearchableEnvironment;
188 * Returns whether the given path is a classpath entry or an output location.
190 private boolean isClasspathEntryOrOutputLocation(IPath path, IClasspathEntry[] resolvedClasspath, IPath projectOutput) {
191 if (projectOutput.equals(path)) return true;
192 for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
193 IClasspathEntry entry = resolvedClasspath[i];
194 if (entry.getPath().equals(path)) {
198 if ((output = entry.getOutputLocation()) != null && output.equals(path)) {
205 protected void setNameLookup(NameLookup newNameLookup) {
207 fNameLookup = newNameLookup;
209 // Reinitialize the searchable name environment since it caches
211 fSearchableEnvironment = null;
215 * Set the fNonJavaResources to res value
217 synchronized void setNonJavaResources(Object[] resources) {
219 fNonJavaResources = resources;
222 protected void setSearchableEnvironment(SearchableEnvironment newSearchableEnvironment) {
224 fSearchableEnvironment = newSearchableEnvironment;