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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-2 / +58 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 8679-8682 Link Here
8679
			"}\n"
8690
			"}\n"
8680
		},
8691
		},
8681
		"");
8692
		"");
8682
}}
8693
}
8694
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906 
8695
public void test265() {
8696
	INameEnvironment nameEnvironment = new FileSystem(Util.getJavaClassLibs(), new String[] {}, null);
8697
	IErrorHandlingPolicy errorHandlingPolicy = new IErrorHandlingPolicy() {
8698
		public boolean proceedOnErrors() { return true; }
8699
		public boolean stopOnFirstError() { return false; }
8700
	};
8701
	Map options = getCompilerOptions();
8702
	options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED);
8703
	CompilerOptions compilerOptions = new CompilerOptions(options);
8704
	compilerOptions.performMethodsFullRecovery = false;
8705
	compilerOptions.performStatementsRecovery = false;
8706
	Requestor requestor = new Requestor(false, null /*no custom requestor*/, false, /* show category */ false /* show warning token*/);
8707
	requestor.outputPath = "bin/";
8708
	IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
8709
8710
	Compiler compiler = new Compiler(nameEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory);
8711
	compiler.options.produceReferenceInfo = true;
8712
8713
	String code = "@javax.xml.bind.annotation.XmlSchema(namespace = \"test\")\npackage testpack;\n";
8714
	ICompilationUnit source = new CompilationUnit(code.toCharArray(), "testpack/package-info.java", null);
8715
8716
	// don't call compile as would be normally expected since that wipes out the lookup environment
8717
	// before we could query it. Use internal API resolve instead which can run a subset of the
8718
	// compilation steps for us.
8719
8720
	compiler.resolve (source,
8721
		true, // verifyMethods,
8722
		true, // boolean analyzeCode,
8723
		false // generateCode
8724
	);
8725
	char [][] compoundName = new char [][] { "testpack".toCharArray(), "package-info".toCharArray()};
8726
	ReferenceBinding type = compiler.lookupEnvironment.getType(compoundName);
8727
	AnnotationBinding[] annotations = null;
8728
	if (type != null && type.isValidBinding()) {
8729
		annotations = type.getAnnotations();
8730
	}
8731
	assertTrue ("Annotations missing on package-info interface", annotations != null && annotations.length == 1);
8732
	assertEquals("Wrong annotation on package-info interface ", "@XmlSchema{ namespace = (String)\"test\"}", annotations[0].toString());
8733
	nameEnvironment.cleanup();
8734
	if (requestor.hasErrors)
8735
		System.err.print(requestor.problemLog); // problem log empty if no problems
8736
	compiler = null;
8737
}
8738
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java (-2 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 376-383 Link Here
376
						if (((ReferenceBinding)this.recipient).isAnnotationType()) {
376
						if (((ReferenceBinding)this.recipient).isAnnotationType()) {
377
							if ((metaTagBits & (TagBits.AnnotationForAnnotationType|TagBits.AnnotationForType)) != 0)
377
							if ((metaTagBits & (TagBits.AnnotationForAnnotationType|TagBits.AnnotationForType)) != 0)
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 if ((metaTagBits & TagBits.AnnotationForPackage) != 0) {
382
							if (CharOperation.equals(((ReferenceBinding)this.recipient).sourceName, TypeConstants.PACKAGE_INFO_NAME))
383
								break checkTargetCompatibility;
384
						}
381
						break;
385
						break;
382
					case Binding.METHOD :
386
					case Binding.METHOD :
383
						if (((MethodBinding)this.recipient).isConstructor()) {
387
						if (((MethodBinding)this.recipient).isConstructor()) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (-4 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 342-350 Link Here
342
		}
342
		}
343
		return;
343
		return;
344
	}
344
	}
345
	if (isPackageInfo() && this.types != null && this.currentPackage!= null && this.currentPackage.annotations != null) {
346
		this.types[0].annotations = this.currentPackage.annotations;
347
	}
348
	try {
345
	try {
349
		if (this.types != null) {
346
		if (this.types != null) {
350
			for (int i = 0, count = this.types.length; i < count; i++)
347
			for (int i = 0, count = this.types.length; i < count; i++)
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 100-105 Link Here
100
				declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
100
				declaration.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccInterface;
101
				firstIsSynthetic = true;
101
				firstIsSynthetic = true;
102
			}
102
			}
103
			// ensure the package annotations are copied over before resolution
104
			if (this.referenceContext.currentPackage != null)
105
				this.referenceContext.types[0].annotations = this.referenceContext.currentPackage.annotations;
103
		}
106
		}
104
		recordQualifiedReference(this.currentPackageName); // always dependent on your own package
107
		recordQualifiedReference(this.currentPackageName); // always dependent on your own package
105
	}
108
	}

Return to bug 258906