Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84ccfa6

Browse files
authored
Merge pull request#8718 from lahodaj/GITHUB-8475
Fixing highlighting for cases - needs to reset token index after searchig for 'when'
2 parents7974e08 +581340e commit84ccfa6

File tree

2 files changed

+38
-61
lines changed

2 files changed

+38
-61
lines changed

‎java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ public Void visitRequires(RequiresTree tree, Void p) {
648648

649649
@Override
650650
publicVoidvisitCase(CaseTreenode,Voidp) {
651+
intrestartIndex =tl.index();
651652
tl.moveToOffset(sourcePositions.getStartPosition(info.getCompilationUnit(),node));
652653
List<?extendsCaseLabelTree>labels =node.getLabels();
653654
for (CaseLabelTreelabelTree :labels) {
@@ -660,6 +661,7 @@ public Void visitCase(CaseTree node, Void p) {
660661
}
661662
}
662663
}
664+
tl.resetToIndex(restartIndex);
663665
returnsuper.visitCase(node,p);
664666
}
665667

‎java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java‎

Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,7 @@ public void testIncDecReading230408() throws Exception {
510510
}
511511

512512
publicvoidtestRecord1()throwsException {
513-
try {
514-
SourceVersion.valueOf("RELEASE_14");//NOI18N
515-
}catch (IllegalArgumentExceptionex) {
516-
//OK, no RELEASE_14, skip tests
517-
return ;
518-
}
519-
enablePreview();
513+
setSourceLevel("16");
520514
performTest("Record",
521515
"public record Test(String s) {}\n" +
522516
"class T {\n" +
@@ -538,13 +532,7 @@ public void testRecord1() throws Exception {
538532
}
539533

540534
publicvoidtestRecord2()throwsException {
541-
try {
542-
SourceVersion.valueOf("RELEASE_14");//NOI18N
543-
}catch (IllegalArgumentExceptionex) {
544-
//OK, no RELEASE_14, skip tests
545-
return;
546-
}
547-
enablePreview();
535+
setSourceLevel("16");
548536
performTest("Records",
549537
"public class Records {\n" +
550538
" public interface Super {}\n" +
@@ -578,13 +566,7 @@ public void testRecord2() throws Exception {
578566
}
579567

580568
publicvoidtestSealed()throwsException {
581-
try {
582-
SourceVersion.valueOf("RELEASE_15");//NOI18N
583-
}catch (IllegalArgumentExceptionex) {
584-
//OK, no RELEASE_14, skip tests
585-
return;
586-
}
587-
enablePreview();
569+
setSourceLevel("17");
588570
performTest("SealedTest",
589571
"sealed class Test{}\n"
590572
+"non-sealed class Child extends Test{}\n",
@@ -597,13 +579,7 @@ public void testSealed() throws Exception {
597579
}
598580

599581
publicvoidtestSealed2()throwsException {
600-
try {
601-
SourceVersion.valueOf("RELEASE_15");//NOI18N
602-
}catch (IllegalArgumentExceptionex) {
603-
//OK, no RELEASE_14, skip tests
604-
return;
605-
}
606-
enablePreview();
582+
setSourceLevel("17");
607583
performTest("SealedTest",
608584
"sealed class Test permits Child{}\n"
609585
+"non-sealed class Child extends Test{}\n",
@@ -618,13 +594,7 @@ public void testSealed2() throws Exception {
618594
}
619595

620596
publicvoidtestSwitchPattern()throwsException {
621-
try {
622-
SourceVersion.valueOf("RELEASE_19");//NOI18N
623-
}catch (IllegalArgumentExceptionex) {
624-
//OK, no RELEASE_19, skip tests
625-
return;
626-
}
627-
enablePreview();
597+
setSourceLevel("21");
628598
performTest("TestSwitchPattern.java",
629599
"public class TestSwitchPattern {\n"
630600
+" String strColor =\"color\";\n"
@@ -643,6 +613,8 @@ public void testSwitchPattern() throws Exception {
643613
+"[PUBLIC, CLASS], 3:8-3:14\n"
644614
+"[LOCAL_VARIABLE, DECLARATION], 3:15-3:18\n"
645615
+"[LOCAL_VARIABLE], 4:16-4:19\n"
616+
+"[PUBLIC, CLASS], 5:17-5:23\n"
617+
+"[LOCAL_VARIABLE, DECLARATION], 5:24-5:25\n"
646618
+"[KEYWORD], 5:26-5:30\n"
647619
+"[LOCAL_VARIABLE], 5:31-5:32\n"
648620
+"[PUBLIC, METHOD], 5:33-5:39\n"
@@ -656,13 +628,7 @@ public void testSwitchPattern() throws Exception {
656628
}
657629

658630
publicvoidtestRecordPattern()throwsException {
659-
try {
660-
SourceVersion.valueOf("RELEASE_19");//NOI18N
661-
}catch (IllegalArgumentExceptionex) {
662-
//OK, no RELEASE_19, skip tests
663-
return;
664-
}
665-
enablePreview();
631+
setSourceLevel("21");
666632
performTest("TestRecordPattern.java",
667633
"public class TestRecordPattern {\n"
668634
+" record Person(int name, int a){}\n"
@@ -684,7 +650,11 @@ public void testRecordPattern() throws Exception {
684650
+"[LOCAL_VARIABLE, DECLARATION], 3:15-3:18\n"
685651
+"[PACKAGE_PRIVATE, CONSTRUCTOR], 3:25-3:31\n"
686652
+"[LOCAL_VARIABLE], 4:16-4:19\n"
653+
+"[STATIC, PACKAGE_PRIVATE, RECORD], 5:17-5:23\n"
654+
+"[LOCAL_VARIABLE, DECLARATION], 5:28-5:29\n"
655+
+"[LOCAL_VARIABLE, UNUSED, DECLARATION], 5:35-5:36\n"
687656
+"[KEYWORD], 5:38-5:42\n"
657+
+"[LOCAL_VARIABLE], 5:43-5:44\n"
688658
+"[PUBLIC, CLASS], 5:52-5:58\n"
689659
+"[STATIC, PUBLIC, FIELD], 5:59-5:62\n"
690660
+"[PUBLIC, METHOD], 5:63-5:70\n"
@@ -694,7 +664,7 @@ public void testRecordPattern() throws Exception {
694664
}
695665

696666
publicvoidtestYield()throwsException {
697-
enablePreview();
667+
setSourceLevel("17");
698668
performTest("YieldTest.java",
699669
"public class YieldTest {\n" +
700670
" private int map(int i) {\n" +
@@ -709,12 +679,6 @@ public void testYield() throws Exception {
709679
}
710680

711681
publicvoidtestRawStringLiteral()throwsException {
712-
try {
713-
SourceVersion.valueOf("RELEASE_15");
714-
}catch (IllegalArgumentExceptioniae) {
715-
//OK, presumably no support for raw string literals
716-
return ;
717-
}
718682
setSourceLevel("15");
719683
performTest("RawStringLiteral",
720684
"public class RawStringLiteral {\n" +
@@ -739,12 +703,6 @@ public void testRawStringLiteral() throws Exception {
739703
}
740704

741705
publicvoidtestBindingPattern()throwsException {
742-
try {
743-
SourceVersion.valueOf("RELEASE_16");
744-
}catch (IllegalArgumentExceptioniae) {
745-
//OK, presumably no support for pattern matching
746-
return ;
747-
}
748706
setSourceLevel("16");
749707
performTest("BindingPattern",
750708
"public class BindingPattern {\n" +
@@ -1070,12 +1028,6 @@ public void testChainTypes4() throws Exception {
10701028
}
10711029

10721030
publicvoidtestRawStringLiteralNETBEANS_5118()throwsException {
1073-
try {
1074-
SourceVersion.valueOf("RELEASE_15");
1075-
}catch (IllegalArgumentExceptioniae) {
1076-
//OK, presumably no support for raw string literals
1077-
return ;
1078-
}
10791031
setSourceLevel("15");
10801032
performTest("RawStringLiteral",
10811033
"public class RawStringLiteral {\n" +
@@ -1115,6 +1067,29 @@ public void testVar() throws Exception {
11151067
"[ABSTRACT, PUBLIC, METHOD], 2:19-2:27");
11161068
}
11171069

1070+
publicvoidtestCaseRuleBodyHighlight()throwsException {
1071+
performTest("CaseTest",
1072+
"""
1073+
public class CaseTest {
1074+
private void t(Object o) {
1075+
switch (o) {
1076+
case Object oo -> {
1077+
o = null;
1078+
}
1079+
}
1080+
}
1081+
}
1082+
""",
1083+
"[PUBLIC, CLASS, DECLARATION], 0:13-0:21",
1084+
"[PRIVATE, METHOD, UNUSED, DECLARATION], 1:17-1:18",
1085+
"[PUBLIC, CLASS], 1:19-1:25",
1086+
"[PARAMETER, DECLARATION], 1:26-1:27",
1087+
"[PARAMETER], 2:16-2:17",
1088+
"[PUBLIC, CLASS], 3:17-3:23",
1089+
"[LOCAL_VARIABLE, UNUSED, DECLARATION], 3:24-3:26",
1090+
"[PARAMETER], 4:16-4:17");
1091+
}
1092+
11181093
privatevoidperformTest(StringfileName)throwsException {
11191094
performTest(fileName,newPerformer() {
11201095
publicvoidcompute(CompilationControllerparameter,Documentdoc,finalErrorDescriptionSettersetter) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp