View | Details | Raw Unified | Return to bug 258906 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java (+9 lines)
Lines 378-383 Link Here
378
							break checkTargetCompatibility;
378
							break checkTargetCompatibility;
379
						} else if ((metaTagBits & TagBits.AnnotationForType) != 0)
379
						} else if ((metaTagBits & TagBits.AnnotationForType) != 0)
380
							break checkTargetCompatibility;
380
							break checkTargetCompatibility;
381
						else {
382
							// Annotations that target a package are kosher for the synthetic interface type
383
							// package-info. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906
384
							char [] name = ((ReferenceBinding)this.recipient).sourceName();
385
							if (name != null && CharOperation.equals(name, TypeConstants.PACKAGE_INFO_NAME)) {
386
								if ((metaTagBits & TagBits.AnnotationForPackage) != 0)
387
									break checkTargetCompatibility;
388
							}
389
						}
381
						break;
390
						break;
382
					case Binding.METHOD :
391
					case Binding.METHOD :
383
						if (((MethodBinding)this.recipient).isConstructor()) {
392
						if (((MethodBinding)this.recipient).isConstructor()) {
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (+12 lines)
Lines 2837-2842 Link Here
2837
		declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
2837
		declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
2838
		this.compilationUnit.types[0] = declaration;
2838
		this.compilationUnit.types[0] = declaration;
2839
		declaration.javadoc = this.compilationUnit.javadoc;
2839
		declaration.javadoc = this.compilationUnit.javadoc;
2840
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906 
2841
		if (this.compilationUnit.currentPackage != null) {
2842
			declaration.annotations = this.compilationUnit.currentPackage.annotations;
2843
		}
2840
	}
2844
	}
2841
}
2845
}
2842
protected void consumeEmptyMemberValueArrayInitializer() {
2846
protected void consumeEmptyMemberValueArrayInitializer() {
Lines 4046-4051 Link Here
4046
		declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
4050
		declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
4047
		this.compilationUnit.types[0] = declaration;
4051
		this.compilationUnit.types[0] = declaration;
4048
		declaration.javadoc = this.compilationUnit.javadoc;
4052
		declaration.javadoc = this.compilationUnit.javadoc;
4053
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906
4054
		if (this.compilationUnit.currentPackage != null) {
4055
			declaration.annotations = this.compilationUnit.currentPackage.annotations;
4056
		}
4049
	}
4057
	}
4050
}
4058
}
4051
protected void consumeInternalCompilationUnitWithTypes() {
4059
protected void consumeInternalCompilationUnitWithTypes() {
Lines 4066-4071 Link Here
4066
			declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
4074
			declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
4067
			this.compilationUnit.types[0] = declaration;
4075
			this.compilationUnit.types[0] = declaration;
4068
			declaration.javadoc = this.compilationUnit.javadoc;
4076
			declaration.javadoc = this.compilationUnit.javadoc;
4077
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906
4078
			if (this.compilationUnit.currentPackage != null) {
4079
				declaration.annotations = this.compilationUnit.currentPackage.annotations;
4080
			}
4069
		} else {
4081
		} else {
4070
			this.compilationUnit.types = new TypeDeclaration[length];
4082
			this.compilationUnit.types = new TypeDeclaration[length];
4071
			this.astPtr -= length;
4083
			this.astPtr -= length;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-1 / +84 lines)
Lines 14-31 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.Hashtable;
16
import java.util.Hashtable;
17
import java.util.Locale;
17
import java.util.Map;
18
import java.util.Map;
18
19
19
import junit.framework.Test;
20
import junit.framework.Test;
20
21
21
import org.eclipse.jdt.core.ToolFactory;
22
import org.eclipse.jdt.core.ToolFactory;
23
import org.eclipse.jdt.core.tests.util.Util;
22
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
24
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
25
import org.eclipse.jdt.internal.compiler.Compiler;
26
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
27
import org.eclipse.jdt.internal.compiler.IProblemFactory;
23
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
28
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
29
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
30
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
24
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
31
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
32
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
33
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
34
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
35
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
27
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
36
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
28
import org.eclipse.jdt.core.tests.util.Util;
37
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
39
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
29
40
30
public class AnnotationTest extends AbstractComparableTest {
41
public class AnnotationTest extends AbstractComparableTest {
31
42
Lines 70-75 Link Here
70
		this.reportMissingJavadocComments = null;
81
		this.reportMissingJavadocComments = null;
71
	}
82
	}
72
83
84
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906 
85
	public void testPackageAnnotations() {
86
87
		Map options = getCompilerOptions();
88
		options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED);
89
90
		IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
91
		Requestor requestor =
92
			new Requestor(
93
					false,
94
					null /*no custom requestor*/,
95
					false, /* show category */
96
					false /* show warning token*/);
97
98
		requestor.outputPath = "bin/";
99
100
		String[] classpath = Util.getJavaClassLibs();
101
102
		INameEnvironment nameEnvironment = new FileSystem(classpath, new String[] {}, null);
103
		IErrorHandlingPolicy errorHandlingPolicy =
104
			new IErrorHandlingPolicy() {
105
			public boolean proceedOnErrors() {
106
				return true;
107
			}
108
			public boolean stopOnFirstError() {
109
				return false;
110
			}
111
		};
112
113
		CompilerOptions compilerOptions = new CompilerOptions(options);
114
		compilerOptions.performMethodsFullRecovery = false;
115
		compilerOptions.performStatementsRecovery = false;
116
		Compiler compiler =
117
			new Compiler(
118
					nameEnvironment,
119
					errorHandlingPolicy,
120
					compilerOptions,
121
					requestor,
122
					problemFactory);
123
		compiler.options.produceReferenceInfo = true;
124
125
		String code = "@javax.xml.bind.annotation.XmlSchema(namespace = \"test\")\npackage testpack;\n";
126
		ICompilationUnit source = new CompilationUnit(code.toCharArray(), "testpack/package-info.java", null);
127
128
		// don't call compile as would be normally expected since that wipes out the lookup environment
129
		// before we could query it. Use internal API resolve instead which can run a subset of the
130
		// compilation steps for us.
131
132
		compiler.resolve (source,
133
				true, // verifyMethods,
134
				true, // boolean analyzeCode,
135
				false // generateCode
136
		);
137
		char [][] compoundName = new char [][] { "testpack".toCharArray(), "package-info".toCharArray()};
138
		ReferenceBinding type = compiler.lookupEnvironment.getType(compoundName);
139
		AnnotationBinding[] annotations = null;
140
		if (type != null && type.isValidBinding()) {
141
			annotations = type.getAnnotations();
142
		}
143
		assertTrue ("Annotations missing on package-info interface", 
144
				annotations != null && annotations.length == 1);
145
		String actual = annotations[0].toString();
146
147
		assertEquals("Wrong annotation on package-info interface ",
148
				"@XmlSchema{ namespace = (String)\"test\"}",
149
				actual);
150
		nameEnvironment.cleanup();
151
		if (requestor.hasErrors)
152
			System.err.print(requestor.problemLog); // problem log empty if no problems
153
		compiler = null;
154
	}
155
	
73
	public void test001() {
156
	public void test001() {
74
		this.runConformTest(
157
		this.runConformTest(
75
			new String[] {
158
			new String[] {

Return to bug 258906