@@ -614,11 +614,10 @@ public Index getIndex() {
614614 * return OTHER: inspect their ColumnOption nodes for inline constraints.
615615 */
616616 public ConstraintKind getConstraintKind () {
617- if (operation == null ) {
618- return ConstraintKind .OTHER ;
617+ if (hasExplicitConstraintHeader () ) {
618+ return ConstraintKind .fromType ( getConstraintType ()) ;
619619 }
620- if (isRenameOperation () && !(constraintType != null && constraintSymbol != null
621- && (operation == AlterOperation .ADD || operation == AlterOperation .ALTER ))) {
620+ if (operation == null || isRenameOperation ()) {
622621 return ConstraintKind .OTHER ;
623622 }
624623 switch (operation ) {
@@ -632,36 +631,43 @@ public ConstraintKind getConstraintKind() {
632631 case DROP_CHECK :
633632 return ConstraintKind .CHECK ;
634633 case ADD :
635- case ALTER :
636- if (constraintType != null && constraintSymbol != null ) {
637- return ConstraintKind .fromType (getConstraintType ());
638- }
639- if (operation != AlterOperation .ADD || columnName != null
640- || colDataTypeList != null || constraintName != null || oldIndex != null
641- || commentText != null || columnSetNotNullList != null
642- || columnDropNotNullList != null
643- || columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()) {
644- return ConstraintKind .OTHER ;
645- }
646- if (constraint != null ) {
647- return constraint .getKind () != null ? constraint .getKind ()
648- : ConstraintKind .OTHER ;
649- }
650- if (index != null ) {
651- return ConstraintKind .OTHER ;
652- }
653- if (pkColumns != null ) {
654- return ConstraintKind .PRIMARY_KEY ;
655- }
656- if (ukColumns != null ) {
657- return ConstraintKind .UNIQUE ;
658- }
659- return fkColumns != null ? ConstraintKind .FOREIGN_KEY : ConstraintKind .OTHER ;
634+ return getAddedConstraintKind ();
660635 default :
661636 return ConstraintKind .OTHER ;
662637 }
663638 }
664639
640+ private boolean hasExplicitConstraintHeader () {
641+ return constraintType != null && constraintSymbol != null
642+ && (operation == AlterOperation .ADD || operation == AlterOperation .ALTER );
643+ }
644+
645+ private ConstraintKind getAddedConstraintKind () {
646+ if (hasColumnOrNamedTarget ()) {
647+ return ConstraintKind .OTHER ;
648+ }
649+ if (constraint != null ) {
650+ return constraint .getKind () != null ? constraint .getKind () : ConstraintKind .OTHER ;
651+ }
652+ if (index != null ) {
653+ return ConstraintKind .OTHER ;
654+ }
655+ if (pkColumns != null ) {
656+ return ConstraintKind .PRIMARY_KEY ;
657+ }
658+ if (ukColumns != null ) {
659+ return ConstraintKind .UNIQUE ;
660+ }
661+ return fkColumns != null ? ConstraintKind .FOREIGN_KEY : ConstraintKind .OTHER ;
662+ }
663+
664+ private boolean hasColumnOrNamedTarget () {
665+ return columnName != null || colDataTypeList != null || constraintName != null
666+ || oldIndex != null || commentText != null || columnSetNotNullList != null
667+ || columnDropNotNullList != null
668+ || columnDropDefaultList != null && !columnDropDefaultList .isEmpty ();
669+ }
670+
665671 /**
666672 * Whether the active ADD body uses the complete table-definition renderer. Legacy constraint
667673 * headers and specialized action bodies use their own renderers. Stored definitions remain
@@ -967,8 +973,7 @@ public final String toString() {
967973 protected void appendBody (StringBuilder b ) {
968974 if (operation == AlterOperation .UNSPECIFIC ) {
969975 b .append (optionalSpecifier );
970- } else if (constraintType != null && constraintSymbol != null
971- && (operation == AlterOperation .ALTER || operation == AlterOperation .ADD )) {
976+ } else if (hasExplicitConstraintHeader ()) {
972977 toStringConstraintAlter (b );
973978 } else if (operation == AlterOperation .ALTER
974979 && (columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()
0 commit comments