### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java,v retrieving revision 1.37 diff -u -r1.37 ClasspathJar.java --- batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java 28 Mar 2006 20:30:01 -0000 1.37 +++ batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java 4 Apr 2006 20:14:51 -0000 @@ -19,8 +19,10 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.util.Util; public class ClasspathJar extends ClasspathLocation { @@ -30,24 +32,60 @@ private Hashtable packageCache; private char[] normalizedPath; -public ClasspathJar(File file) throws IOException { - this(file, true, null); -} -public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet) { +public ClasspathJar(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet, int mode, String encoding) { super(accessRuleSet); this.file = file; this.closeZipFileAtEnd = closeZipFileAtEnd; + this.mode = mode; } - public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (!isPackage(qualifiedPackageName)) return null; // most common case + if (this.mode == ClasspathLocation.SOURCE) { + ZipEntry sourceEntry = this.zipFile.getEntry(qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java); + if (sourceEntry != null) { + ZipEntry binaryEntry = this.zipFile.getEntry(qualifiedBinaryFileName); + if (binaryEntry != null) { + if (sourceEntry.getTime() > binaryEntry.getTime()) { + try { + return new NameEnvironmentAnswer(new CompilationUnit(Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry), -1, this.encoding), + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java, this.encoding), + fetchAccessRestriction(qualifiedBinaryFileName)); + } catch (IOException e) { + // treat as if source file is missing + } + } else { + try { + ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); + if (reader != null) return new NameEnvironmentAnswer(reader, + fetchAccessRestriction(qualifiedBinaryFileName)); + } catch(ClassFormatException e) { + // treat as if class file is missing + } catch (IOException e) { + // treat as if class file is missing + } + } + } else { + try { + return new NameEnvironmentAnswer(new CompilationUnit(Util.getInputStreamAsCharArray(this.zipFile.getInputStream(sourceEntry), -1, this.encoding), + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java, this.encoding), + fetchAccessRestriction(qualifiedBinaryFileName)); + } catch (IOException e) { + // treat as if source file is missing + } + } + } + return null; + } + try { ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); if (reader != null) return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName)); - } catch (Exception e) { + } catch(ClassFormatException e) { + // treat as if class file is missing + } catch (IOException e) { // treat as if class file is missing } return null; Index: batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java,v retrieving revision 1.37 diff -u -r1.37 FileSystem.java --- batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java 28 Mar 2006 20:30:01 -0000 1.37 +++ batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java 4 Apr 2006 20:14:51 -0000 @@ -56,18 +56,12 @@ classPathNames is a collection is Strings representing the full path of each class path initialFileNames is a collection is Strings, the trailing '.java' will be removed if its not already. */ - public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding) { - this(classpathNames, initialFileNames, encoding, null); -} -public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, int[] classpathDirectoryModes) { final int classpathSize = classpathNames.length; this.classpaths = new Classpath[classpathSize]; int counter = 0; for (int i = 0; i < classpathSize; i++) { - Classpath classpath = getClasspath(classpathNames[i], encoding, - classpathDirectoryModes == null ? 0 - : classpathDirectoryModes[i], null); + Classpath classpath = getClasspath(classpathNames[i], encoding, null); try { classpath.initialize(); this.classpaths[counter++] = classpath; @@ -99,20 +93,21 @@ } initializeKnownFileNames(initialFileNames); } -static Classpath getClasspath(String classpathName, String encoding, - int classpathDirectoryMode, AccessRuleSet accessRuleSet) { +static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet) { + return getClasspath(classpathName, encoding, ClasspathLocation.SOURCE | ClasspathLocation.BINARY, accessRuleSet); +} +static Classpath getClasspath(String classpathName, String encoding, int mode, AccessRuleSet accessRuleSet) { Classpath result = null; File file = new File(convertPathSeparators(classpathName)); if (file.isDirectory()) { if (file.exists()) { - result = new ClasspathDirectory(file, encoding, - classpathDirectoryMode, accessRuleSet); + result = new ClasspathDirectory(file, encoding, mode, accessRuleSet); } } else { String lowercaseClasspathName = classpathName.toLowerCase(); if (lowercaseClasspathName.endsWith(SUFFIX_STRING_jar) || lowercaseClasspathName.endsWith(SUFFIX_STRING_zip)) { - result = new ClasspathJar(file, true, accessRuleSet); + result = new ClasspathJar(file, true, accessRuleSet, mode, encoding); // will throw an IOException if file does not exist } } @@ -211,9 +206,6 @@ typeName); return null; } -public ClasspathJar getClasspathJar(File file) throws IOException { - return new ClasspathJar(file, true, null); -} public boolean isPackage(char[][] compoundName, char[] packageName) { String qualifiedPackageName = new String(CharOperation.concatWith(compoundName, packageName, '/')); String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v retrieving revision 1.242 diff -u -r1.242 Main.java --- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 3 Apr 2006 17:22:11 -0000 1.242 +++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 4 Apr 2006 20:14:51 -0000 @@ -1257,16 +1257,13 @@ "template.restrictedAccess.field", //$NON-NLS-1$ new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, templates); - FileSystem.Classpath currentClasspath = FileSystem - .getClasspath(currentClasspathName, - customEncoding, 0, accessRuleSet); + FileSystem.Classpath currentClasspath = FileSystem.getClasspath( + currentClasspathName, + customEncoding, + isSource ? ClasspathLocation.SOURCE : ClasspathLocation.BINARY | ClasspathLocation.SOURCE, + accessRuleSet); if (currentClasspath != null) { paths.add(currentClasspath); - if (isSource && currentClasspath instanceof ClasspathDirectory) { - ((ClasspathDirectory) currentClasspath).mode = - ClasspathDirectory.SOURCE; - // TODO may consider adding this attribute to other classpath natures - } } else { this.logger.logIncorrectClasspath(currentClasspathName); // we go on anyway @@ -2378,8 +2375,8 @@ for (int j = 0, max2 = current.length; j < max2; j++) { FileSystem.Classpath classpath = FileSystem.getClasspath( - current[j].getAbsolutePath(), - null, 0, null); + current[j].getAbsolutePath(), + null, null); if (classpath != null) { bootclasspaths.add(classpath); } @@ -2402,14 +2399,14 @@ String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ if ((classProp == null) || (classProp.length() == 0)) { this.logger.logNoClasspath(); - classpaths.add(FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, 0, null));//$NON-NLS-1$ + classpaths.add(FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null));//$NON-NLS-1$ } else { StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); String token; while (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); FileSystem.Classpath currentClasspath = FileSystem - .getClasspath(token, customEncoding, 0, null); + .getClasspath(token, customEncoding, null); if (currentClasspath != null) { classpaths.add(currentClasspath); } else { @@ -2471,7 +2468,7 @@ FileSystem.Classpath classpath = FileSystem.getClasspath( current[j].getAbsolutePath(), - null, 0, null); + null, null); if (classpath != null) { extdirsClasspaths.add(classpath); } Index: batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java,v retrieving revision 1.3 diff -u -r1.3 ClasspathLocation.java --- batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java 6 Dec 2005 16:21:53 -0000 1.3 +++ batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java 4 Apr 2006 20:14:51 -0000 @@ -20,7 +20,13 @@ public abstract class ClasspathLocation implements FileSystem.Classpath, SuffixConstants { + public static final int SOURCE = 1; + public static final int BINARY = 2; + + protected int mode; // ability to only consider one kind of files (source vs. binaries), by default use both + private AccessRuleSet accessRuleSet; + protected String encoding; // only useful if referenced in the source path public ClasspathLocation(AccessRuleSet accessRuleSet) { this.accessRuleSet = accessRuleSet; Index: batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java,v retrieving revision 1.37 diff -u -r1.37 ClasspathDirectory.java --- batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java 28 Mar 2006 20:30:01 -0000 1.37 +++ batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java 4 Apr 2006 20:14:51 -0000 @@ -26,30 +26,16 @@ private String path; private Hashtable directoryCache; private String[] missingPackageHolder = new String[1]; -private String encoding; -public int mode; // ability to only consider one kind of files (source vs. binaries), by default use both - -public static final int SOURCE = 1; -public static final int BINARY = 2; ClasspathDirectory(File directory, String encoding, int mode, AccessRuleSet accessRuleSet) { super(accessRuleSet); - if (mode == 0){ - this.mode = SOURCE | BINARY; - } - else { - this.mode = mode; - } + this.mode = mode; this.path = directory.getAbsolutePath(); if (!this.path.endsWith(File.separator)) this.path += File.separator; this.directoryCache = new Hashtable(11); this.encoding = encoding; } - -ClasspathDirectory(File directory, String encoding) { - this(directory, encoding, SOURCE | BINARY, null); // by default consider both sources and binaries -} String[] directoryList(String qualifiedPackageName) { String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName); if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar @@ -112,8 +98,7 @@ } if (binaryExists) { try { - ClassFileReader reader = ClassFileReader.read(this.path - + qualifiedBinaryFileName); + ClassFileReader reader = ClassFileReader.read(this.path + qualifiedBinaryFileName); if (reader != null) return new NameEnvironmentAnswer( reader,