mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
assign weaker access: find method to implement (IDEA-153610)
This commit is contained in:
@@ -1327,6 +1327,7 @@ public class HighlightMethodUtil {
|
||||
|
||||
static HighlightInfo checkOverrideEquivalentInheritedMethods(PsiClass aClass, PsiFile containingFile, @NotNull LanguageLevel languageLevel) {
|
||||
String description = null;
|
||||
boolean appendImplementMethodFix = true;
|
||||
final Collection<HierarchicalMethodSignature> visibleSignatures = aClass.getVisibleSignatures();
|
||||
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(aClass.getProject()).getResolveHelper();
|
||||
Ultimate:
|
||||
@@ -1360,6 +1361,7 @@ public class HighlightMethodUtil {
|
||||
HighlightUtil.formatClass(containingClass),
|
||||
JavaHighlightUtil.formatMethod(superMethod),
|
||||
HighlightUtil.formatClass(superMethod.getContainingClass()));
|
||||
appendImplementMethodFix = false;
|
||||
break Ultimate;
|
||||
}
|
||||
}
|
||||
@@ -1383,7 +1385,11 @@ public class HighlightMethodUtil {
|
||||
if (description != null) {
|
||||
// show error info at the class level
|
||||
TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
if (appendImplementMethodFix) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createImplementMethodsFix(aClass));
|
||||
}
|
||||
return highlightInfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,14 @@ public class OverrideImplementExploreUtil {
|
||||
PsiUtilCore.ensureValid(method);
|
||||
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) || !resolveHelper.isAccessible(method, aClass, aClass)) continue;
|
||||
for (HierarchicalMethodSignature superMethodSignature : signature.getSuperSignatures()) {
|
||||
final PsiMethod superMethod = superMethodSignature.getMethod();
|
||||
if (PsiUtil.getAccessLevel(superMethod.getModifierList()) > PsiUtil.getAccessLevel(method.getModifierList())) {
|
||||
method = superMethod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PsiClass hisClass = method.getContainingClass();
|
||||
if (hisClass == null) continue;
|
||||
// filter non-immediate super constructors
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Implement methods" "true"
|
||||
class B {
|
||||
protected void f() {}
|
||||
}
|
||||
interface A {
|
||||
void f();
|
||||
}
|
||||
class D extends B implements A {
|
||||
@Override
|
||||
public void f() {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Implement methods" "true"
|
||||
class B {
|
||||
protected void f() {}
|
||||
}
|
||||
interface A {
|
||||
void f();
|
||||
}
|
||||
<caret>class D extends B implements A {}
|
||||
@@ -68,6 +68,39 @@ interface B extends A {
|
||||
"""
|
||||
}
|
||||
|
||||
public void testImplementInterfaceWhenClassProvidesProtectedImplementation() {
|
||||
myFixture.addClass """\
|
||||
interface A {
|
||||
void f();
|
||||
}
|
||||
"""
|
||||
myFixture.addClass """\
|
||||
class B {
|
||||
protected void f() {}
|
||||
}
|
||||
"""
|
||||
|
||||
def file = myFixture.addClass("""\
|
||||
class C extends B implements A {
|
||||
<caret>
|
||||
}
|
||||
""").containingFile.virtualFile
|
||||
myFixture.configureFromExistingVirtualFile(file)
|
||||
|
||||
def Presentation presentation = new Presentation()
|
||||
presentation.setText(ActionsBundle.message("action.ImplementMethods.text"))
|
||||
CommandProcessor.instance.executeCommand(project, { invokeAction(true) }, presentation.text, null)
|
||||
|
||||
myFixture.checkResult """\
|
||||
class C extends B implements A {
|
||||
@Override
|
||||
public void f() {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
public void testImplementSameNamedInterfaces() {
|
||||
myFixture.addClass """\
|
||||
class Main1 {
|
||||
|
||||
Reference in New Issue
Block a user