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.builder;
13 import net.sourceforge.phpdt.internal.compiler.env.NameEnvironmentAnswer;
14 import net.sourceforge.phpdt.internal.core.util.SimpleLookupTable;
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;
21 class ClasspathDirectory extends ClasspathLocation {
23 IContainer binaryFolder; // includes .class files for a single directory
25 boolean isOutputFolder;
27 String binaryLocation;
29 SimpleLookupTable directoryCache;
31 String[] missingPackageHolder = new String[1];
33 ClasspathDirectory(IContainer binaryFolder, boolean isOutputFolder) {
34 this.binaryFolder = binaryFolder;
35 this.isOutputFolder = isOutputFolder;
36 // IPath location = binaryFolder.getLocation();
37 // this.binaryLocation = location != null ?
38 // location.addTrailingSeparator().toString() : ""; //$NON-NLS-1$
39 this.binaryLocation = "";
40 this.directoryCache = new SimpleLookupTable(5);
43 public void cleanup() {
44 this.directoryCache = null;
47 String[] directoryList(String qualifiedPackageName) {
48 String[] dirList = (String[]) directoryCache.get(qualifiedPackageName);
49 if (dirList == missingPackageHolder)
50 return null; // package exists in another classpath directory or
56 IResource container = binaryFolder.findMember(qualifiedPackageName); // this
60 if (container instanceof IContainer) {
61 IResource[] members = ((IContainer) container).members();
62 dirList = new String[members.length];
64 for (int i = 0, l = members.length; i < l; i++) {
65 IResource m = members[i];
66 // if (m.getType() == IResource.FILE &&
67 // ProjectPrefUtil.isClassFileName(m.getName()))
68 // // add exclusion pattern check here if we want to hide
70 // dirList[index++] = m.getName();
72 if (index < dirList.length)
73 System.arraycopy(dirList, 0, dirList = new String[index],
75 directoryCache.put(qualifiedPackageName, dirList);
78 } catch (CoreException ignored) {
80 directoryCache.put(qualifiedPackageName, missingPackageHolder);
84 boolean doesFileExist(String fileName, String qualifiedPackageName,
85 String qualifiedFullName) {
86 String[] dirList = directoryList(qualifiedPackageName);
88 return false; // most common case
90 for (int i = dirList.length; --i >= 0;)
91 if (fileName.equals(dirList[i]))
96 public boolean equals(Object o) {
99 if (!(o instanceof ClasspathDirectory))
102 return binaryFolder.equals(((ClasspathDirectory) o).binaryFolder);
105 public NameEnvironmentAnswer findClass(String binaryFileName,
106 String qualifiedPackageName, String qualifiedBinaryFileName) {
107 if (!doesFileExist(binaryFileName, qualifiedPackageName,
108 qualifiedBinaryFileName))
109 return null; // most common case
112 // ClassFileReader reader = ClassFileReader.read(binaryLocation +
113 // qualifiedBinaryFileName);
114 // if (reader != null) return new NameEnvironmentAnswer(reader);
115 // } catch (Exception e) {} // treat as if class file is missing
119 public IPath getProjectRelativePath() {
120 return binaryFolder.getProjectRelativePath();
123 public boolean isOutputFolder() {
124 return isOutputFolder;
127 public boolean isPackage(String qualifiedPackageName) {
128 return directoryList(qualifiedPackageName) != null;
131 public void reset() {
132 this.directoryCache = new SimpleLookupTable(5);
135 public String toString() {
136 return "Binary classpath directory " + binaryFolder.getFullPath().toString(); //$NON-NLS-1$