src/share/classes/com/sun/tools/javac/comp/Annotate.java

changeset 1629
f427043f8c65
parent 1521
71f35e4b93a5
child 1755
ddb4a2bfcd82
equal deleted inserted replaced
1628:5ddecb91d843 1629:f427043f8c65
382 MethodSymbol containerValueSymbol = null; 382 MethodSymbol containerValueSymbol = null;
383 383
384 Assert.check(!annotations.isEmpty() && 384 Assert.check(!annotations.isEmpty() &&
385 !annotations.tail.isEmpty()); // i.e. size() > 1 385 !annotations.tail.isEmpty()); // i.e. size() > 1
386 386
387 int count = 0;
387 for (List<T> al = annotations; 388 for (List<T> al = annotations;
388 !al.isEmpty(); 389 !al.isEmpty();
389 al = al.tail) 390 al = al.tail)
390 { 391 {
392 count++;
393
394 // There must be more than a single anno in the annotation list
395 Assert.check(count > 1 || !al.tail.isEmpty());
396
391 T currentAnno = al.head; 397 T currentAnno = al.head;
392 398
393 origAnnoType = currentAnno.type; 399 origAnnoType = currentAnno.type;
394 if (arrayOfOrigAnnoType == null) { 400 if (arrayOfOrigAnnoType == null) {
395 arrayOfOrigAnnoType = types.makeArrayType(origAnnoType); 401 arrayOfOrigAnnoType = types.makeArrayType(origAnnoType);
396 } 402 }
397 403
398 Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno)); 404 // Only report errors if this isn't the first occurrence I.E. count > 1
405 boolean reportError = count > 1;
406 Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno), reportError);
399 if (currentContainerType == null) { 407 if (currentContainerType == null) {
400 continue; 408 continue;
401 } 409 }
402 // Assert that the target Container is == for all repeated 410 // Assert that the target Container is == for all repeated
403 // annos of the same annotation type, the types should 411 // annos of the same annotation type, the types should
462 } 470 }
463 } 471 }
464 472
465 /** Fetches the actual Type that should be the containing annotation. */ 473 /** Fetches the actual Type that should be the containing annotation. */
466 private Type getContainingType(Attribute.Compound currentAnno, 474 private Type getContainingType(Attribute.Compound currentAnno,
467 DiagnosticPosition pos) 475 DiagnosticPosition pos,
476 boolean reportError)
468 { 477 {
469 Type origAnnoType = currentAnno.type; 478 Type origAnnoType = currentAnno.type;
470 TypeSymbol origAnnoDecl = origAnnoType.tsym; 479 TypeSymbol origAnnoDecl = origAnnoType.tsym;
471 480
472 // Fetch the Repeatable annotation from the current 481 // Fetch the Repeatable annotation from the current
473 // annotation's declaration, or null if it has none 482 // annotation's declaration, or null if it has none
474 Attribute.Compound ca = origAnnoDecl.attribute(syms.repeatableType.tsym); 483 Attribute.Compound ca = origAnnoDecl.attribute(syms.repeatableType.tsym);
475 if (ca == null) { // has no Repeatable annotation 484 if (ca == null) { // has no Repeatable annotation
476 log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType); 485 if (reportError)
486 log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType);
477 return null; 487 return null;
478 } 488 }
479 489
480 return filterSame(extractContainingType(ca, pos, origAnnoDecl), 490 return filterSame(extractContainingType(ca, pos, origAnnoDecl),
481 origAnnoType); 491 origAnnoType);

mercurial