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;
16 import org.eclipse.core.resources.IContainer;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IPath;
22 * Info for IJavaProject.
24 * Note: <code>getChildren()</code> returns all of the <code>IPackageFragmentRoots</code>
25 * specified on the classpath for the project. This can include roots external to the
26 * project. See <code>JavaProject#getAllPackageFragmentRoots()</code> and
27 * <code>JavaProject#getPackageFragmentRoots()</code>. To get only the <code>IPackageFragmentRoots</code>
28 * that are internal to the project, use <code>JavaProject#getChildren()</code>.
32 class JavaProjectElementInfo extends OpenableElementInfo {
35 * The name lookup facility to use with this project.
37 protected NameLookup fNameLookup = null;
40 * The searchable builder environment facility used
41 * with this project (doubles as the builder environment).
43 protected SearchableEnvironment fSearchableEnvironment = null;
46 * A array with all the non-java resources contained by this PackageFragment
48 private Object[] fNonJavaResources;
51 * Create and initialize a new instance of the receiver
53 public JavaProjectElementInfo() {
54 fNonJavaResources = null;
58 * Compute the non-java resources contained in this java project.
60 private Object[] computeNonJavaResources(JavaProject project) {
62 // determine if src == project and/or if bin == project
63 IPath projectPath = project.getProject().getFullPath();
64 boolean srcIsProject = false;
65 boolean binIsProject = false;
66 char[][] exclusionPatterns = null;
67 IClasspathEntry[] classpath = null;
68 IPath projectOutput = null;
70 classpath = project.getResolvedClasspath(true/*ignore unresolved variable*/);
71 for (int i = 0; i < classpath.length; i++) {
72 IClasspathEntry entry = classpath[i];
73 if (projectPath.equals(entry.getPath())) {
75 exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars();
79 projectOutput = project.getOutputLocation();
80 binIsProject = projectPath.equals(projectOutput);
81 } catch (JavaModelException e) {
85 Object[] nonJavaResources = new IResource[5];
86 int nonJavaResourcesCounter = 0;
88 IResource[] members = ((IContainer) project.getResource()).members();
89 for (int i = 0, max = members.length; i < max; i++) {
90 IResource res = members[i];
91 switch (res.getType()) {
93 IPath resFullPath = res.getFullPath();
94 String resName = res.getName();
96 // ignore a jar file on the classpath
97 // if (Util.isArchiveFileName(resName) && this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
100 // ignore .java file if src == project
102 // && Util.isValidCompilationUnitName(resName)
103 && !Util.isExcluded(res, exclusionPatterns)) {
106 // ignore .class file if bin == project
107 // if (binIsProject && Util.isValidClassFileName(resName)) {
110 // else add non java resource
111 if (nonJavaResources.length == nonJavaResourcesCounter) {
116 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
118 nonJavaResourcesCounter);
120 nonJavaResources[nonJavaResourcesCounter++] = res;
122 case IResource.FOLDER :
123 resFullPath = res.getFullPath();
125 // ignore non-excluded folders on the classpath or that correspond to an output location
126 if ((srcIsProject && !Util.isExcluded(res, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName()))
127 || this.isClasspathEntryOrOutputLocation(resFullPath, classpath, projectOutput)) {
130 // else add non java resource
131 if (nonJavaResources.length == nonJavaResourcesCounter) {
136 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
138 nonJavaResourcesCounter);
140 nonJavaResources[nonJavaResourcesCounter++] = res;
143 if (nonJavaResources.length != nonJavaResourcesCounter) {
147 (nonJavaResources = new IResource[nonJavaResourcesCounter]),
149 nonJavaResourcesCounter);
151 } catch (CoreException e) {
152 nonJavaResources = NO_NON_JAVA_RESOURCES;
153 nonJavaResourcesCounter = 0;
155 return nonJavaResources;
161 protected NameLookup getNameLookup() {
167 * Returns an array of non-java resources contained in the receiver.
169 Object[] getNonJavaResources(JavaProject project) {
171 Object[] nonJavaResources = fNonJavaResources;
172 if (nonJavaResources == null) {
173 nonJavaResources = computeNonJavaResources(project);
174 fNonJavaResources = nonJavaResources;
176 return nonJavaResources;
182 protected SearchableEnvironment getSearchableEnvironment() {
184 return fSearchableEnvironment;
187 * Returns whether the given path is a classpath entry or an output location.
189 private boolean isClasspathEntryOrOutputLocation(IPath path, IClasspathEntry[] resolvedClasspath, IPath projectOutput) {
190 if (projectOutput.equals(path)) return true;
191 for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
192 IClasspathEntry entry = resolvedClasspath[i];
193 if (entry.getPath().equals(path)) {
197 if ((output = entry.getOutputLocation()) != null && output.equals(path)) {
204 protected void setNameLookup(NameLookup newNameLookup) {
206 fNameLookup = newNameLookup;
208 // Reinitialize the searchable name environment since it caches
210 fSearchableEnvironment = null;
214 * Set the fNonJavaResources to res value
216 synchronized void setNonJavaResources(Object[] resources) {
218 fNonJavaResources = resources;
221 protected void setSearchableEnvironment(SearchableEnvironment newSearchableEnvironment) {
223 fSearchableEnvironment = newSearchableEnvironment;