mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor: introduce NotNull annotations to BaseElementAtCaretIntentionAction methods
GitOrigin-RevId: 20fde7acc6856d13b67d52d6b4841dfbc158e652
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c6589d5977
commit
7fd8f8c401
+2
-2
@@ -47,7 +47,7 @@ public class ExtractToMethodReferenceIntention extends BaseElementAtCaretIntenti
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class, false);
|
||||
if (lambdaExpression != null) {
|
||||
PsiElement body = lambdaExpression.getBody();
|
||||
@@ -84,7 +84,7 @@ public class ExtractToMethodReferenceIntention extends BaseElementAtCaretIntenti
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class, false);
|
||||
if (lambdaExpression != null) {
|
||||
PsiCodeBlock body = CommonJavaRefactoringUtil.expandExpressionLambdaToCodeBlock(lambdaExpression);
|
||||
|
||||
+2
-2
@@ -160,12 +160,12 @@ public final class ProjectProblemUtils {
|
||||
|
||||
private static final class ShowRelatedProblemsAction extends BaseElementAtCaretIntentionAction {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
return ProjectProblemCodeVisionProviderKt.isCodeVisionEnabled(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class);
|
||||
if (member == null) return;
|
||||
showProblems(editor, member);
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ public class AddExplicitTypeArgumentsIntention extends BaseElementAtCaretIntenti
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
PsiIdentifier identifier = ObjectUtils.tryCast(element, PsiIdentifier.class);
|
||||
if (identifier == null) return false;
|
||||
PsiReferenceExpression methodExpression = ObjectUtils.tryCast(identifier.getParent(), PsiReferenceExpression.class);
|
||||
@@ -40,7 +40,7 @@ public class AddExplicitTypeArgumentsIntention extends BaseElementAtCaretIntenti
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
|
||||
assert callExpression != null;
|
||||
PsiExpression withArgs = AddTypeArgumentsFix.addTypeArguments(callExpression, null);
|
||||
|
||||
@@ -17,12 +17,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AddJavadocIntention extends BaseElementAtCaretIntentionAction implements LowPriorityAction {
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull final Project project, final @NotNull Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
|
||||
FixDocCommentAction.generateOrFixComment(element, project, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull final Project project, final @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
if (element instanceof PsiIdentifier ||
|
||||
element instanceof PsiJavaCodeReferenceElement ||
|
||||
element instanceof PsiJavaModuleReferenceElement) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class AnnotateOverriddenMethodsIntention extends BaseElementAtCaretIntent
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement node) {
|
||||
public final boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement node) {
|
||||
final PsiAnnotation annotation = (PsiAnnotation)findMatchingElement(node);
|
||||
if (annotation == null) return false;
|
||||
final String annotationText = annotation.getText();
|
||||
@@ -82,7 +82,7 @@ public class AnnotateOverriddenMethodsIntention extends BaseElementAtCaretIntent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element){
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element){
|
||||
final PsiAnnotation annotation = (PsiAnnotation)findMatchingElement(element);
|
||||
if (annotation == null) return;
|
||||
final String annotationName = annotation.getQualifiedName();
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ChangeModifierIntention extends BaseElementAtCaretIntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
if (!JavaLanguage.INSTANCE.equals(element.getLanguage())) return false;
|
||||
PsiMember member = findMember(element);
|
||||
if (!(member instanceof PsiNameIdentifierOwner)) return false;
|
||||
@@ -132,7 +132,7 @@ public class ChangeModifierIntention extends BaseElementAtCaretIntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
PsiMember member = findMember(element);
|
||||
if (member == null) return;
|
||||
PsiFile file = member.getContainingFile();
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
public class ConvertAtomicToLongAdderIntention extends BaseElementAtCaretIntentionAction {
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
final PsiVariable variable = getVariable(element);
|
||||
if (variable != null) {
|
||||
final PsiType longAdder =
|
||||
@@ -33,7 +33,7 @@ public class ConvertAtomicToLongAdderIntention extends BaseElementAtCaretIntenti
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
if (!element.isValid() || !PsiUtil.isLanguageLevel8OrHigher(element)) return false;
|
||||
final PsiVariable variable = getVariable(element);
|
||||
return variable != null;
|
||||
|
||||
+3
-3
@@ -91,7 +91,7 @@ public class ConvertFieldToAtomicIntention extends BaseElementAtCaretIntentionAc
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
PsiVariable psiVariable = getVariable(element);
|
||||
if (psiVariable == null || psiVariable instanceof PsiResourceVariable) return false;
|
||||
if (psiVariable.getLanguage() != JavaLanguage.INSTANCE) return false;
|
||||
@@ -126,7 +126,7 @@ public class ConvertFieldToAtomicIntention extends BaseElementAtCaretIntentionAc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
PsiVariable var = getVariable(element);
|
||||
LOG.assertTrue(var != null);
|
||||
|
||||
@@ -238,7 +238,7 @@ public class ConvertFieldToAtomicIntention extends BaseElementAtCaretIntentionAc
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
return getVariable(element) != null;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ public class ConvertFieldToThreadLocalIntention extends BaseElementAtCaretIntent
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiIdentifier)) return false;
|
||||
PsiElement parent = element.getParent();
|
||||
if (!(parent instanceof PsiField field)) return false;
|
||||
@@ -57,7 +57,7 @@ public class ConvertFieldToThreadLocalIntention extends BaseElementAtCaretIntent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
final PsiField psiField = PsiTreeUtil.getParentOfType(element, PsiField.class);
|
||||
LOG.assertTrue(psiField != null);
|
||||
|
||||
|
||||
@@ -26,13 +26,12 @@ open class JsonSortPropertiesIntention : BaseElementAtCaretIntentionAction(), Lo
|
||||
override fun getFamilyName(): @Nls(capitalization = Nls.Capitalization.Sentence) String =
|
||||
JsonBundle.message("json.intention.sort.properties")
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean {
|
||||
return editor != null && Session(editor, element).hasUnsortedObjects()
|
||||
override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean {
|
||||
return Session(editor, element).hasUnsortedObjects()
|
||||
}
|
||||
|
||||
@Throws(IncorrectOperationException::class)
|
||||
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
|
||||
editor ?: return
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, element)) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, JsonBundle.message("file.is.readonly"),
|
||||
JsonBundle.message("cannot.sort.properties"), null)
|
||||
|
||||
+6
-6
@@ -15,7 +15,7 @@ public abstract class BaseElementAtCaretIntentionAction extends BaseIntentionAct
|
||||
|
||||
@Override
|
||||
public final boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!checkFile(file)) return false;
|
||||
if (editor == null || file == null || !checkFile(file)) return false;
|
||||
|
||||
useElementToTheLeft = false;
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
@@ -46,14 +46,14 @@ public abstract class BaseElementAtCaretIntentionAction extends BaseIntentionAct
|
||||
* @param element the element under caret.
|
||||
* @return true if the intention is available, false otherwise.
|
||||
*/
|
||||
public abstract boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element);
|
||||
public abstract boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element);
|
||||
|
||||
@Override
|
||||
public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (editor == null || file == null) return;
|
||||
|
||||
PsiElement element = getElement(editor, file);
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
if (element == null) return;
|
||||
|
||||
invoke(project, editor, element);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public abstract class BaseElementAtCaretIntentionAction extends BaseIntentionAct
|
||||
* @param element the element under cursor.
|
||||
* @throws IncorrectOperationException On errors.
|
||||
*/
|
||||
public abstract void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException;
|
||||
public abstract void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) throws IncorrectOperationException;
|
||||
|
||||
/**
|
||||
* Retrieves the element this intention was invoked on.
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ internal open class IntentionOnElementAtCaretWrapper(intention: BaseElementAtCar
|
||||
val element = descriptor.psiElement ?: return
|
||||
val file = element.containingFile ?: return
|
||||
val fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file.virtualFile)
|
||||
val editor = (fileEditor as? TextEditor)?.editor
|
||||
val editor = (fileEditor as? TextEditor)?.editor ?: return
|
||||
val action = action as BaseElementAtCaretIntentionAction
|
||||
action.invoke(project, editor, element)
|
||||
}
|
||||
|
||||
+3
-4
@@ -19,16 +19,15 @@ internal class FixCellAlignmentIntention: BaseElementAtCaretIntentionAction() {
|
||||
return MarkdownBundle.message("markdown.fix.cell.alignment.intention.text")
|
||||
}
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean {
|
||||
override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean {
|
||||
val cell = TableUtils.findCell(element)
|
||||
if (editor == null || cell == null || cell.parentTable == null) {
|
||||
if (cell == null || cell.parentTable == null) {
|
||||
return false
|
||||
}
|
||||
return !cell.hasCorrectPadding() || !cell.hasValidAlignment()
|
||||
}
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
|
||||
requireNotNull(editor)
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
val cell = TableUtils.findCell(element) ?: return
|
||||
val expectedAlignment = cell.parentTable?.getColumnAlignment(cell.columnIndex) ?: return
|
||||
cell.updateAlignment(editor.document, expectedAlignment)
|
||||
|
||||
+3
-4
@@ -17,16 +17,15 @@ internal class ReformatTableIntention: BaseElementAtCaretIntentionAction() {
|
||||
return MarkdownBundle.message("markdown.reformat.table.intention.text")
|
||||
}
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean {
|
||||
override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean {
|
||||
val table = TableUtils.findTable(element)
|
||||
if (editor == null || table == null) {
|
||||
if (table == null) {
|
||||
return false
|
||||
}
|
||||
return !table.isCorrectlyFormatted()
|
||||
}
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
|
||||
requireNotNull(editor)
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
val table = TableUtils.findTable(element)!!
|
||||
TableFormattingUtils.reformatAllColumns(table, editor.document, trimToMaxContent = true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user