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[] { |