1 11 package org.eclipse.jdt.internal.core.builder; 12 13 import java.io.IOException ; 14 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.runtime.*; 17 18 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; 19 import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; 20 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 21 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; 22 import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; 23 import org.eclipse.jdt.internal.compiler.util.SuffixConstants; 24 import org.eclipse.jdt.internal.core.util.Util; 25 26 public class ClasspathDirectory extends ClasspathLocation { 27 28 IContainer binaryFolder; boolean isOutputFolder; 30 SimpleLookupTable directoryCache; 31 String [] missingPackageHolder = new String [1]; 32 AccessRuleSet accessRuleSet; 33 34 ClasspathDirectory(IContainer binaryFolder, boolean isOutputFolder, AccessRuleSet accessRuleSet) { 35 this.binaryFolder = binaryFolder; 36 this.isOutputFolder = isOutputFolder; 37 this.directoryCache = new SimpleLookupTable(5); 38 this.accessRuleSet = accessRuleSet; 39 } 40 41 public void cleanup() { 42 this.directoryCache = null; 43 } 44 45 String [] directoryList(String qualifiedPackageName) { 46 String [] dirList = (String []) directoryCache.get(qualifiedPackageName); 47 if (dirList == missingPackageHolder) return null; if (dirList != null) return dirList; 49 50 try { 51 IResource container = binaryFolder.findMember(qualifiedPackageName); if (container instanceof IContainer) { 53 IResource[] members = ((IContainer) container).members(); 54 dirList = new String [members.length]; 55 int index = 0; 56 for (int i = 0, l = members.length; i < l; i++) { 57 IResource m = members[i]; 58 if (m.getType() == IResource.FILE && org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(m.getName())) 59 dirList[index++] = m.getName(); 61 } 62 if (index < dirList.length) 63 System.arraycopy(dirList, 0, dirList = new String [index], 0, index); 64 directoryCache.put(qualifiedPackageName, dirList); 65 return dirList; 66 } 67 } catch(CoreException ignored) { 68 } 70 directoryCache.put(qualifiedPackageName, missingPackageHolder); 71 return null; 72 } 73 74 boolean doesFileExist(String fileName, String qualifiedPackageName, String qualifiedFullName) { 75 String [] dirList = directoryList(qualifiedPackageName); 76 if (dirList == null) return false; 78 for (int i = dirList.length; --i >= 0;) 79 if (fileName.equals(dirList[i])) 80 return true; 81 return false; 82 } 83 84 public boolean equals(Object o) { 85 if (this == o) return true; 86 if (!(o instanceof ClasspathDirectory)) return false; 87 88 ClasspathDirectory dir = (ClasspathDirectory) o; 89 if (this.accessRuleSet != dir.accessRuleSet) 90 if (this.accessRuleSet == null || !this.accessRuleSet.equals(dir.accessRuleSet)) 91 return false; 92 return this.binaryFolder.equals(dir.binaryFolder); 93 } 94 95 public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) { 96 if (!doesFileExist(binaryFileName, qualifiedPackageName, qualifiedBinaryFileName)) return null; 98 ClassFileReader reader = null; 99 try { 100 reader = Util.newClassFileReader(this.binaryFolder.getFile(new Path(qualifiedBinaryFileName))); 101 } catch (CoreException e) { 102 return null; 103 } catch (ClassFormatException e) { 104 return null; 105 } catch (IOException e) { 106 return null; 107 } 108 if (reader != null) { 109 if (this.accessRuleSet == null) 110 return new NameEnvironmentAnswer(reader, null); 111 String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); 112 return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray())); 113 } 114 return null; 115 } 116 117 public IPath getProjectRelativePath() { 118 return binaryFolder.getProjectRelativePath(); 119 } 120 121 protected boolean isExcluded(IResource resource) { 122 return false; 123 } 124 125 public boolean isOutputFolder() { 126 return isOutputFolder; 127 } 128 129 public boolean isPackage(String qualifiedPackageName) { 130 return directoryList(qualifiedPackageName) != null; 131 } 132 133 public void reset() { 134 this.directoryCache = new SimpleLookupTable(5); 135 } 136 137 public String toString() { 138 String start = "Binary classpath directory " + this.binaryFolder.getFullPath().toString(); if (this.accessRuleSet == null) 140 return start; 141 return start + " with " + this.accessRuleSet; } 143 144 public String debugPathString() { 145 return this.binaryFolder.getFullPath().toString(); 146 } 147 148 149 } 150 | Popular Tags |