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.IPackageFragmentRoot;
16 import net.sourceforge.phpdt.core.JavaModelException;
17 import net.sourceforge.phpdt.internal.core.util.Util;
19 import org.eclipse.core.resources.IContainer;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.CoreException;
22 //import org.eclipse.core.runtime.IPath;
25 * The element info for <code>PackageFragmentRoot</code>s.
27 class PackageFragmentRootInfo extends OpenableElementInfo {
30 * The SourceMapper for this JAR (or <code>null</code> if this JAR does
31 * not have source attached).
33 // protected SourceMapper sourceMapper = null;
35 * The kind of the root associated with this info. Valid kinds are:
37 * <li><code>IPackageFragmentRoot.K_SOURCE</code>
38 * <li><code>IPackageFragmentRoot.K_BINARY</code>
41 protected int fRootKind = IPackageFragmentRoot.K_SOURCE;
44 * A array with all the non-java resources contained by this PackageFragment
46 protected Object[] fNonJavaResources;
49 * Create and initialize a new instance of the receiver
51 public PackageFragmentRootInfo() {
52 fNonJavaResources = null;
56 * Starting at this folder, create non-java resources for this package
57 * fragment root and add them to the non-java resources collection.
59 * @exception JavaModelException
60 * The resource associated with this package fragment does
63 static Object[] computeFolderNonJavaResources(JavaProject project,
64 IContainer folder, char[][] exclusionPatterns)
65 throws JavaModelException {
66 Object[] nonJavaResources = new IResource[5];
67 int nonJavaResourcesCounter = 0;
69 IClasspathEntry[] classpath = project
70 .getResolvedClasspath(true/* ignore unresolved variable */);
71 IResource[] members = folder.members();
72 nextResource: for (int i = 0, max = members.length; i < max; i++) {
73 IResource member = members[i];
74 switch (member.getType()) {
76 String fileName = member.getName();
78 // ignore .java files that are not excluded
79 if (Util.isValidCompilationUnitName(fileName)
80 && !Util.isExcluded(member, exclusionPatterns))
81 continue nextResource;
82 // ignore .class files
83 // if (ProjectPrefUtil.isValidClassFileName(fileName))
84 // continue nextResource;
85 // // ignore .zip or .jar file on classpath
86 // if (ProjectPrefUtil.isArchiveFileName(fileName) &&
87 // isClasspathEntry(member.getFullPath(), classpath))
88 // continue nextResource;
91 case IResource.FOLDER:
92 // ignore valid packages or excluded folders that correspond
93 // to a nested pkg fragment root
95 // (ProjectPrefUtil.isValidFolderNameForPackage(member.getName())
96 // && (!ProjectPrefUtil.isExcluded(member,
98 // || isClasspathEntry(member.getFullPath(), classpath)))
99 // continue nextResource;
102 if (nonJavaResources.length == nonJavaResourcesCounter) {
108 (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]),
109 0, nonJavaResourcesCounter);
111 nonJavaResources[nonJavaResourcesCounter++] = member;
114 if (nonJavaResources.length != nonJavaResourcesCounter) {
119 (nonJavaResources = new IResource[nonJavaResourcesCounter]),
120 0, nonJavaResourcesCounter);
122 return nonJavaResources;
123 } catch (CoreException e) {
124 throw new JavaModelException(e);
129 * Compute the non-package resources of this package fragment root.
131 * @exception JavaModelException
132 * The resource associated with this package fragment root
135 private Object[] computeNonJavaResources(IJavaProject project,
136 IResource underlyingResource, PackageFragmentRoot handle) {
137 Object[] nonJavaResources = NO_NON_JAVA_RESOURCES;
139 // the underlying resource may be a folder or a project (in the case
140 // that the project folder
141 // is actually the package fragment root)
142 if (underlyingResource.getType() == IResource.FOLDER
143 || underlyingResource.getType() == IResource.PROJECT) {
144 nonJavaResources = computeFolderNonJavaResources(
145 (JavaProject) project, (IContainer) underlyingResource,
146 handle.fullExclusionPatternChars());
148 } catch (JavaModelException e) {
150 return nonJavaResources;
154 * Returns an array of non-java resources contained in the receiver.
156 synchronized Object[] getNonJavaResources(IJavaProject project,
157 IResource underlyingResource, PackageFragmentRoot handle) {
158 Object[] nonJavaResources = fNonJavaResources;
159 if (nonJavaResources == null) {
160 nonJavaResources = this.computeNonJavaResources(project,
161 underlyingResource, handle);
162 fNonJavaResources = nonJavaResources;
164 return nonJavaResources;
168 * Returns the kind of this root.
170 public int getRootKind() {
175 * Retuns the SourceMapper for this root, or <code>null</code> if this
176 * root does not have attached source.
178 // protected synchronized SourceMapper getSourceMapper() {
179 // return this.sourceMapper;
181 // private static boolean isClasspathEntry(IPath path,
182 // IClasspathEntry[] resolvedClasspath) {
183 // for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
184 // IClasspathEntry entry = resolvedClasspath[i];
185 // if (entry.getPath().equals(path)) {
193 * Set the fNonJavaResources to res value
195 synchronized void setNonJavaResources(Object[] resources) {
196 fNonJavaResources = resources;
200 * Sets the kind of this root.
202 protected void setRootKind(int newRootKind) {
203 fRootKind = newRootKind;
206 * Sets the SourceMapper for this root.
208 // protected synchronized void setSourceMapper(SourceMapper mapper) {
209 // this.sourceMapper= mapper;