@@ -436,8 +436,7 @@ public List<ColumnSetDefault> getColumnSetDefaultList() {
436436 * existing action-specific API to add or remove entries.
437437 */
438438 public List <ColumnDefaultAction > getColumnDefaults () {
439- if (operation != AlterOperation .ALTER || columnSetDefaultList == null
440- || constraintType != null && constraintSymbol != null
439+ if (!usesColumnActionBody () || columnSetDefaultList == null
441440 || columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()) {
442441 return Collections .emptyList ();
443442 }
@@ -994,10 +993,7 @@ protected void appendBody(StringBuilder b) {
994993 b .append (optionalSpecifier );
995994 } else if (hasExplicitConstraintHeader ()) {
996995 toStringConstraintAlter (b );
997- } else if (operation == AlterOperation .ALTER
998- && (columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()
999- || columnSetDefaultList != null && !columnSetDefaultList .isEmpty ()
1000- || columnSetVisibilityList != null && !columnSetVisibilityList .isEmpty ())) {
996+ } else if (usesColumnActionBody ()) {
1001997 toStringAlterColumn (b );
1002998 } else if (isSimpleKeywordOperation ()) {
1003999 toStringSimpleKeyword (b );
@@ -1014,6 +1010,35 @@ protected void appendBody(StringBuilder b) {
10141010 }
10151011 }
10161012
1013+ /**
1014+ * Whether the selected body renders ALTER COLUMN default or visibility actions. Subclasses
1015+ * overriding {@link #appendBody(StringBuilder)} must reflect their dispatch here as well.
1016+ */
1017+ protected boolean usesColumnActionBody () {
1018+ return operation == AlterOperation .ALTER && !hasExplicitConstraintHeader ()
1019+ && (columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()
1020+ || columnSetDefaultList != null && !columnSetDefaultList .isEmpty ()
1021+ || columnSetVisibilityList != null && !columnSetVisibilityList .isEmpty ());
1022+ }
1023+
1024+ /**
1025+ * Whether this action currently renders its column definitions through the general body.
1026+ * Inactive column metadata is retained in the AST but must not select a different body when
1027+ * deparsing. Subclasses with their own body dispatch override this method accordingly.
1028+ */
1029+ public boolean hasActiveColumnDefinitions () {
1030+ return hasColumnDefinitionPayload () && operation != AlterOperation .UNSPECIFIC
1031+ && !hasExplicitConstraintHeader () && !usesColumnActionBody ()
1032+ && !isSimpleKeywordOperation () && !isRenameOperation () && !isDropSpecialOperation ()
1033+ && operation != AlterOperation .CONVERT && operation != AlterOperation .COLLATE
1034+ && !isPartitionOperation ();
1035+ }
1036+
1037+ /** Whether column definitions take precedence within the general body. */
1038+ protected boolean hasColumnDefinitionPayload () {
1039+ return commentText == null && columnName == null && colDataTypeList != null ;
1040+ }
1041+
10171042 /**
10181043 * Appends the common tail (parameters, index comment) shared by all ALTER expressions.
10191044 */
0 commit comments