Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Jul 29, 2025

Updated the formatting logic for SQL embedded within @Sql annotations to align with the intended indentation inside Java literal strings, rather than relying on the original line position.

Previous PR:
#331

Key Improvements

  • SQL alignment:
    SQL content is now indented to match the position after the opening """ (triple-quote) of the string literal.

  • Closing quotes alignment:
    The closing """ is automatically placed on a new line, aligned with the first line of the SQL content.


Example

Before Formatting:

@Select
@Sql("""
   /** TopBlock */
   select Count(distinct (x))
      , o.* , log(nbor.nearest
        , /* id */2) AS nearest -- column Line commen
/** From */
   from user""")
Emp selectInjection3(Integer id);

After Formatting:

@Select
@Sql("""
        /** TopBlock */
	SELECT Count(DISTINCT (x))
	       , o.*
	       , log(nbor.nearest
	             , /* id */2) AS nearest -- column Line commen
          /** From */
          FROM user
	""")
Emp selectInjection3(Integer id);

@xterao xterao requested a review from Copilot July 29, 2025 02:03
@xterao xterao self-assigned this Jul 29, 2025
@xterao xterao linked an issue Jul 29, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances SQL formatting within @Sql annotations by improving alignment and indentation logic for embedded SQL strings in Java literal strings, particularly for triple-quoted strings.

Key changes include:

  • Refactored SQL indentation to align content with the position after the opening triple quotes
  • Simplified post-processing by removing unnecessary parameters and improving text processing
  • Enhanced block comment formatting with new specialized block classes
  • Consolidated string constants into a centralized utility

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
DaoInjectionSqlVisitor.kt Core formatting logic updated to improve SQL alignment and simplify indentation handling
SqlPostProcessor.kt Simplified post-processing by removing unused parameters
SqlBlockGenerator.kt Added block comment spacing configuration
Multiple comment block files New classes for handling different parts of block comments (start, content, end)
Various utility files Centralized string constants and updated references to use SINGLE_SPACE

@xterao xterao merged commit e2405b1 into feature/sql-format-official-version Jul 29, 2025
5 checks passed
@xterao xterao deleted the feature/sql-format-support-injection-sql branch July 29, 2025 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Formatter】Support SQL Format in @Sql

2 participants