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 <code>IPackageFragmentRoots</code>
27 * specified on the classpath for the project. This can include roots external to the
28 * project. See <code>JavaProject#getAllPackageFragmentRoots()</code> and
29 * <code>JavaProject#getPackageFragmentRoots()</code>. To get only the <code>IPackageFragmentRoots</code>
30 * that are internal to the project, use <code>JavaProject#getChildren()</code>.
34 class JavaProjectElementInfo extends OpenableElementInfo {
37 * The name lookup facility to use with this project.
39 protected NameLookup fNameLookup = null;
42 * The searchable builder environment facility used
43 * with this project (doubles as the builder environment).
45 protected SearchableEnvironment fSearchableEnvironment = null;
48 * A array with all the non-java resources contained by this PackageFragment
50 private Object[] fNonJavaResources;
53 * Create and initialize a new instance of the receiver
55 public JavaProjectElementInfo() {
56 fNonJavaResources = null;
60 * Compute the non-java resources contained in this java project.
62 private Object[] computeNonJavaResources(JavaProject project) {
64 // determine if src == project and/or if bin == project
65 IPath projectPath = project.getProject().getFullPath();
66 boolean srcIsProject = false;
67 boolean binIsProject = false;
68 char[][] exclusionPatterns = null;
69 IClasspathEntry[] classpath = null;
70 IPath projectOutput = null;
72 classpath = project.getResolvedClasspath(true/*ignore unresolved variable*/);
73 for (int i = 0; i < classpath.length; i++) {
74 IClasspathEntry entry = classpath[i];
75 if (projectPath.equals(entry.getPath())) {
77 exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars();
81 projectOutput = project.getOutputLocation();
82 binIsProject = projectPath.equals(projectOutput);
83 } catch (JavaModelException e) {
87 Object[] nonJavaResources = new IResource[5];
88 int nonJavaResourcesCounter = 0;
90 IResource[] members = ((IContainer) project.getResource()).members();
91 for (int i = 0, max = members.length; i < max; i++) {
92 IResource res = members[i];
93 switch (res.getType()) {
95 IPath resFullPath = res.getFullPath();
96 String resName = res.getName();
98 // ignore a jar file on the classpath
99 // if (Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
102 // ignore .java file if src == project
104 // && Util.isValidCompilationUnitName(resName)
105 && !Util.isExcluded(res, exclusionPatterns)) {
108 // ignore .class file if bin == project
109 // if (binIsProject && Util.isValidClassFileName(resName)) {
112 // else add non java resource
113 if (nonJavaResources.length == nonJavaResourcesCounter) {
118 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
120 nonJavaResourcesCounter);
122 nonJavaResources[nonJavaResourcesCounter++] = res;
124 case IResource.FOLDER :
125 resFullPath = res.getFullPath();
127 // ignore non-excluded folders on the classpath or that correspond to an output location
128 if ((srcIsProject && !Util.isExcluded(res, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName()))
129 || this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
132 // else add non java resource
133 if (nonJavaResources.length == nonJavaResourcesCounter) {
138 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
140 nonJavaResourcesCounter);
142 nonJavaResources[nonJavaResourcesCounter++] = res;
145 if (nonJavaResources.length != nonJavaResourcesCounter) {
149 (nonJavaResources = new IResource[nonJavaResourcesCounter]),
151 nonJavaResourcesCounter);
153 } catch (CoreException e) {
154 nonJavaResources = NO_NON_JAVA_RESOURCES;
155 nonJavaResourcesCounter = 0;
157 return nonJavaResources;
163 protected NameLookup getNameLookup() {
169 * Returns an array of non-java resources contained in the receiver.
171 Object[] getNonJavaResources(JavaProject project) {
173 Object[] nonJavaResources = fNonJavaResources;
174 if (nonJavaResources == null) {
175 nonJavaResources = computeNonJavaResources(project);
176 fNonJavaResources = nonJavaResources;
178 return nonJavaResources;
184 protected SearchableEnvironment getSearchableEnvironment() {
186 return fSearchableEnvironment;
189 * Returns whether the given path is a classpath entry or an output location.
191 private boolean isClasspathEntryOrOutputLocation(IPath path, IClasspathEntry[] resolvedClasspath, IPath projectOutput) {
192 if (projectOutput.equals(path)) return true;
193 for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
194 IClasspathEntry entry = resolvedClasspath[i];
195 if (entry.getPath().equals(path)) {
199 if ((output = entry.getOutputLocation()) != null && output.equals(path)) {
206 protected void setNameLookup(NameLookup newNameLookup) {
208 fNameLookup = newNameLookup;
210 // Reinitialize the searchable name environment since it caches
212 fSearchableEnvironment = null;
216 * Set the fNonJavaResources to res value
218 synchronized void setNonJavaResources(Object[] resources) {
220 fNonJavaResources = resources;
223 protected void setSearchableEnvironment(SearchableEnvironment newSearchableEnvironment) {
225 fSearchableEnvironment = newSearchableEnvironment;