From 3d7d9f82980bcd603a709d1a649281eae6f457d0 Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Wed, 2 Aug 2023 16:11:03 +0200 Subject: [PATCH] [java, refactoring] disable extract interface for unnamed class GitOrigin-RevId: 97ceafc6e1da2b8aefa921e94bfd30bd90c0808d --- .../extractInterface/ExtractInterfaceHandler.java | 11 +++++++---- .../resources/messages/RefactoringBundle.properties | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractInterface/ExtractInterfaceHandler.java b/java/java-impl-refactorings/src/com/intellij/refactoring/extractInterface/ExtractInterfaceHandler.java index 5d6fc06ef3ab..8fa081eeed00 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractInterface/ExtractInterfaceHandler.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractInterface/ExtractInterfaceHandler.java @@ -29,10 +29,7 @@ import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class ExtractInterfaceHandler implements ElementsHandler, ContextAwareActionHandler { @@ -74,6 +71,12 @@ public class ExtractInterfaceHandler implements ElementsHandler, ContextAwareAct return; } + if (myClass instanceof PsiUnnamedClass) { + String message = RefactoringBundle.message("error.interface.cannot.be.extracted.from.unnamed.class"); + CommonRefactoringUtil.showErrorHint(project, null, message, getRefactoringName(), HelpID.EXTRACT_INTERFACE); + return; + } + if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myClass)) return; final Set selectedMembers = new HashSet<>(); diff --git a/platform/refactoring/resources/messages/RefactoringBundle.properties b/platform/refactoring/resources/messages/RefactoringBundle.properties index 4649224fe997..7ded3b553b00 100644 --- a/platform/refactoring/resources/messages/RefactoringBundle.properties +++ b/platform/refactoring/resources/messages/RefactoringBundle.properties @@ -10,6 +10,7 @@ error.wrong.caret.position.method.or.class.name=Caret should be positioned at th error.wrong.caret.position.method.or.variable.name=Caret should be positioned at the name of method or variable to be refactored error.wrong.caret.position.class=Caret should be positioned inside class to be refactored error.select.class.to.be.refactored=Cannot perform the refactoring.\nThe refactoring should be invoked on the class or members to be refactored. +error.interface.cannot.be.extracted.from.unnamed.class=Cannot perform the refactoring.\nCannot extract interface from unnamed class error.wrong.caret.position.method.or.local.name=Caret should be positioned at the name of element to be refactored error.wrong.caret.position.symbol.to.rename=Caret should be positioned at symbol to be renamed error.wrong.caret.position.symbol.to.refactor=Caret should be positioned at symbol to be refactored