constructor reference: don't ignore constructor parameters during method reference...
[idea/community.git] / java / java-analysis-api / src / com / intellij / codeInsight / intention / QuickFixFactory.java
1 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.codeInsight.intention;
3
4 import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
5 import com.intellij.codeInspection.LocalQuickFix;
6 import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
7 import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
8 import com.intellij.lang.jvm.actions.JvmElementActionsFactory;
9 import com.intellij.openapi.components.ServiceManager;
10 import com.intellij.openapi.module.Module;
11 import com.intellij.openapi.project.Project;
12 import com.intellij.pom.java.LanguageLevel;
13 import com.intellij.psi.*;
14 import com.intellij.psi.tree.IElementType;
15 import com.intellij.psi.util.PropertyMemberType;
16 import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval;
17 import org.jetbrains.annotations.Nls;
18 import org.jetbrains.annotations.NotNull;
19 import org.jetbrains.annotations.Nullable;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Set;
25
26 /**
27  * @author cdr
28  */
29 public abstract class QuickFixFactory {
30   public static QuickFixFactory getInstance() {
31     return ServiceManager.getService(QuickFixFactory.class);
32   }
33
34   /**
35    * Consider to use
36    * {@link QuickFixFactory#createModifierListFix(PsiModifierListOwner, String, boolean, boolean)} for java only fix or
37    * {@link JvmElementActionsFactory#createChangeModifierActions(com.intellij.lang.jvm.JvmModifiersOwner, com.intellij.lang.jvm.actions.ChangeModifierRequest)}
38    * for jvm languages transparent fix
39    *
40    * Usage of this method might be unsafe in case of fixing java multi variable declaration modifier list
41    */
42   @NotNull
43   public abstract LocalQuickFixAndIntentionActionOnPsiElement createModifierListFix(@NotNull PsiModifierList modifierList,
44                                                                                     @PsiModifier.ModifierConstant @NotNull String modifier,
45                                                                                     boolean shouldHave,
46                                                                                     final boolean showContainingClass);
47
48   /**
49    * @see JvmElementActionsFactory#createChangeModifierActions(com.intellij.lang.jvm.JvmModifiersOwner, com.intellij.lang.jvm.actions.ChangeModifierRequest
50    * for jvm language transparent fix
51    */
52   @NotNull
53   public abstract LocalQuickFixAndIntentionActionOnPsiElement createModifierListFix(@NotNull PsiModifierListOwner owner,
54                                                                                     @PsiModifier.ModifierConstant @NotNull String modifier,
55                                                                                     boolean shouldHave,
56                                                                                     final boolean showContainingClass);
57
58   @NotNull
59   public abstract LocalQuickFixAndIntentionActionOnPsiElement createMethodReturnFix(@NotNull PsiMethod method,
60                                                                                     @NotNull PsiType toReturn,
61                                                                                     boolean fixWholeHierarchy);
62
63   @NotNull
64   public abstract LocalQuickFixAndIntentionActionOnPsiElement createAddMethodFix(@NotNull PsiMethod method, @NotNull PsiClass toClass);
65
66   @NotNull
67   public abstract LocalQuickFixAndIntentionActionOnPsiElement createAddMethodFix(@NotNull String methodText,
68                                                                                  @NotNull PsiClass toClass,
69                                                                                  @NotNull String... exceptions);
70
71   /**
72    * @param psiElement psiClass or enum constant without class initializer
73    */
74   @NotNull
75   public abstract LocalQuickFixAndIntentionActionOnPsiElement createImplementMethodsFix(@NotNull PsiElement psiElement);
76
77   @NotNull
78   public abstract LocalQuickFixAndIntentionActionOnPsiElement createAssignmentToComparisonFix(@NotNull PsiAssignmentExpression expr);
79
80   @NotNull
81   public abstract LocalQuickFixAndIntentionActionOnPsiElement createImplementMethodsFix(@NotNull PsiClass psiElement);
82
83   @NotNull
84   public abstract LocalQuickFixOnPsiElement createMethodThrowsFix(@NotNull PsiMethod method,
85                                                                   @NotNull PsiClassType exceptionClass,
86                                                                   boolean shouldThrow,
87                                                                   boolean showContainingClass);
88
89   @NotNull
90   public abstract LocalQuickFixAndIntentionActionOnPsiElement createAddDefaultConstructorFix(@NotNull PsiClass aClass);
91
92   @Nullable
93   public abstract LocalQuickFixAndIntentionActionOnPsiElement createAddConstructorFix(@NotNull PsiClass aClass,
94                                                                                       @PsiModifier.ModifierConstant @NotNull String modifier);
95
96   @NotNull
97   public abstract LocalQuickFixAndIntentionActionOnPsiElement createMethodParameterTypeFix(@NotNull PsiMethod method,
98                                                                                            int index,
99                                                                                            @NotNull PsiType newType,
100                                                                                            boolean fixWholeHierarchy);
101
102   @NotNull
103   public abstract LocalQuickFixAndIntentionActionOnPsiElement createMakeClassInterfaceFix(@NotNull PsiClass aClass);
104
105   @NotNull
106   public abstract LocalQuickFixAndIntentionActionOnPsiElement createMakeClassInterfaceFix(@NotNull PsiClass aClass,
107                                                                                           final boolean makeInterface);
108
109   @NotNull
110   public abstract LocalQuickFixAndIntentionActionOnPsiElement createExtendsListFix(@NotNull PsiClass aClass,
111                                                                                    @NotNull PsiClassType typeToExtendFrom,
112                                                                                    boolean toAdd);
113
114   @NotNull
115   public abstract LocalQuickFixAndIntentionActionOnPsiElement createRemoveUnusedParameterFix(@NotNull PsiParameter parameter);
116
117   @NotNull
118   public abstract IntentionAction createRemoveUnusedVariableFix(@NotNull PsiVariable variable);
119
120   @Nullable
121   public abstract IntentionAction createCreateClassOrPackageFix(@NotNull PsiElement context,
122                                                                 @NotNull String qualifiedName,
123                                                                 final boolean createClass,
124                                                                 final String superClass);
125
126   @Nullable
127   public abstract IntentionAction createCreateClassOrInterfaceFix(@NotNull PsiElement context,
128                                                                   @NotNull String qualifiedName,
129                                                                   final boolean createClass,
130                                                                   final String superClass);
131
132   @NotNull
133   public abstract IntentionAction createCreateFieldOrPropertyFix(@NotNull PsiClass aClass,
134                                                                  @NotNull String name,
135                                                                  @NotNull PsiType type,
136                                                                  @NotNull PropertyMemberType targetMember,
137                                                                  @NotNull PsiAnnotation... annotations);
138
139   @NotNull
140   public abstract IntentionAction createSetupJDKFix();
141
142   @NotNull
143   public abstract IntentionAction createAddExceptionToCatchFix();
144
145   @NotNull
146   public abstract IntentionAction createAddExceptionToThrowsFix(@NotNull PsiElement element);
147
148   @NotNull
149   public abstract IntentionAction createAddExceptionFromFieldInitializerToConstructorThrowsFix(@NotNull PsiElement element);
150
151   @NotNull
152   public abstract IntentionAction createSurroundWithTryCatchFix(@NotNull PsiElement element);
153
154   @NotNull
155   public abstract IntentionAction createAddExceptionToExistingCatch(@NotNull PsiElement element);
156
157   @NotNull
158   public abstract IntentionAction createChangeToAppendFix(@NotNull IElementType sign,
159                                                           @NotNull PsiType type,
160                                                           @NotNull PsiAssignmentExpression assignment);
161
162   @NotNull
163   public abstract IntentionAction createAddTypeCastFix(@NotNull PsiType type, @NotNull PsiExpression expression);
164
165   @NotNull
166   public abstract IntentionAction createWrapExpressionFix(@NotNull PsiType type, @NotNull PsiExpression expression);
167
168   @NotNull
169   public abstract IntentionAction createReuseVariableDeclarationFix(@NotNull PsiLocalVariable variable);
170
171   @NotNull
172   public abstract IntentionAction createNavigateToAlreadyDeclaredVariableFix(@NotNull PsiVariable variable);
173
174   @NotNull
175   public abstract IntentionAction createConvertToStringLiteralAction();
176
177   @NotNull
178   public abstract IntentionAction createDeleteCatchFix(@NotNull PsiParameter parameter);
179
180   @NotNull
181   public abstract IntentionAction createDeleteMultiCatchFix(@NotNull PsiTypeElement element);
182
183   @NotNull
184   public abstract IntentionAction createConvertSwitchToIfIntention(@NotNull PsiSwitchStatement statement);
185
186   @NotNull
187   public abstract IntentionAction createNegationBroadScopeFix(@NotNull PsiPrefixExpression expr);
188
189   @NotNull
190   public abstract IntentionAction createCreateFieldFromUsageFix(@NotNull PsiReferenceExpression place);
191
192   @NotNull
193   public abstract IntentionAction createReplaceWithListAccessFix(@NotNull PsiArrayAccessExpression expression);
194
195   @NotNull
196   public abstract IntentionAction createAddNewArrayExpressionFix(@NotNull PsiArrayInitializerExpression expression);
197
198   @NotNull
199   public abstract IntentionAction createMoveCatchUpFix(@NotNull PsiCatchSection section, @NotNull PsiCatchSection section1);
200
201   @NotNull
202   public abstract IntentionAction createRenameWrongRefFix(@NotNull PsiReferenceExpression ref);
203
204   @NotNull
205   public abstract IntentionAction createRemoveQualifierFix(@NotNull PsiExpression qualifier,
206                                                            @NotNull PsiReferenceExpression expression,
207                                                            @NotNull PsiClass resolved);
208
209   @NotNull
210   public abstract IntentionAction createRemoveParameterListFix(@NotNull PsiMethod parent);
211
212   @NotNull
213   public abstract IntentionAction createShowModulePropertiesFix(@NotNull PsiElement element);
214
215   @NotNull
216   public abstract IntentionAction createShowModulePropertiesFix(@NotNull Module module);
217
218   @NotNull
219   public abstract IntentionAction createIncreaseLanguageLevelFix(@NotNull LanguageLevel level);
220
221   @NotNull
222   public abstract IntentionAction createChangeParameterClassFix(@NotNull PsiClass aClass, @NotNull PsiClassType type);
223
224   @NotNull
225   public abstract IntentionAction createReplaceInaccessibleFieldWithGetterSetterFix(@NotNull PsiElement element,
226                                                                                     @NotNull PsiMethod getter,
227                                                                                     boolean isSetter);
228
229   @NotNull
230   public abstract IntentionAction createSurroundWithArrayFix(@Nullable PsiCall methodCall, @Nullable PsiExpression expression);
231
232   @NotNull
233   public abstract IntentionAction createImplementAbstractClassMethodsFix(@NotNull PsiElement elementToHighlight);
234
235   @NotNull
236   public abstract IntentionAction createMoveClassToSeparateFileFix(@NotNull PsiClass aClass);
237
238   @NotNull
239   public abstract IntentionAction createRenameFileFix(@NotNull String newName);
240
241   @NotNull
242   public abstract LocalQuickFixAndIntentionActionOnPsiElement createRenameElementFix(@NotNull PsiNamedElement element);
243
244   @NotNull
245   public abstract LocalQuickFixAndIntentionActionOnPsiElement createRenameElementFix(@NotNull PsiNamedElement element,
246                                                                                      @NotNull String newName);
247
248   @NotNull
249   public abstract IntentionAction createChangeExtendsToImplementsFix(@NotNull PsiClass aClass, @NotNull PsiClassType classToExtendFrom);
250
251   @NotNull
252   public abstract IntentionAction createCreateConstructorMatchingSuperFix(@NotNull PsiClass aClass);
253
254   @NotNull
255   public abstract IntentionAction createRemoveNewQualifierFix(@NotNull PsiNewExpression expression, @Nullable PsiClass aClass);
256
257   @NotNull
258   public abstract IntentionAction createSuperMethodReturnFix(@NotNull PsiMethod superMethod, @NotNull PsiType superMethodType);
259
260   @NotNull
261   public abstract IntentionAction createInsertNewFix(@NotNull PsiMethodCallExpression call, @NotNull PsiClass aClass);
262
263   @NotNull
264   public abstract IntentionAction createAddMethodBodyFix(@NotNull PsiMethod method);
265
266   @NotNull
267   public abstract IntentionAction createDeleteMethodBodyFix(@NotNull PsiMethod method);
268
269   @NotNull
270   public abstract IntentionAction createInsertSuperFix(@NotNull PsiMethod constructor);
271
272   @NotNull
273   public abstract IntentionAction createInsertThisFix(@NotNull PsiMethod constructor);
274
275   @NotNull
276   public abstract IntentionAction createChangeMethodSignatureFromUsageFix(@NotNull PsiMethod targetMethod,
277                                                                           @NotNull PsiExpression[] expressions,
278                                                                           @NotNull PsiSubstitutor substitutor,
279                                                                           @NotNull PsiElement context,
280                                                                           boolean changeAllUsages, int minUsagesNumberToShowDialog);
281
282   @NotNull
283   public abstract IntentionAction createChangeMethodSignatureFromUsageReverseOrderFix(@NotNull PsiMethod targetMethod,
284                                                                                       @NotNull PsiExpression[] expressions,
285                                                                                       @NotNull PsiSubstitutor substitutor,
286                                                                                       @NotNull PsiElement context,
287                                                                                       boolean changeAllUsages,
288                                                                                       int minUsagesNumberToShowDialog);
289
290   @NotNull
291   public List<IntentionAction> createCreateMethodFromUsageFixes(@NotNull PsiMethodCallExpression call) {
292     return Collections.emptyList();
293   }
294
295   /**
296    * @deprecated use {@link #createCreateMethodFromUsageFixes}
297    */
298   @Deprecated
299   @ScheduledForRemoval(inVersion = "2019.3")
300   @NotNull
301   public abstract IntentionAction createCreateMethodFromUsageFix(@NotNull PsiMethodCallExpression call);
302
303   @NotNull
304   public abstract IntentionAction createCreateMethodFromUsageFix(@NotNull PsiMethodReferenceExpression methodReferenceExpression);
305
306   /**
307    * @deprecated use {@link #createCreateMethodFromUsageFixes}
308    */
309   @Deprecated
310   @ScheduledForRemoval(inVersion = "2019.3")
311   @NotNull
312   public abstract IntentionAction createCreateAbstractMethodFromUsageFix(@NotNull PsiMethodCallExpression call);
313
314   /**
315    * @deprecated use {@link #createCreateMethodFromUsageFixes}
316    */
317   @Deprecated
318   @ScheduledForRemoval(inVersion = "2019.3")
319   @NotNull
320   public abstract IntentionAction createCreatePropertyFromUsageFix(@NotNull PsiMethodCallExpression call);
321
322   /**
323    * @deprecated use {@link #createCreateConstructorFromCallExpressionFixes}
324    */
325   @Deprecated
326   @ScheduledForRemoval(inVersion = "2019.3")
327   @NotNull
328   public abstract IntentionAction createCreateConstructorFromSuperFix(@NotNull PsiMethodCallExpression call);
329
330   /**
331    * @deprecated use {@link #createCreateConstructorFromCallExpressionFixes}
332    */
333   @Deprecated
334   @ScheduledForRemoval(inVersion = "2019.3")
335   @NotNull
336   public abstract IntentionAction createCreateConstructorFromThisFix(@NotNull PsiMethodCallExpression call);
337
338   @NotNull
339   public List<IntentionAction> createCreateConstructorFromCallExpressionFixes(@NotNull PsiMethodCallExpression call) {
340     return Collections.emptyList();
341   }
342
343   /**
344    * @deprecated use {@link #createCreateMethodFromUsageFixes}
345    */
346   @Deprecated
347   @ScheduledForRemoval(inVersion = "2019.3")
348   @NotNull
349   public abstract IntentionAction createCreateGetterSetterPropertyFromUsageFix(@NotNull PsiMethodCallExpression call);
350
351   @NotNull
352   public abstract IntentionAction createStaticImportMethodFix(@NotNull PsiMethodCallExpression call);
353
354   @NotNull
355   public abstract IntentionAction createQualifyStaticMethodCallFix(@NotNull PsiMethodCallExpression call);
356
357   @NotNull
358   public abstract IntentionAction createReplaceAddAllArrayToCollectionFix(@NotNull PsiMethodCallExpression call);
359
360   /**
361    * @deprecated use {@link #createCreateConstructorFromUsageFixes}
362    */
363   @Deprecated
364   @ScheduledForRemoval(inVersion = "2019.3")
365   @NotNull
366   public abstract IntentionAction createCreateConstructorFromCallFix(@NotNull PsiConstructorCall call);
367
368   @NotNull
369   public List<IntentionAction> createCreateConstructorFromUsageFixes(@NotNull PsiConstructorCall call) {
370     return Collections.emptyList();
371   }
372
373   @NotNull
374   public abstract List<IntentionAction> getVariableTypeFromCallFixes(@NotNull PsiMethodCallExpression call,
375                                                                      @NotNull PsiExpressionList list);
376
377   @NotNull
378   public abstract IntentionAction createAddReturnFix(@NotNull PsiParameterListOwner methodOrLambda);
379
380   @NotNull
381   public abstract IntentionAction createAddVariableInitializerFix(@NotNull PsiVariable variable);
382
383   @NotNull
384   public abstract IntentionAction createDeferFinalAssignmentFix(@NotNull PsiVariable variable, @NotNull PsiReferenceExpression expression);
385
386   @NotNull
387   public abstract IntentionAction createVariableAccessFromInnerClassFix(@NotNull PsiVariable variable, @NotNull PsiElement scope);
388
389   @NotNull
390   public abstract IntentionAction createCreateConstructorParameterFromFieldFix(@NotNull PsiField field);
391
392   @NotNull
393   public abstract IntentionAction createInitializeFinalFieldInConstructorFix(@NotNull PsiField field);
394
395   @NotNull
396   public abstract IntentionAction createRemoveTypeArgumentsFix(@NotNull PsiElement variable);
397
398   @NotNull
399   public abstract IntentionAction createChangeClassSignatureFromUsageFix(@NotNull PsiClass owner,
400                                                                          @NotNull PsiReferenceParameterList parameterList);
401
402   @NotNull
403   public abstract IntentionAction createReplacePrimitiveWithBoxedTypeAction(@NotNull PsiTypeElement element,
404                                                                             @NotNull String typeName,
405                                                                             @NotNull String boxedTypeName);
406
407   @NotNull
408   public abstract IntentionAction createMakeVarargParameterLastFix(@NotNull PsiParameter parameter);
409
410   @NotNull
411   public abstract IntentionAction createMoveBoundClassToFrontFix(@NotNull PsiClass aClass, @NotNull PsiClassType type);
412
413   public abstract void registerPullAsAbstractUpFixes(@NotNull PsiMethod method, @NotNull QuickFixActionRegistrar registrar);
414
415   @NotNull
416   public abstract IntentionAction createCreateAnnotationMethodFromUsageFix(@NotNull PsiNameValuePair pair);
417
418   @NotNull
419   public abstract IntentionAction createOptimizeImportsFix(boolean onTheFly);
420
421   public abstract void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo);
422
423   /**
424    * Use {@link #createAddToDependencyInjectionAnnotationsFix(Project, String)} instead
425    */
426   @Deprecated
427   @NotNull
428   public IntentionAction createAddToDependencyInjectionAnnotationsFix(@NotNull Project project,
429                                                                       @NotNull String qualifiedName,
430                                                                       @NotNull String element) {
431     return createAddToDependencyInjectionAnnotationsFix(project, qualifiedName);
432   }
433
434   @NotNull
435   public abstract IntentionAction createAddToDependencyInjectionAnnotationsFix(@NotNull Project project, @NotNull String qualifiedName);
436
437   @NotNull
438   public abstract IntentionAction createAddToImplicitlyWrittenFieldsFix(@NotNull Project project, @NotNull String qualifiedName);
439
440   @NotNull
441   public abstract IntentionAction createCreateGetterOrSetterFix(boolean createGetter, boolean createSetter, @NotNull PsiField field);
442
443   @NotNull
444   public abstract IntentionAction createRenameToIgnoredFix(@NotNull PsiNamedElement namedElement);
445
446   @NotNull
447   public abstract IntentionAction createEnableOptimizeImportsOnTheFlyFix();
448
449   @NotNull
450   public abstract LocalQuickFixAndIntentionActionOnPsiElement createDeleteFix(@NotNull PsiElement element);
451
452   @NotNull
453   public abstract LocalQuickFixAndIntentionActionOnPsiElement createDeleteFix(@NotNull PsiElement element, @NotNull @Nls String text);
454
455   @NotNull
456   public abstract IntentionAction createDeleteSideEffectAwareFix(@NotNull PsiExpressionStatement statement);
457
458   @NotNull
459   public abstract IntentionAction createSafeDeleteFix(@NotNull PsiElement element);
460
461   @Nullable
462   public abstract List<LocalQuickFix> registerOrderEntryFixes(@NotNull QuickFixActionRegistrar registrar, @NotNull PsiReference reference);
463
464   @NotNull
465   public abstract IntentionAction createAddMissingRequiredAnnotationParametersFix(@NotNull PsiAnnotation annotation,
466                                                                                   @NotNull PsiMethod[] annotationMethods,
467                                                                                   @NotNull Collection<String> missedElements);
468
469   @NotNull
470   public abstract IntentionAction createSurroundWithQuotesAnnotationParameterValueFix(@NotNull PsiAnnotationMemberValue value,
471                                                                                       @NotNull PsiType expectedType);
472
473   @NotNull
474   public abstract IntentionAction addMethodQualifierFix(@NotNull PsiMethodCallExpression methodCall);
475
476   @NotNull
477   public abstract IntentionAction createWrapWithOptionalFix(@Nullable PsiType type, @NotNull PsiExpression expression);
478
479   @Nullable
480   public abstract IntentionAction createNotIterableForEachLoopFix(@NotNull PsiExpression expression);
481
482   @NotNull
483   public abstract List<IntentionAction> createAddAnnotationAttributeNameFixes(@NotNull PsiNameValuePair pair);
484
485   @NotNull
486   public abstract IntentionAction createCollectionToArrayFix(@NotNull PsiExpression collectionExpression,
487                                                              @NotNull PsiExpression expressionToReplace,
488                                                              @NotNull PsiArrayType arrayType);
489
490   @NotNull
491   public abstract IntentionAction createInsertMethodCallFix(@NotNull PsiMethodCallExpression call, @NotNull PsiMethod method);
492
493   @NotNull
494   public abstract LocalQuickFixAndIntentionActionOnPsiElement createAccessStaticViaInstanceFix(@NotNull PsiReferenceExpression methodRef,
495                                                                                                @NotNull JavaResolveResult result);
496
497   @NotNull
498   public abstract IntentionAction createWrapWithAdapterFix(@Nullable PsiType type, @NotNull PsiExpression expression);
499
500   @Nullable
501   public abstract IntentionAction createCreateClassInPackageInModuleFix(@NotNull Module module, @Nullable String packageName);
502
503   @NotNull
504   public abstract IntentionAction createPushDownMethodFix();
505
506   @NotNull
507   public IntentionAction createSameErasureButDifferentMethodsFix(@NotNull PsiMethod method, @NotNull PsiMethod superMethod) {
508     throw new AbstractMethodError();
509   }
510
511   public abstract IntentionAction createAddMissingEnumBranchesFix(@NotNull PsiSwitchBlock switchBlock, @NotNull Set<String> missingCases);
512
513   public abstract IntentionAction createAddSwitchDefaultFix(@NotNull PsiSwitchBlock switchBlock, @Nullable String message);
514
515   public abstract IntentionAction createCollapseAnnotationsFix(PsiAnnotation annotation);
516 }