|
20 | 20 | import javax.annotation.processing.ProcessingEnvironment; |
21 | 21 | import javax.lang.model.element.ExecutableElement; |
22 | 22 | import javax.lang.model.element.VariableElement; |
| 23 | +import javax.tools.Diagnostic.Kind; |
23 | 24 |
|
24 | 25 | import org.seasar.doma.SelectType; |
| 26 | +import org.seasar.doma.Suppress; |
25 | 27 | import org.seasar.doma.internal.apt.AptException; |
| 28 | +import org.seasar.doma.internal.apt.Notifier; |
26 | 29 | import org.seasar.doma.internal.apt.cttype.AnyCtType; |
27 | 30 | import org.seasar.doma.internal.apt.cttype.BasicCtType; |
28 | 31 | import org.seasar.doma.internal.apt.cttype.CollectorCtType; |
@@ -442,10 +445,14 @@ protected class ReturnCtTypeVisitor extends |
442 | 445 |
|
443 | 446 | protected QueryReturnMeta returnMeta; |
444 | 447 |
|
| 448 | + protected Suppress suppress; |
| 449 | + |
445 | 450 | protected ReturnCtTypeVisitor(SqlFileSelectQueryMeta queryMeta, |
446 | 451 | QueryReturnMeta returnMeta) { |
447 | 452 | this.queryMeta = queryMeta; |
448 | 453 | this.returnMeta = returnMeta; |
| 454 | + this.suppress = queryMeta.getExecutableElement().getAnnotation( |
| 455 | + Suppress.class); |
449 | 456 | } |
450 | 457 |
|
451 | 458 | @Override |
@@ -496,6 +503,20 @@ public Void visitIterableCtType(IterableCtType ctType, Void p) |
496 | 503 | return null; |
497 | 504 | } |
498 | 505 |
|
| 506 | + @Override |
| 507 | + public Void visitStreamCtType(StreamCtType ctType, Void p) |
| 508 | + throws RuntimeException { |
| 509 | + if (!isSuppressed(Message.DOMA4274)) { |
| 510 | + Notifier.notify(env, Kind.WARNING, Message.DOMA4274, |
| 511 | + returnMeta.getElement()); |
| 512 | + } |
| 513 | + queryMeta.setResultStream(true); |
| 514 | + ctType.getElementCtType() |
| 515 | + .accept(new ReturnStreamElementCtTypeVisitor(queryMeta, |
| 516 | + returnMeta), p); |
| 517 | + return null; |
| 518 | + } |
| 519 | + |
499 | 520 | @Override |
500 | 521 | public Void visitOptionalCtType(OptionalCtType ctType, Void p) |
501 | 522 | throws RuntimeException { |
@@ -523,6 +544,17 @@ public Void visitOptionalDoubleCtType(OptionalDoubleCtType ctType, |
523 | 544 | return null; |
524 | 545 | } |
525 | 546 |
|
| 547 | + protected boolean isSuppressed(Message message) { |
| 548 | + if (suppress != null) { |
| 549 | + for (Message suppressMessage : suppress.messages()) { |
| 550 | + if (suppressMessage == message) { |
| 551 | + return true; |
| 552 | + } |
| 553 | + } |
| 554 | + } |
| 555 | + return false; |
| 556 | + } |
| 557 | + |
526 | 558 | } |
527 | 559 |
|
528 | 560 | /** |
@@ -608,6 +640,89 @@ public Void visitOptionalDoubleCtType(OptionalDoubleCtType ctType, |
608 | 640 |
|
609 | 641 | } |
610 | 642 |
|
| 643 | + /** |
| 644 | + * |
| 645 | + * @author nakamura-to |
| 646 | + * |
| 647 | + */ |
| 648 | + protected class ReturnStreamElementCtTypeVisitor extends |
| 649 | + SimpleCtTypeVisitor<Void, Void, RuntimeException> { |
| 650 | + |
| 651 | + protected SqlFileSelectQueryMeta queryMeta; |
| 652 | + |
| 653 | + protected QueryReturnMeta returnMeta; |
| 654 | + |
| 655 | + protected ReturnStreamElementCtTypeVisitor( |
| 656 | + SqlFileSelectQueryMeta queryMeta, QueryReturnMeta returnMeta) { |
| 657 | + this.queryMeta = queryMeta; |
| 658 | + this.returnMeta = returnMeta; |
| 659 | + } |
| 660 | + |
| 661 | + @Override |
| 662 | + protected Void defaultAction(CtType type, Void p) |
| 663 | + throws RuntimeException { |
| 664 | + throw new AptException(Message.DOMA4271, env, |
| 665 | + returnMeta.getElement(), type.getTypeName()); |
| 666 | + } |
| 667 | + |
| 668 | + @Override |
| 669 | + public Void visitBasicCtType(BasicCtType ctType, Void p) |
| 670 | + throws RuntimeException { |
| 671 | + return null; |
| 672 | + } |
| 673 | + |
| 674 | + @Override |
| 675 | + public Void visitDomainCtType(DomainCtType ctType, Void p) |
| 676 | + throws RuntimeException { |
| 677 | + return null; |
| 678 | + } |
| 679 | + |
| 680 | + @Override |
| 681 | + public Void visitMapCtType(MapCtType ctType, Void p) |
| 682 | + throws RuntimeException { |
| 683 | + return null; |
| 684 | + } |
| 685 | + |
| 686 | + @Override |
| 687 | + public Void visitEntityCtType(EntityCtType ctType, Void p) |
| 688 | + throws RuntimeException { |
| 689 | + if (ctType.isAbstract()) { |
| 690 | + throw new AptException(Message.DOMA4272, env, |
| 691 | + returnMeta.getElement(), ctType.getTypeMirror()); |
| 692 | + } |
| 693 | + queryMeta.setEntityCtType(ctType); |
| 694 | + return null; |
| 695 | + } |
| 696 | + |
| 697 | + @Override |
| 698 | + public Void visitOptionalCtType(OptionalCtType ctType, Void p) |
| 699 | + throws RuntimeException { |
| 700 | + ctType.getElementCtType().accept( |
| 701 | + new ReturnStreamOptionalElementCtTypeVisitor(queryMeta, |
| 702 | + returnMeta), p); |
| 703 | + return null; |
| 704 | + } |
| 705 | + |
| 706 | + @Override |
| 707 | + public Void visitOptionalIntCtType(OptionalIntCtType ctType, Void p) |
| 708 | + throws RuntimeException { |
| 709 | + return null; |
| 710 | + } |
| 711 | + |
| 712 | + @Override |
| 713 | + public Void visitOptionalLongCtType(OptionalLongCtType ctType, Void p) |
| 714 | + throws RuntimeException { |
| 715 | + return null; |
| 716 | + } |
| 717 | + |
| 718 | + @Override |
| 719 | + public Void visitOptionalDoubleCtType(OptionalDoubleCtType ctType, |
| 720 | + Void p) throws RuntimeException { |
| 721 | + return null; |
| 722 | + } |
| 723 | + |
| 724 | + } |
| 725 | + |
611 | 726 | /** |
612 | 727 | * |
613 | 728 | * @author nakamura-to |
@@ -701,4 +816,42 @@ public Void visitDomainCtType(DomainCtType ctType, Void p) |
701 | 816 | } |
702 | 817 | } |
703 | 818 |
|
| 819 | + /** |
| 820 | + * |
| 821 | + * @author nakamura-to |
| 822 | + * |
| 823 | + */ |
| 824 | + protected class ReturnStreamOptionalElementCtTypeVisitor extends |
| 825 | + SimpleCtTypeVisitor<Void, Void, RuntimeException> { |
| 826 | + |
| 827 | + protected SqlFileSelectQueryMeta queryMeta; |
| 828 | + |
| 829 | + protected QueryReturnMeta returnMeta; |
| 830 | + |
| 831 | + protected ReturnStreamOptionalElementCtTypeVisitor( |
| 832 | + SqlFileSelectQueryMeta queryMeta, QueryReturnMeta returnMeta) { |
| 833 | + this.queryMeta = queryMeta; |
| 834 | + this.returnMeta = returnMeta; |
| 835 | + } |
| 836 | + |
| 837 | + @Override |
| 838 | + protected Void defaultAction(CtType type, Void p) |
| 839 | + throws RuntimeException { |
| 840 | + throw new AptException(Message.DOMA4267, env, |
| 841 | + returnMeta.getElement(), type.getTypeName()); |
| 842 | + } |
| 843 | + |
| 844 | + @Override |
| 845 | + public Void visitBasicCtType(BasicCtType ctType, Void p) |
| 846 | + throws RuntimeException { |
| 847 | + return null; |
| 848 | + } |
| 849 | + |
| 850 | + @Override |
| 851 | + public Void visitDomainCtType(DomainCtType ctType, Void p) |
| 852 | + throws RuntimeException { |
| 853 | + return null; |
| 854 | + } |
| 855 | + } |
| 856 | + |
704 | 857 | } |
0 commit comments