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 |
} |