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
24 boolean isOutputFolder;
25 String binaryLocation;
26 SimpleLookupTable directoryCache;
27 String[] missingPackageHolder = new String[1];
29 ClasspathDirectory(IContainer binaryFolder, boolean isOutputFolder) {
30 this.binaryFolder = binaryFolder;
31 this.isOutputFolder = isOutputFolder;
32 // IPath location = binaryFolder.getLocation();
33 // this.binaryLocation = location != null ? location.addTrailingSeparator().toString() : ""; //$NON-NLS-1$
34 this.binaryLocation = "";
35 this.directoryCache = new SimpleLookupTable(5);
38 public void cleanup() {
39 this.directoryCache = null;
42 String[] directoryList(String qualifiedPackageName) {
43 String[] dirList = (String[]) directoryCache.get(qualifiedPackageName);
44 if (dirList == missingPackageHolder) return null; // package exists in another classpath directory or jar
45 if (dirList != null) return dirList;
48 IResource container = binaryFolder.findMember(qualifiedPackageName); // this is a case-sensitive check
49 if (container instanceof IContainer) {
50 IResource[] members = ((IContainer) container).members();
51 dirList = new String[members.length];
53 for (int i = 0, l = members.length; i < l; i++) {
54 IResource m = members[i];
55 // if (m.getType() == IResource.FILE && Util.isClassFileName(m.getName()))
56 // // add exclusion pattern check here if we want to hide .class files
57 // dirList[index++] = m.getName();
59 if (index < dirList.length)
60 System.arraycopy(dirList, 0, dirList = new String[index], 0, index);
61 directoryCache.put(qualifiedPackageName, dirList);
64 } catch(CoreException ignored) {
66 directoryCache.put(qualifiedPackageName, missingPackageHolder);
70 boolean doesFileExist(String fileName, String qualifiedPackageName, String qualifiedFullName) {
71 String[] dirList = directoryList(qualifiedPackageName);
72 if (dirList == null) return false; // most common case
74 for (int i = dirList.length; --i >= 0;)
75 if (fileName.equals(dirList[i]))
80 public boolean equals(Object o) {
81 if (this == o) return true;
82 if (!(o instanceof ClasspathDirectory)) return false;
84 return binaryFolder.equals(((ClasspathDirectory) o).binaryFolder);
87 public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) {
88 if (!doesFileExist(binaryFileName, qualifiedPackageName, qualifiedBinaryFileName)) return null; // most common case
91 // ClassFileReader reader = ClassFileReader.read(binaryLocation + qualifiedBinaryFileName);
92 // if (reader != null) return new NameEnvironmentAnswer(reader);
93 // } catch (Exception e) {} // treat as if class file is missing
97 public IPath getProjectRelativePath() {
98 return binaryFolder.getProjectRelativePath();
101 public boolean isOutputFolder() {
102 return isOutputFolder;
105 public boolean isPackage(String qualifiedPackageName) {
106 return directoryList(qualifiedPackageName) != null;
109 public void reset() {
110 this.directoryCache = new SimpleLookupTable(5);
113 public String toString() {
114 return "Binary classpath directory " + binaryFolder.getFullPath().toString(); //$NON-NLS-1$