### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java,v retrieving revision 1.190 diff -u -r1.190 AnnotationTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 25 Nov 2008 09:57:46 -0000 1.190 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 7 Jan 2009 16:27:20 -0000 @@ -14,18 +14,29 @@ import java.io.IOException; import java.util.HashMap; import java.util.Hashtable; +import java.util.Locale; import java.util.Map; import junit.framework.Test; import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; +import org.eclipse.jdt.internal.compiler.IProblemFactory; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; -import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; +import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; public class AnnotationTest extends AbstractComparableTest { @@ -8679,4 +8690,49 @@ "}\n" }, ""); -}} +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906 +public void test265() { + INameEnvironment nameEnvironment = new FileSystem(Util.getJavaClassLibs(), new String[] {}, null); + IErrorHandlingPolicy errorHandlingPolicy = new IErrorHandlingPolicy() { + public boolean proceedOnErrors() { return true; } + public boolean stopOnFirstError() { return false; } + }; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + CompilerOptions compilerOptions = new CompilerOptions(options); + compilerOptions.performMethodsFullRecovery = false; + compilerOptions.performStatementsRecovery = false; + Requestor requestor = new Requestor(false, null /*no custom requestor*/, false, /* show category */ false /* show warning token*/); + requestor.outputPath = "bin/"; + IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); + + Compiler compiler = new Compiler(nameEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory); + compiler.options.produceReferenceInfo = true; + + String code = "@javax.xml.bind.annotation.XmlSchema(namespace = \"test\")\npackage testpack;\n"; + ICompilationUnit source = new CompilationUnit(code.toCharArray(), "testpack/package-info.java", null); + + // don't call compile as would be normally expected since that wipes out the lookup environment + // before we could query it. Use internal API resolve instead which can run a subset of the + // compilation steps for us. + + compiler.resolve (source, + true, // verifyMethods, + true, // boolean analyzeCode, + false // generateCode + ); + char [][] compoundName = new char [][] { "testpack".toCharArray(), "package-info".toCharArray()}; + ReferenceBinding type = compiler.lookupEnvironment.getType(compoundName); + AnnotationBinding[] annotations = null; + if (type != null && type.isValidBinding()) { + annotations = type.getAnnotations(); + } + assertTrue ("Annotations missing on package-info interface", annotations != null && annotations.length == 1); + assertEquals("Wrong annotation on package-info interface ", "@XmlSchema{ namespace = (String)\"test\"}", annotations[0].toString()); + nameEnvironment.cleanup(); + if (requestor.hasErrors) + System.err.print(requestor.problemLog); // problem log empty if no problems + compiler = null; +} +} #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java,v retrieving revision 1.65 diff -u -r1.65 Annotation.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java 5 Sep 2008 10:24:43 -0000 1.65 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java 7 Jan 2009 16:27:21 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -376,8 +376,12 @@ if (((ReferenceBinding)this.recipient).isAnnotationType()) { if ((metaTagBits & (TagBits.AnnotationForAnnotationType|TagBits.AnnotationForType)) != 0) break checkTargetCompatibility; - } else if ((metaTagBits & TagBits.AnnotationForType) != 0) + } else if ((metaTagBits & TagBits.AnnotationForType) != 0) { break checkTargetCompatibility; + } else if ((metaTagBits & TagBits.AnnotationForPackage) != 0) { + if (CharOperation.equals(((ReferenceBinding)this.recipient).sourceName, TypeConstants.PACKAGE_INFO_NAME)) + break checkTargetCompatibility; + } break; case Binding.METHOD : if (((MethodBinding)this.recipient).isConstructor()) { 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.83 diff -u -r1.83 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 3 Dec 2008 12:55:10 -0000 1.83 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 7 Jan 2009 16:27:21 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -342,9 +342,6 @@ } return; } - if (isPackageInfo() && this.types != null && this.currentPackage!= null && this.currentPackage.annotations != null) { - this.types[0].annotations = this.currentPackage.annotations; - } try { if (this.types != null) { for (int i = 0, count = this.types.length; i < count; i++) Index: compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java,v retrieving revision 1.123 diff -u -r1.123 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 27 Nov 2008 20:31:16 -0000 1.123 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 7 Jan 2009 16:27:21 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -100,6 +100,9 @@ declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface; firstIsSynthetic = true; } + // ensure the package annotations are copied over before resolution + if (this.referenceContext.currentPackage != null) + this.referenceContext.types[0].annotations = this.referenceContext.currentPackage.annotations; } recordQualifiedReference(this.currentPackageName); // always dependent on your own package }