### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/Javadoc.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Javadoc.java,v retrieving revision 1.62 diff -u -r1.62 Javadoc.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Javadoc.java 6 Nov 2008 15:00:06 -0000 1.62 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Javadoc.java 19 Nov 2008 08:35:07 -0000 @@ -235,7 +235,9 @@ * Resolve compilation unit javadoc */ public void resolve(CompilationUnitScope unitScope) { - // do nothing + // Do nothing - This is to mimic the SDK's javadoc tool behavior, which neither + // sanity checks nor generates documentation using comments at the CU scope + // (unless the unit happens to be package-info.java - in which case we don't come here.) } /* Index: compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java,v retrieving revision 1.81 diff -u -r1.81 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 5 Sep 2008 10:24:43 -0000 1.81 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 19 Nov 2008 08:35:07 -0000 @@ -513,15 +513,18 @@ syntheticTypeDeclaration.javadoc = new Javadoc(syntheticTypeDeclaration.declarationSourceStart, syntheticTypeDeclaration.declarationSourceStart); } syntheticTypeDeclaration.resolve(this.scope); - // resolve annotations if any - if (this.currentPackage!= null && this.currentPackage.annotations != null) { + // resolve annotations if any, skip this step if we don't have a valid scope due to an earlier error. (bug 252555) + if (this.currentPackage!= null && this.currentPackage.annotations != null && syntheticTypeDeclaration.staticInitializerScope != null) { resolveAnnotations(syntheticTypeDeclaration.staticInitializerScope, this.currentPackage.annotations, this.scope.fPackage); } /* - * resolve javadoc package if any + * resolve javadoc package if any, skip this step if we don't have a valid scope due to an earlier error (bug 252555) * we do it now and the javadoc in the fake type won't be resolved */ - if (this.javadoc != null) { + + // The peculiar usage of MethodScope to resolve the package level javadoc is because the CU level resolve method + // is a NOP to mimic Javadoc's behavior and can't be used as such. + if (this.javadoc != null && syntheticTypeDeclaration.staticInitializerScope != null) { this.javadoc.resolve(syntheticTypeDeclaration.staticInitializerScope); } startingTypeIndex = 1; @@ -664,10 +667,12 @@ final TypeDeclaration syntheticTypeDeclaration = this.types[0]; // resolve javadoc package if any final MethodScope methodScope = syntheticTypeDeclaration.staticInitializerScope; - if (this.javadoc != null) { + // Don't traverse in null scope and invite trouble a la bug 252555. + if (this.javadoc != null && methodScope != null) { this.javadoc.traverse(visitor, methodScope); } - if (this.currentPackage != null) { + // Don't traverse in null scope and invite trouble a la bug 252555. + if (this.currentPackage != null && methodScope != null) { final Annotation[] annotations = this.currentPackage.annotations; if (annotations != null) { int annotationsLength = annotations.length; #P org.eclipse.jdt.core.tests.builder Index: src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java,v retrieving revision 1.9 diff -u -r1.9 PackageInfoTest.java --- src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java 27 Jun 2008 16:02:02 -0000 1.9 +++ src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java 19 Nov 2008 08:35:09 -0000 @@ -148,6 +148,43 @@ // expectingOnlyProblemsFor(packageInfoPath); expectingOnlySpecificProblemFor(packageInfoPath, new Problem("testcase/package-info.java", "The declared package \"\" does not match the expected package \"testcase\"", packageInfoPath, 0, 0, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ } + +public void test004() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath otherRoot = env.addPackageFragmentRoot(projectPath, "test"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addPackage(root, "my.foo"); + env.addPackage(otherRoot, "my.foo"); + + IPath packageInfoPath = env.addFile(root, "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "/**\n" + + "* A demo package for foo.\n" + + "*/\n" + + "package my.foo;\n" + ); + + IPath otherPackageInfoPath = env.addFile(otherRoot, "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "/**\n" + + "* A demo package for foo.\n" + + "*/\n" + + "package my.foo;\n" + ); + + incrementalBuild(projectPath); + expectingOnlySpecificProblemFor(otherPackageInfoPath, new Problem("my/foo/package-info.java", "The type package-info is already defined", otherPackageInfoPath, 0, 0, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ +} + + protected void assertSourceEquals(String message, String expected, String actual) { if (actual == null) { assertEquals(message, expected, null);