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;
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 * The element info for <code>PackageFragmentRoot</code>s.
26 class PackageFragmentRootInfo extends OpenableElementInfo {
29 * The SourceMapper for this JAR (or <code>null</code> if
30 * this JAR does not have source attached).
32 // protected SourceMapper sourceMapper = null;
35 * The kind of the root associated with this info.
36 * Valid kinds are: <ul>
37 * <li><code>IPackageFragmentRoot.K_SOURCE</code>
38 * <li><code>IPackageFragmentRoot.K_BINARY</code></ul>
40 protected int fRootKind= IPackageFragmentRoot.K_SOURCE;
43 * A array with all the non-java resources contained by this PackageFragment
45 protected Object[] fNonJavaResources;
47 * Create and initialize a new instance of the receiver
49 public PackageFragmentRootInfo() {
50 fNonJavaResources = null;
53 * Starting at this folder, create non-java resources for this package fragment root
54 * and add them to the non-java resources collection.
56 * @exception JavaModelException The resource associated with this package fragment does not exist
58 static Object[] computeFolderNonJavaResources(JavaProject project, IContainer folder, char[][] exclusionPatterns) throws JavaModelException {
59 Object[] nonJavaResources = new IResource[5];
60 int nonJavaResourcesCounter = 0;
62 IClasspathEntry[] classpath = project.getResolvedClasspath(true/*ignore unresolved variable*/);
63 IResource[] members = folder.members();
64 nextResource: for (int i = 0, max = members.length; i < max; i++) {
65 IResource member = members[i];
66 switch (member.getType()) {
68 String fileName = member.getName();
70 // ignore .java files that are not excluded
71 if (Util.isValidCompilationUnitName(fileName) && !Util.isExcluded(member, exclusionPatterns))
72 continue nextResource;
73 // ignore .class files
74 // if (Util.isValidClassFileName(fileName))
75 // continue nextResource;
76 // // ignore .zip or .jar file on classpath
77 // if (Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath))
78 // continue nextResource;
81 case IResource.FOLDER :
82 // ignore valid packages or excluded folders that correspond to a nested pkg fragment root
83 // if (Util.isValidFolderNameForPackage(member.getName())
84 // && (!Util.isExcluded(member, exclusionPatterns)
85 // || isClasspathEntry(member.getFullPath(), classpath)))
86 // continue nextResource;
89 if (nonJavaResources.length == nonJavaResourcesCounter) {
91 System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter);
93 nonJavaResources[nonJavaResourcesCounter++] = member;
96 if (nonJavaResources.length != nonJavaResourcesCounter) {
97 System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter);
99 return nonJavaResources;
100 } catch (CoreException e) {
101 throw new JavaModelException(e);
105 * Compute the non-package resources of this package fragment root.
107 * @exception JavaModelException The resource associated with this package fragment root does not exist
109 private Object[] computeNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) {
110 Object[] nonJavaResources = NO_NON_JAVA_RESOURCES;
112 // the underlying resource may be a folder or a project (in the case that the project folder
113 // is actually the package fragment root)
114 if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
116 computeFolderNonJavaResources(
117 (JavaProject)project,
118 (IContainer) underlyingResource,
119 handle.fullExclusionPatternChars());
121 } catch (JavaModelException e) {
123 return nonJavaResources;
126 * Returns an array of non-java resources contained in the receiver.
128 synchronized Object[] getNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) {
129 Object[] nonJavaResources = fNonJavaResources;
130 if (nonJavaResources == null) {
131 nonJavaResources = this.computeNonJavaResources(project, underlyingResource, handle);
132 fNonJavaResources = nonJavaResources;
134 return nonJavaResources;
137 * Returns the kind of this root.
139 public int getRootKind() {
143 * Retuns the SourceMapper for this root, or <code>null</code>
144 * if this root does not have attached source.
146 //protected synchronized SourceMapper getSourceMapper() {
147 // return this.sourceMapper;
149 private static boolean isClasspathEntry(IPath path, IClasspathEntry[] resolvedClasspath) {
150 for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
151 IClasspathEntry entry = resolvedClasspath[i];
152 if (entry.getPath().equals(path)) {
159 * Set the fNonJavaResources to res value
161 synchronized void setNonJavaResources(Object[] resources) {
162 fNonJavaResources = resources;
165 * Sets the kind of this root.
167 protected void setRootKind(int newRootKind) {
168 fRootKind = newRootKind;
171 * Sets the SourceMapper for this root.
173 //protected synchronized void setSourceMapper(SourceMapper mapper) {
174 // this.sourceMapper= mapper;