Skip to content

Commit

Permalink
Reuse quick fixes from LocalCorrectionsBaseSubProcessor.
Browse files Browse the repository at this point in the history
- New quick fixes :
  - UnqualifiedFieldAccess -> addUnqualifiedFieldAccessProposal
  - UnnecessaryInstanceof -> addUnnecessaryInstanceofProposal
  - IllegalQualifiedEnumConstantLabel -> addIllegalQualifiedEnumConstantLabelProposal
  - UnnecessaryElse -> addUnnecessaryElseProposals
  - SuperclassMustBeAClass -> addInterfaceExtendsClassProposals
  - AssignmentHasNoEffect -> addAssignmentHasNoEffectProposals
  - FallthroughCase, IllegalFallthroughToPattern
     -> addFallThroughProposals
  - UnsafeTypeConversion, RawTypeReference, UnsafeRawMethodInvocation
    -> addDeprecatedFieldsToMethodsProposals
  - IllegalTotalPatternWithDefault -> addRemoveDefaultCaseProposal
  - SuperfluousSemicolon -> addSuperfluousSemicolonProposal
  - AbstractServiceImplementation,
       ProviderMethodOrConstructorRequiredForServiceImpl,
       ServiceImplDefaultConstructorNotPublic
    -> addServiceProviderConstructorProposals
  - NonStaticFieldFromStaticInvocation, NonStaticFieldFromStaticInvocation
    -> addObjectReferenceProposal, addVariableReferenceProposal,
       addNewObjectProposal
- Fix the JDT-LS QuickFixProcessor to better match upstream (by
  preventing fall-throughs, with 'break' where appropriate)
- Preserve non-upstreamed behaviour of surrounding all selected
  statements when "Surrounding with try/catch"
- Based on https://eclip.se/545163 the "Surround with try-catch"
  quick-fix is not valid for a 'throw' statement so we should adjust
  those testcases to use methods with throw declarations instead
- Ensure the current compilation unit primary type is never used when it
  is null

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Jan 24, 2025
1 parent fdced4b commit cc0946b
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,17 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
case IProblem.SealedNotDirectSuperInterface:
case IProblem.SealedNotDirectSuperClass:
LocalCorrectionsSubProcessor.addSealedAsDirectSuperTypeProposal(context, problem, proposals);
break;
case IProblem.SealedSuperClassDoesNotPermit:
case IProblem.SealedSuperInterfaceDoesNotPermit:
LocalCorrectionsSubProcessor.addTypeAsPermittedSubTypeProposal(context, problem, proposals);
break;
case IProblem.StaticMethodRequested:
case IProblem.NonStaticFieldFromStaticInvocation:
LocalCorrectionsSubProcessor.addObjectReferenceProposal(context, problem, proposals);
LocalCorrectionsSubProcessor.addVariableReferenceProposal(context, problem, proposals);
LocalCorrectionsSubProcessor.addNewObjectProposal(context, problem, proposals);
//$FALL-THROUGH$
case IProblem.InstanceMethodDuringConstructorInvocation:
case IProblem.InstanceFieldDuringConstructorInvocation:
ModifierCorrectionSubProcessor.addNonAccessibleReferenceProposal(context, problem, proposals, ModifierCorrectionSubProcessor.TO_STATIC, IProposalRelevance.CHANGE_MODIFIER_TO_STATIC);
Expand Down Expand Up @@ -353,29 +359,24 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
// problem, proposals, ModifierCorrectionSubProcessor.TO_NON_PRIVATE,
// IProposalRelevance.CHANGE_VISIBILITY_TO_NON_PRIVATE);
// break;
// case IProblem.SuperfluousSemicolon:
// LocalCorrectionsSubProcessor.addSuperfluousSemicolonProposal(context,
// problem, proposals);
// break;
case IProblem.SuperfluousSemicolon:
LocalCorrectionsSubProcessor.addSuperfluousSemicolonProposal(context, problem, proposals);
break;
case IProblem.UnnecessaryCast:
LocalCorrectionsSubProcessor.addUnnecessaryCastProposal(context, problem, proposals);
break;
// case IProblem.UnnecessaryInstanceof:
// LocalCorrectionsSubProcessor.addUnnecessaryInstanceofProposal(context,
// problem, proposals);
// break;
case IProblem.UnnecessaryInstanceof:
LocalCorrectionsSubProcessor.addUnnecessaryInstanceofProposal(context, problem, proposals);
break;
// case IProblem.UnusedMethodDeclaredThrownException:
// case IProblem.UnusedConstructorDeclaredThrownException:
// LocalCorrectionsSubProcessor.addUnnecessaryThrownExceptionProposal(context,
// problem, proposals);
// break;
// case IProblem.UnqualifiedFieldAccess:
// GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context,
// problem, proposals,
// IProposalRelevance.GETTER_SETTER_UNQUALIFIED_FIELD_ACCESS);
// LocalCorrectionsSubProcessor.addUnqualifiedFieldAccessProposal(context,
// problem, proposals);
// break;
case IProblem.UnqualifiedFieldAccess:
// GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, problem, proposals, IProposalRelevance.GETTER_SETTER_UNQUALIFIED_FIELD_ACCESS);
LocalCorrectionsSubProcessor.addUnqualifiedFieldAccessProposal(context, problem, proposals);
break;
// case IProblem.Task:
// proposals.add(new TaskMarkerProposal(context.getCompilationUnit(),
// problem, 10));
Expand Down Expand Up @@ -429,14 +430,12 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
case IProblem.MissingSerialVersion:
SerialVersionSubProcessor.getSerialVersionProposals(context, problem, proposals);
break;
// case IProblem.UnnecessaryElse:
// LocalCorrectionsSubProcessor.getUnnecessaryElseProposals(context,
// problem, proposals);
// break;
// case IProblem.SuperclassMustBeAClass:
// LocalCorrectionsSubProcessor.getInterfaceExtendsClassProposals(context,
// problem, proposals);
// break;
case IProblem.UnnecessaryElse:
LocalCorrectionsSubProcessor.addUnnecessaryElseProposals(context, problem, proposals);
break;
case IProblem.SuperclassMustBeAClass:
LocalCorrectionsSubProcessor.addInterfaceExtendsClassProposals(context, problem, proposals);
break;
case IProblem.CodeCannotBeReached:
case IProblem.DeadCode:
LocalCorrectionsSubProcessor.getUnreachableCodeProposals(context, problem, proposals);
Expand Down Expand Up @@ -513,15 +512,14 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
// ReorgCorrectionsSubProcessor.getAccessRulesProposals(context,
// problem, proposals);
// break;
// case IProblem.AssignmentHasNoEffect:
// LocalCorrectionsSubProcessor.getAssignmentHasNoEffectProposals(context,
// problem, proposals);
// break;
// case IProblem.UnsafeTypeConversion:
// case IProblem.RawTypeReference:
// case IProblem.UnsafeRawMethodInvocation:
// LocalCorrectionsSubProcessor.addDeprecatedFieldsToMethodsProposals(context,
// problem, proposals);
case IProblem.AssignmentHasNoEffect:
LocalCorrectionsSubProcessor.addAssignmentHasNoEffectProposals(context, problem, proposals);
break;
case IProblem.UnsafeTypeConversion:
case IProblem.RawTypeReference:
case IProblem.UnsafeRawMethodInvocation:
LocalCorrectionsSubProcessor.addDeprecatedFieldsToMethodsProposals(context, problem, proposals);
break;
// //$FALL-THROUGH$
// case IProblem.UnsafeElementTypeConversion:
// LocalCorrectionsSubProcessor.addTypePrametersToRawTypeReference(context,
Expand All @@ -531,10 +529,9 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
// LocalCorrectionsSubProcessor.addRemoveRedundantTypeArgumentsProposals(context,
// problem, proposals);
// break;
// case IProblem.FallthroughCase:
// LocalCorrectionsSubProcessor.addFallThroughProposals(context,
// problem, proposals);
// break;
case IProblem.FallthroughCase:
LocalCorrectionsSubProcessor.addFallThroughProposals(context, problem, proposals);
break;
// case IProblem.UnhandledWarningToken:
// SuppressWarningsSubProcessor.addUnknownSuppressWarningProposals(context, problem, proposals);
// break;
Expand All @@ -554,6 +551,12 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
case IProblem.MissingDefaultCase:
LocalCorrectionsSubProcessor.addMissingDefaultCaseProposal(context, problem, proposals);
break;
case IProblem.IllegalTotalPatternWithDefault:
LocalCorrectionsSubProcessor.addRemoveDefaultCaseProposal(context, problem, proposals);
break;
case IProblem.IllegalFallthroughToPattern:
LocalCorrectionsSubProcessor.addFallThroughProposals(context, problem, proposals);
break;
case IProblem.MissingEnumConstantCaseDespiteDefault:
LocalCorrectionsSubProcessor.getMissingEnumConstantCaseProposals(context, problem, proposals);
LocalCorrectionsSubProcessor.addCasesOmittedProposals(context, problem, proposals);
Expand All @@ -565,6 +568,12 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
case IProblem.NotAccessibleType:
GradleCompatibilityProcessor.getGradleCompatibilityProposals(context, problem, proposals);
break;
case IProblem.AbstractServiceImplementation:
case IProblem.ProviderMethodOrConstructorRequiredForServiceImpl:
case IProblem.ServiceImplDefaultConstructorNotPublic:
// LocalCorrectionsSubProcessor.addServiceProviderProposal(context, problem, proposals);
LocalCorrectionsSubProcessor.addServiceProviderConstructorProposals(context, problem, proposals);
break;
// case IProblem.MissingSynchronizedModifierInInheritedMethod:
// ModifierCorrectionSubProcessor.addSynchronizedMethodProposal(context,
// problem, proposals);
Expand Down Expand Up @@ -652,10 +661,9 @@ private void process(CodeActionParams params, IInvocationContext context, IProbl
// NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context,
// problem, ChangeKind.OVERRIDDEN, proposals);
// break;
// case IProblem.IllegalQualifiedEnumConstantLabel:
// LocalCorrectionsSubProcessor.addIllegalQualifiedEnumConstantLabelProposal(context,
// problem, proposals);
// break;
case IProblem.IllegalQualifiedEnumConstantLabel:
LocalCorrectionsSubProcessor.addIllegalQualifiedEnumConstantLabelProposal(context, problem, proposals);
break;
// case IProblem.DuplicateInheritedDefaultMethods:
// case IProblem.InheritedDefaultMethodConflictsWithOtherInherited:
// LocalCorrectionsSubProcessor.addOverrideDefaultMethodProposal(context,
Expand Down
Loading

0 comments on commit cc0946b

Please sign in to comment.