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
31 * this JAR does not have source attached).
33 // protected SourceMapper sourceMapper = null;
36 * The kind of the root associated with this info.
37 * Valid kinds are: <ul>
38 * <li><code>IPackageFragmentRoot.K_SOURCE</code>
39 * <li><code>IPackageFragmentRoot.K_BINARY</code></ul>
41 protected int fRootKind= IPackageFragmentRoot.K_SOURCE;
44 * A array with all the non-java resources contained by this PackageFragment
46 protected Object[] fNonJavaResources;
48 * Create and initialize a new instance of the receiver
50 public PackageFragmentRootInfo() {
51 fNonJavaResources = null;
54 * Starting at this folder, create non-java resources for this package fragment root
55 * and add them to the non-java resources collection.
57 * @exception JavaModelException The resource associated with this package fragment does not exist
59 static Object[] computeFolderNonJavaResources(JavaProject project, IContainer folder, char[][] exclusionPatterns) throws JavaModelException {
60 Object[] nonJavaResources = new IResource[5];
61 int nonJavaResourcesCounter = 0;
63 IClasspathEntry[] classpath = project.getResolvedClasspath(true/*ignore unresolved variable*/);
64 IResource[] members = folder.members();
65 nextResource: for (int i = 0, max = members.length; i < max; i++) {
66 IResource member = members[i];
67 switch (member.getType()) {
69 String fileName = member.getName();
71 // ignore .java files that are not excluded
72 if (Util.isValidCompilationUnitName(fileName) && !Util.isExcluded(member, exclusionPatterns))
73 continue nextResource;
74 // ignore .class files
75 // if (Util.isValidClassFileName(fileName))
76 // continue nextResource;
77 // // ignore .zip or .jar file on classpath
78 // if (Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath))
79 // continue nextResource;
82 case IResource.FOLDER :
83 // ignore valid packages or excluded folders that correspond to a nested pkg fragment root
84 // if (Util.isValidFolderNameForPackage(member.getName())
85 // && (!Util.isExcluded(member, exclusionPatterns)
86 // || isClasspathEntry(member.getFullPath(), classpath)))
87 // continue nextResource;
90 if (nonJavaResources.length == nonJavaResourcesCounter) {
92 System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
94 nonJavaResources[nonJavaResourcesCounter++] = member;
97 if (nonJavaResources.length != nonJavaResourcesCounter) {
98 System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter);
100 return nonJavaResources;
101 } catch (CoreException e) {
102 throw new JavaModelException(e);
106 * Compute the non-package resources of this package fragment root.
108 * @exception JavaModelException The resource associated with this package fragment root does not exist
110 private Object[] computeNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) {
111 Object[] nonJavaResources = NO_NON_JAVA_RESOURCES;
113 // the underlying resource may be a folder or a project (in the case that the project folder
114 // is actually the package fragment root)
115 if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
117 computeFolderNonJavaResources(
118 (JavaProject)project,
119 (IContainer) underlyingResource,
120 handle.fullExclusionPatternChars());
122 } catch (JavaModelException e) {
124 return nonJavaResources;
127 * Returns an array of non-java resources contained in the receiver.
129 synchronized Object[] getNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) {
130 Object[] nonJavaResources = fNonJavaResources;
131 if (nonJavaResources == null) {
132 nonJavaResources = this.computeNonJavaResources(project, underlyingResource, handle);
133 fNonJavaResources = nonJavaResources;
135 return nonJavaResources;
138 * Returns the kind of this root.
140 public int getRootKind() {
144 * Retuns the SourceMapper for this root, or <code>null</code>
145 * if this root does not have attached source.
147 //protected synchronized SourceMapper getSourceMapper() {
148 // return this.sourceMapper;
150 private static boolean isClasspathEntry(IPath path, IClasspathEntry[] resolvedClasspath) {
151 for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
152 IClasspathEntry entry = resolvedClasspath[i];
153 if (entry.getPath().equals(path)) {
160 * Set the fNonJavaResources to res value
162 synchronized void setNonJavaResources(Object[] resources) {
163 fNonJavaResources = resources;
166 * Sets the kind of this root.
168 protected void setRootKind(int newRootKind) {
169 fRootKind = newRootKind;
172 * Sets the SourceMapper for this root.
174 //protected synchronized void setSourceMapper(SourceMapper mapper) {
175 // this.sourceMapper= mapper;