Skip to content

JPQL syntax highlighting support with constant string concatenation #1460

Closed
@rasitayaz

Description

@rasitayaz

Expected Behavior

Similar to issue #1262, but with constants. It's best if I explain this with an example. Syntax highlighting for inline string inside query annotation does not work in this case, because the inline string is concatenated with a constant:

@Data
@AllArgsConstructor
public class UserDao {

  private UUID userId;
  private String name;

  public static final String SELECT = 
    """
      SELECT new com.package.UserDao(
        u.id,
        u.name
      )
    """;
}

public interface UserRepo extends JpaRepository<User, UUID> {
  @Query(
    UserDao.SELECT +
    """
      FROM User u
      WHERE u.id IN :ids
    """
  )
  List<UserDao> findAllByIdIn(Collection<UUID> ids);
}

Current Behavior

Syntax highlighting works properly when we only concatenate inline strings like following:

public interface UserRepo extends JpaRepository<User, UUID> {
  @Query(
    """
      SELECT new com.package.UserDao(
        u.id,
        u.name
      )
    """ +
    """
      FROM User u
      WHERE u.id IN :ids
    """
  )
  List<UserDao> findAllByIdIn(Collection<UUID> ids);
}

Context

The use case is to reduce duplicate code for queries that use the same data access object, and centralize the implementation so when any changes made to access object, changing only one string will be sufficient for all queries.

I'm using VS Code as code editor, here's some screenshots to show the difference:

Image Image

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions