76
76
import org .eclipse .jdt .ls .core .internal .handlers .GenerateToStringHandler ;
77
77
import org .eclipse .jdt .ls .core .internal .handlers .JdtDomModels .LspVariableBinding ;
78
78
import org .eclipse .jdt .ls .core .internal .handlers .OrganizeImportsHandler ;
79
+ import org .eclipse .jdt .ls .core .internal .handlers .CodeActionHandler .CodeActionData ;
79
80
import org .eclipse .jdt .ls .core .internal .handlers .GenerateAccessorsHandler .AccessorCodeActionParams ;
80
81
import org .eclipse .jdt .ls .core .internal .preferences .PreferenceManager ;
81
82
import org .eclipse .lsp4j .CodeAction ;
@@ -144,12 +145,12 @@ public List<Either<Command, CodeAction>> getSourceActionCommands(CodeActionParam
144
145
// Generate QuickAssist
145
146
if (isInImportDeclaration ) {
146
147
Optional <Either <Command , CodeAction >> sourceOrganizeImports = getCodeActionFromProposal (params .getContext (), context .getCompilationUnit (), CorrectionMessages .ReorgCorrectionsSubProcessor_organizeimports_description ,
147
- JavaCodeActionKind .QUICK_ASSIST , organizeImportsProposal );
148
+ JavaCodeActionKind .QUICK_ASSIST , organizeImportsProposal , CodeActionComparator . ORGANIZE_IMPORTS_PRIORITY );
148
149
addSourceActionCommand ($ , params .getContext (), sourceOrganizeImports );
149
150
}
150
151
// Generate Source Action
151
152
Optional <Either <Command , CodeAction >> sourceOrganizeImports = getCodeActionFromProposal (params .getContext (), context .getCompilationUnit (), CorrectionMessages .ReorgCorrectionsSubProcessor_organizeimports_description ,
152
- CodeActionKind .SourceOrganizeImports , organizeImportsProposal );
153
+ CodeActionKind .SourceOrganizeImports , organizeImportsProposal , CodeActionComparator . ORGANIZE_IMPORTS_PRIORITY );
153
154
addSourceActionCommand ($ , params .getContext (), sourceOrganizeImports );
154
155
}
155
156
@@ -211,12 +212,12 @@ public List<Either<Command, CodeAction>> getSourceActionCommands(CodeActionParam
211
212
// Generate QuickAssist
212
213
if (isInTypeDeclaration ) {
213
214
Optional <Either <Command , CodeAction >> generateToStringQuickAssist = getCodeActionFromProposal (params .getContext (), context .getCompilationUnit (), ActionMessages .GenerateToStringAction_label ,
214
- JavaCodeActionKind .QUICK_ASSIST , generateToStringProposal );
215
+ JavaCodeActionKind .QUICK_ASSIST , generateToStringProposal , CodeActionComparator . GENERATE_TOSTRING_PRIORITY );
215
216
addSourceActionCommand ($ , params .getContext (), generateToStringQuickAssist );
216
217
}
217
218
// Generate Source Action
218
219
Optional <Either <Command , CodeAction >> generateToStringCommand = getCodeActionFromProposal (params .getContext (), context .getCompilationUnit (), ActionMessages .GenerateToStringAction_label ,
219
- JavaCodeActionKind .SOURCE_GENERATE_TO_STRING , generateToStringProposal );
220
+ JavaCodeActionKind .SOURCE_GENERATE_TO_STRING , generateToStringProposal , CodeActionComparator . GENERATE_TOSTRING_PRIORITY );
220
221
addSourceActionCommand ($ , params .getContext (), generateToStringCommand );
221
222
}
222
223
}
@@ -329,6 +330,7 @@ private Optional<Either<Command, CodeAction>> getOrganizeImportsAction(CodeActio
329
330
CodeAction codeAction = new CodeAction (CorrectionMessages .ReorgCorrectionsSubProcessor_organizeimports_description );
330
331
codeAction .setKind (kind );
331
332
codeAction .setCommand (command );
333
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .ORGANIZE_IMPORTS_PRIORITY ));
332
334
codeAction .setDiagnostics (Collections .emptyList ());
333
335
return Optional .of (Either .forRight (codeAction ));
334
336
@@ -344,6 +346,7 @@ private Optional<Either<Command, CodeAction>> getOverrideMethodsAction(CodeActio
344
346
CodeAction codeAction = new CodeAction (ActionMessages .OverrideMethodsAction_label );
345
347
codeAction .setKind (kind );
346
348
codeAction .setCommand (command );
349
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .GENERATE_OVERRIDE_IMPLEMENT_PRIORITY ));
347
350
codeAction .setDiagnostics (Collections .emptyList ());
348
351
return Optional .of (Either .forRight (codeAction ));
349
352
} else {
@@ -378,7 +381,7 @@ private Optional<Either<Command, CodeAction>> getGetterSetterAction(CodeActionPa
378
381
TextEdit edit = operation .createTextEdit (pm , accessors );
379
382
return convertToWorkspaceEdit (context .getCompilationUnit (), edit );
380
383
};
381
- return getCodeActionFromProposal (params .getContext (), context .getCompilationUnit (), actionMessage , kind , getAccessorsProposal );
384
+ return getCodeActionFromProposal (params .getContext (), context .getCompilationUnit (), actionMessage , kind , getAccessorsProposal , CodeActionComparator . GENERATE_ACCESSORS_PRIORITY );
382
385
} else {
383
386
String actionMessage ;
384
387
switch (accessorKind ) {
@@ -400,6 +403,7 @@ private Optional<Either<Command, CodeAction>> getGetterSetterAction(CodeActionPa
400
403
CodeAction codeAction = new CodeAction (actionMessage );
401
404
codeAction .setKind (kind );
402
405
codeAction .setCommand (command );
406
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .GENERATE_ACCESSORS_PRIORITY ));
403
407
codeAction .setDiagnostics (Collections .emptyList ());
404
408
return Optional .of (Either .forRight (codeAction ));
405
409
} else {
@@ -439,6 +443,7 @@ private Optional<Either<Command, CodeAction>> getHashCodeEqualsAction(CodeAction
439
443
CodeAction codeAction = new CodeAction (ActionMessages .GenerateHashCodeEqualsAction_label );
440
444
codeAction .setKind (kind );
441
445
codeAction .setCommand (command );
446
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .GENERATE_HASHCODE_EQUALS_PRIORITY ));
442
447
codeAction .setDiagnostics (Collections .emptyList ());
443
448
return Optional .of (Either .forRight (codeAction ));
444
449
} else {
@@ -467,6 +472,7 @@ private Optional<Either<Command, CodeAction>> getGenerateToStringAction(CodeActi
467
472
CodeAction codeAction = new CodeAction (ActionMessages .GenerateToStringAction_ellipsisLabel );
468
473
codeAction .setKind (kind );
469
474
codeAction .setCommand (command );
475
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .GENERATE_TOSTRING_PRIORITY ));
470
476
codeAction .setDiagnostics (Collections .emptyList ());
471
477
return Optional .of (Either .forRight (codeAction ));
472
478
} else {
@@ -493,14 +499,15 @@ private Optional<Either<Command, CodeAction>> getGenerateConstructorsAction(Code
493
499
TextEdit edit = GenerateConstructorsHandler .generateConstructors (type , status .constructors , status .fields , params .getRange (), pm );
494
500
return convertToWorkspaceEdit (type .getCompilationUnit (), edit );
495
501
};
496
- return getCodeActionFromProposal (params .getContext (), type .getCompilationUnit (), ActionMessages .GenerateConstructorsAction_label , kind , generateConstructorsProposal );
502
+ return getCodeActionFromProposal (params .getContext (), type .getCompilationUnit (), ActionMessages .GenerateConstructorsAction_label , kind , generateConstructorsProposal , CodeActionComparator . GENERATE_CONSTRUCTORS_PRIORITY );
497
503
}
498
504
499
505
Command command = new Command (ActionMessages .GenerateConstructorsAction_ellipsisLabel , COMMAND_ID_ACTION_GENERATECONSTRUCTORSPROMPT , Collections .singletonList (params ));
500
506
if (preferenceManager .getClientPreferences ().isSupportedCodeActionKind (JavaCodeActionKind .SOURCE_GENERATE_CONSTRUCTORS )) {
501
507
CodeAction codeAction = new CodeAction (ActionMessages .GenerateConstructorsAction_ellipsisLabel );
502
508
codeAction .setKind (kind );
503
509
codeAction .setCommand (command );
510
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .GENERATE_CONSTRUCTORS_PRIORITY ));
504
511
codeAction .setDiagnostics (Collections .emptyList ());
505
512
return Optional .of (Either .forRight (codeAction ));
506
513
} else {
@@ -525,6 +532,7 @@ private Optional<Either<Command, CodeAction>> getGenerateDelegateMethodsAction(C
525
532
CodeAction codeAction = new CodeAction (ActionMessages .GenerateDelegateMethodsAction_label );
526
533
codeAction .setKind (JavaCodeActionKind .SOURCE_GENERATE_DELEGATE_METHODS );
527
534
codeAction .setCommand (command );
535
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .GENERATE_DELEGATE_METHOD_PRIORITY ));
528
536
codeAction .setDiagnostics (Collections .EMPTY_LIST );
529
537
return Optional .of (Either .forRight (codeAction ));
530
538
} else {
@@ -581,7 +589,7 @@ private Optional<Either<Command, CodeAction>> getFinalModifierWherePossibleActio
581
589
if (this .preferenceManager .getClientPreferences ().isResolveCodeActionSupported ()) {
582
590
CodeAction codeAction = new CodeAction (actionMessage );
583
591
codeAction .setKind (proposal .getKind ());
584
- codeAction .setData (proposal );
592
+ codeAction .setData (new CodeActionData ( proposal , CodeActionComparator . CHANGE_MODIFIER_TO_FINAL_PRIORITY ) );
585
593
codeAction .setDiagnostics (Collections .EMPTY_LIST );
586
594
return Optional .of (Either .forRight (codeAction ));
587
595
} else {
@@ -601,6 +609,7 @@ private Optional<Either<Command, CodeAction>> getFinalModifierWherePossibleActio
601
609
CodeAction codeAction = new CodeAction (actionMessage );
602
610
codeAction .setKind (proposal .getKind ());
603
611
codeAction .setCommand (command );
612
+ codeAction .setData (new CodeActionData (null , CodeActionComparator .CHANGE_MODIFIER_TO_FINAL_PRIORITY ));
604
613
codeAction .setDiagnostics (Collections .EMPTY_LIST );
605
614
return Optional .of (Either .forRight (codeAction ));
606
615
} else {
@@ -609,11 +618,11 @@ private Optional<Either<Command, CodeAction>> getFinalModifierWherePossibleActio
609
618
}
610
619
}
611
620
612
- private Optional <Either <Command , CodeAction >> getCodeActionFromProposal (CodeActionContext context , ICompilationUnit cu , String name , String kind , CodeActionProposal proposal ) {
621
+ private Optional <Either <Command , CodeAction >> getCodeActionFromProposal (CodeActionContext context , ICompilationUnit cu , String name , String kind , CodeActionProposal proposal , int priority ) {
613
622
if (preferenceManager .getClientPreferences ().isResolveCodeActionSupported ()) {
614
623
CodeAction codeAction = new CodeAction (name );
615
624
codeAction .setKind (kind );
616
- codeAction .setData (proposal );
625
+ codeAction .setData (new CodeActionData ( proposal , priority ) );
617
626
codeAction .setDiagnostics (Collections .EMPTY_LIST );
618
627
return Optional .of (Either .forRight (codeAction ));
619
628
}
@@ -629,6 +638,7 @@ private Optional<Either<Command, CodeAction>> getCodeActionFromProposal(CodeActi
629
638
CodeAction codeAction = new CodeAction (name );
630
639
codeAction .setKind (kind );
631
640
codeAction .setCommand (command );
641
+ codeAction .setData (new CodeActionData (null , priority ));
632
642
codeAction .setDiagnostics (context .getDiagnostics ());
633
643
return Optional .of (Either .forRight (codeAction ));
634
644
} else {
0 commit comments