Skip to content

Commit 1e844f8

Browse files
authored
Bug 576380 - Quick fix not offered when a type that has a permits clause but does not have a sealed modifier (#2489)
1 parent 9fbdd21 commit 1e844f8

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest17.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,38 @@ public sealed interface IShape {
708708
assertProposalExists(proposals, expectedProposal6);
709709
}
710710

711+
@Test
712+
public void testAddSealedNonSealedModifier() throws Exception {
713+
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=576380
714+
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
715+
fJProject1.setRawClasspath(projectsetup.getDefaultClasspath(), null);
716+
JavaProjectHelper.set17CompilerOptions(fJProject1, false);
717+
718+
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
719+
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
720+
String str= """
721+
package test;
722+
interface I permits J {}
723+
record J() implements I {}""";
724+
ICompilationUnit cu= pack1.createCompilationUnit("I.java", str, false, null);
725+
726+
CompilationUnit astRoot= getASTRoot(cu);
727+
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot);
728+
assertNumberOfProposals(proposals, 2);
729+
assertCorrectLabels(proposals);
730+
731+
String[] expected= new String[2];
732+
expected[0]= """
733+
package test;
734+
sealed interface I permits J {}
735+
record J() implements I {}""";
736+
737+
expected[1]= """
738+
package test;
739+
non-sealed interface I permits J {}
740+
record J() implements I {}""";
741+
742+
assertExpectedExistInProposals(proposals, expected);
743+
}
744+
711745
}

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ public boolean hasCorrections(ICompilationUnit cu, int problemId) {
330330
case IProblem.IllegalTotalPatternWithDefault:
331331
case IProblem.IllegalFallthroughToPattern:
332332
case IProblem.ExpressionShouldBeAVariable:
333+
case IProblem.SealedMissingSealedModifier:
333334
return true;
334335

335336
default:
@@ -500,6 +501,7 @@ private void process(IInvocationContext context, IProblemLocation problem, Colle
500501
break;
501502
case IProblem.SealedMissingClassModifier:
502503
case IProblem.SealedMissingInterfaceModifier:
504+
case IProblem.SealedMissingSealedModifier:
503505
ModifierCorrectionSubProcessor.addSealedMissingModifierProposal(context, problem, proposals);
504506
break;
505507
case IProblem.SealedNotDirectSuperInterface:

0 commit comments

Comments
 (0)