|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005, 2012 BEA Systems, Inc. and others |
2 |
* Copyright (c) 2005, 2008 BEA Systems, Inc. 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 7-13
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* sbandow@bea.com - initial API and implementation |
9 |
* sbandow@bea.com - initial API and implementation |
| 10 |
* IBM Corporation - Added test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=352949 |
10 |
* |
| 11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 12 |
|
12 |
|
| 13 |
package org.eclipse.jdt.apt.tests; |
13 |
package org.eclipse.jdt.apt.tests; |
|
Lines 37-42
Link Here
|
| 37 |
import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; |
37 |
import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; |
| 38 |
import com.sun.mirror.declaration.AnnotationValue; |
38 |
import com.sun.mirror.declaration.AnnotationValue; |
| 39 |
import com.sun.mirror.declaration.Declaration; |
39 |
import com.sun.mirror.declaration.Declaration; |
|
|
40 |
import com.sun.mirror.declaration.PackageDeclaration; |
| 40 |
import com.sun.mirror.declaration.TypeDeclaration; |
41 |
import com.sun.mirror.declaration.TypeDeclaration; |
| 41 |
import com.sun.mirror.util.SourcePosition; |
42 |
import com.sun.mirror.util.SourcePosition; |
| 42 |
|
43 |
|
|
Lines 166-171
Link Here
|
| 166 |
" public class Inner{} \n" + |
167 |
" public class Inner{} \n" + |
| 167 |
"}"; |
168 |
"}"; |
| 168 |
|
169 |
|
|
|
170 |
|
| 169 |
final IPath fooPath = env.addClass(srcRoot, "test", "Foo", codeFoo); |
171 |
final IPath fooPath = env.addClass(srcRoot, "test", "Foo", codeFoo); |
| 170 |
fullBuild( project.getFullPath() ); |
172 |
fullBuild( project.getFullPath() ); |
| 171 |
|
173 |
|
|
Lines 264-270
Link Here
|
| 264 |
} |
266 |
} |
| 265 |
|
267 |
|
| 266 |
public void testPackageInfo() { |
268 |
public void testPackageInfo() { |
| 267 |
PackageInfoProc p = new PackageInfoProc(); |
269 |
PackageInfoProc p = new PackageInfoProc(true); |
| 268 |
GenericFactory.setProcessor(p); |
270 |
GenericFactory.setProcessor(p); |
| 269 |
|
271 |
|
| 270 |
IProject project = env.getProject( getProjectName() ); |
272 |
IProject project = env.getProject( getProjectName() ); |
|
Lines 281-287
Link Here
|
| 281 |
"@interface PkgAnnotation {\n" + |
283 |
"@interface PkgAnnotation {\n" + |
| 282 |
" String value() default \"def\";\n" + |
284 |
" String value() default \"def\";\n" + |
| 283 |
"}\n"; |
285 |
"}\n"; |
| 284 |
env.addClass(srcRoot, "pkg", "pkgAnnotation", annContents); |
286 |
env.addClass(srcRoot, "pkg", "PkgAnnotation", annContents); |
|
|
287 |
fullBuild( project.getFullPath() ); |
| 288 |
expectingNoProblems(); |
| 289 |
|
| 290 |
assertTrue("Processor not invoked", p.called); |
| 291 |
} |
| 292 |
|
| 293 |
public void testPackageInfoOfOtherClass() { |
| 294 |
PackageInfoProc p = new PackageInfoProc(false); |
| 295 |
GenericFactory.setProcessor(p); |
| 296 |
|
| 297 |
IProject project = env.getProject( getProjectName() ); |
| 298 |
IPath srcRoot = getSourcePath(); |
| 299 |
IPath pkg = env.addPackage(srcRoot, "pkg"); |
| 300 |
String contents = "@PkgAnnotation\n" + |
| 301 |
"package pkg;"; |
| 302 |
env.addFile(pkg, "package-info.java", contents); |
| 303 |
String annContents = |
| 304 |
"package pkg;\n" + |
| 305 |
"\n" + |
| 306 |
"@interface PkgAnnotation {\n" + |
| 307 |
" String value() default \"def\";\n" + |
| 308 |
"}\n"; |
| 309 |
env.addClass(srcRoot, "pkg", "PkgAnnotation", annContents); |
| 310 |
contents = "package otherpkg;\n"+ |
| 311 |
"import org.eclipse.jdt.apt.tests.annotations.generic.*;\n"+ |
| 312 |
"@GenericAnnotation\n" + |
| 313 |
"class Test{}"; |
| 314 |
env.addClass(srcRoot, "otherpkg", "Test", contents); |
| 285 |
fullBuild( project.getFullPath() ); |
315 |
fullBuild( project.getFullPath() ); |
| 286 |
expectingNoProblems(); |
316 |
expectingNoProblems(); |
| 287 |
|
317 |
|
|
Lines 329-335
Link Here
|
| 329 |
static class PackageInfoProc extends AbstractGenericProcessor { |
359 |
static class PackageInfoProc extends AbstractGenericProcessor { |
| 330 |
|
360 |
|
| 331 |
boolean called; |
361 |
boolean called; |
| 332 |
|
362 |
boolean annotInSamePkg; |
|
|
363 |
public PackageInfoProc(boolean annotInSamePkg) { |
| 364 |
this.annotInSamePkg = annotInSamePkg; |
| 365 |
} |
| 333 |
public void _process() { |
366 |
public void _process() { |
| 334 |
called = true; |
367 |
called = true; |
| 335 |
AnnotationTypeDeclaration annoDecl = (AnnotationTypeDeclaration)env.getTypeDeclaration("pkg.PkgAnnotation"); |
368 |
AnnotationTypeDeclaration annoDecl = (AnnotationTypeDeclaration)env.getTypeDeclaration("pkg.PkgAnnotation"); |
|
Lines 339-358
Link Here
|
| 339 |
// don't return the package declaration - well, apt is doing that.. |
372 |
// don't return the package declaration - well, apt is doing that.. |
| 340 |
assertTrue(annotatedDecls == null || annotatedDecls.size() == 0); |
373 |
assertTrue(annotatedDecls == null || annotatedDecls.size() == 0); |
| 341 |
|
374 |
|
| 342 |
//TODO: test to support package annotation |
375 |
PackageDeclaration pdCode = env.getPackage("pkg"); |
| 343 |
// PackageDeclaration pdCode = env.getPackage("pkg"); |
376 |
for (AnnotationMirror am : pdCode.getAnnotationMirrors()) { |
| 344 |
// for (AnnotationMirror am : pdCode.getAnnotationMirrors()) { |
377 |
if ("GenericAnnotation".equals(am.getAnnotationType().getDeclaration().getSimpleName())) { |
| 345 |
// if ("GenericAnnotation".equals(am.getAnnotationType().getDeclaration().getSimpleName())) { |
378 |
continue; |
| 346 |
// continue; |
379 |
} |
| 347 |
// } |
380 |
if (this.annotInSamePkg) { |
| 348 |
// assertTrue(null != am.getPosition()); |
381 |
assertTrue(null != am.getPosition()); |
| 349 |
// AnnotationTypeDeclaration atd = am.getAnnotationType().getDeclaration(); |
382 |
}else { |
| 350 |
// assertTrue(null != atd.getPosition()); |
383 |
// package-info.java in not getting processed |
| 351 |
// for (Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> entry : am.getElementValues().entrySet()) { |
384 |
// and hence this is OK.. |
| 352 |
// assertNotNull(entry.getKey().getPosition()); |
385 |
assertTrue(null == am.getPosition()); |
| 353 |
// assertNotNull(entry.getKey().getDefaultValue().getPosition()); |
386 |
} |
| 354 |
// } |
387 |
AnnotationTypeDeclaration atd = am.getAnnotationType().getDeclaration(); |
| 355 |
// } |
388 |
assertTrue(null != atd.getPosition()); |
|
|
389 |
for (Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> entry : am.getElementValues().entrySet()) { |
| 390 |
assertNotNull(entry.getKey().getPosition()); |
| 391 |
assertNotNull(entry.getKey().getDefaultValue().getPosition()); |
| 392 |
} |
| 393 |
} |
| 356 |
} |
394 |
} |
| 357 |
} |
395 |
} |
| 358 |
|
396 |
|