|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2024 Broadcom, Inc. |
| 2 | + * Copyright (c) 2024, 2025 Broadcom, Inc. |
3 | 3 | * All rights reserved. This program and the accompanying materials |
4 | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution, and is available at |
@@ -536,5 +536,121 @@ public interface OwnerRepository { |
536 | 536 |
|
537 | 537 | } |
538 | 538 |
|
| 539 | + @Test |
| 540 | + void ConcatenatedStringWithConstantQuery() throws Exception { |
| 541 | + String source = """ |
| 542 | + package my.package |
| 543 | + |
| 544 | + import org.springframework.data.jpa.repository.Query; |
| 545 | + |
| 546 | + public interface OwnerRepository { |
| 547 | + |
| 548 | + static final String Q = " test FROM Te"; |
| 549 | + |
| 550 | + @Query(value = "SELECT" + |
| 551 | + " DIS" + |
| 552 | + "TINCT" + |
| 553 | + Q + |
| 554 | + "st", nativeQuery = true) |
| 555 | + void findByLastName(); |
| 556 | + } |
| 557 | + """; |
| 558 | + |
| 559 | + String uri = Paths.get(jp.getLocationUri()).resolve("src/main/resource/my/package/OwnerRepository.java").toUri() |
| 560 | + .toASCIIString(); |
| 561 | + CompilationUnit cu = CompilationUnitCache.parse2(source.toCharArray(), uri, "OwnerRepository.java", jp); |
539 | 562 |
|
| 563 | + assertThat(cu).isNotNull(); |
| 564 | + |
| 565 | + List<SemanticTokenData> tokens = computeTokens(cu); |
| 566 | + |
| 567 | + SemanticTokenData token = tokens.get(0); |
| 568 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("SELECT"); |
| 569 | + assertThat(token).isEqualTo(new SemanticTokenData(171, 177, "keyword", new String[0])); |
| 570 | + |
| 571 | + token = tokens.get(1); |
| 572 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("DIS"); |
| 573 | + assertThat(token).isEqualTo(new SemanticTokenData(185, 188, "keyword", new String[0])); |
| 574 | + |
| 575 | + token = tokens.get(2); |
| 576 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("TINCT"); |
| 577 | + assertThat(token).isEqualTo(new SemanticTokenData(195, 200, "keyword", new String[0])); |
| 578 | + |
| 579 | +// token = tokens.get(3); |
| 580 | +// assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("test"); |
| 581 | +// assertThat(token).isEqualTo(new SemanticTokenData(165, 169, "variable", new String[0])); |
| 582 | +// |
| 583 | +// token = tokens.get(4); |
| 584 | +// assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("FROM"); |
| 585 | +// assertThat(token).isEqualTo(new SemanticTokenData(170, 174, "keyword", new String[0])); |
| 586 | +// |
| 587 | +// token = tokens.get(5); |
| 588 | +// assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("Te"); |
| 589 | +// assertThat(token).isEqualTo(new SemanticTokenData(175, 177, "variable", new String[0])); |
| 590 | + |
| 591 | + token = tokens.get(3); |
| 592 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("st"); |
| 593 | + assertThat(token).isEqualTo(new SemanticTokenData(213, 215, "variable", new String[0])); |
| 594 | + |
| 595 | + } |
| 596 | + |
| 597 | + @Test |
| 598 | + void ConcatenatedStringWithFieldAccessConstantQuery() throws Exception { |
| 599 | + String source = """ |
| 600 | + package my.package |
| 601 | + |
| 602 | + import org.springframework.data.jpa.repository.Query; |
| 603 | + |
| 604 | + public interface OwnerRepository { |
| 605 | + |
| 606 | + static class P { |
| 607 | + static final String Q = " test FROM Te"; |
| 608 | + } |
| 609 | + |
| 610 | + @Query(value = "SELECT" + |
| 611 | + " DIS" + |
| 612 | + "TINCT" + |
| 613 | + P.Q + |
| 614 | + "st", nativeQuery = true) |
| 615 | + void findByLastName(); |
| 616 | + } |
| 617 | + """; |
| 618 | + |
| 619 | + String uri = Paths.get(jp.getLocationUri()).resolve("src/main/resource/my/package/OwnerRepository.java").toUri() |
| 620 | + .toASCIIString(); |
| 621 | + CompilationUnit cu = CompilationUnitCache.parse2(source.toCharArray(), uri, "OwnerRepository.java", jp); |
| 622 | + |
| 623 | + assertThat(cu).isNotNull(); |
| 624 | + |
| 625 | + List<SemanticTokenData> tokens = computeTokens(cu); |
| 626 | + |
| 627 | + SemanticTokenData token = tokens.get(0); |
| 628 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("SELECT"); |
| 629 | + assertThat(token).isEqualTo(new SemanticTokenData(194, 200, "keyword", new String[0])); |
| 630 | + |
| 631 | + token = tokens.get(1); |
| 632 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("DIS"); |
| 633 | + assertThat(token).isEqualTo(new SemanticTokenData(208, 211, "keyword", new String[0])); |
| 634 | + |
| 635 | + token = tokens.get(2); |
| 636 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("TINCT"); |
| 637 | + assertThat(token).isEqualTo(new SemanticTokenData(218, 223, "keyword", new String[0])); |
| 638 | + |
| 639 | +// token = tokens.get(3); |
| 640 | +// assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("test"); |
| 641 | +// assertThat(token).isEqualTo(new SemanticTokenData(165, 169, "variable", new String[0])); |
| 642 | +// |
| 643 | +// token = tokens.get(4); |
| 644 | +// assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("FROM"); |
| 645 | +// assertThat(token).isEqualTo(new SemanticTokenData(170, 174, "keyword", new String[0])); |
| 646 | +// |
| 647 | +// token = tokens.get(5); |
| 648 | +// assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("Te"); |
| 649 | +// assertThat(token).isEqualTo(new SemanticTokenData(175, 177, "variable", new String[0])); |
| 650 | + |
| 651 | + token = tokens.get(3); |
| 652 | + assertThat(source.substring(token.getStart(), token.getEnd())).isEqualTo("st"); |
| 653 | + assertThat(token).isEqualTo(new SemanticTokenData(238, 240, "variable", new String[0])); |
| 654 | + |
| 655 | + } |
540 | 656 | } |
0 commit comments