From 84e4ac4c32722a5ef268aad7252ed5e3e47ed52b Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sat, 20 Jan 2018 23:19:56 +0100 Subject: [PATCH] IG: ignore method if removing it would break compilation (IDEA-185066) --- .../RedundantMethodOverrideInspection.java | 11 ++++++----- .../RedundantMethodOverride.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java index cdd6afb1167a..fef06d06b2d5 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2017 Bas Leijdekkers + * Copyright 2005-2018 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,14 +86,15 @@ public class RedundantMethodOverrideInspection extends BaseInspection { public void visitMethod(PsiMethod method) { super.visitMethod(method); final PsiCodeBlock body = method.getBody(); - if (body == null) { + if (body == null || method.getNameIdentifier() == null) { return; } - if (method.getNameIdentifier() == null) { + final PsiMethod[] methods = method.findSuperMethods(); + if (methods.length == 0) { return; } - final PsiMethod superMethod = MethodUtils.getSuper(method); - if (superMethod == null) { + final PsiMethod superMethod = methods[0]; + if (superMethod.hasModifierProperty(PsiModifier.DEFAULT) && methods.length > 1) { return; } if (!MethodUtils.haveEquivalentModifierLists(method, superMethod)) { diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java index 4ccc8caf7223..03fc2af16a7e 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java @@ -145,3 +145,18 @@ class Annotations2 extends Annotations1{ super.m(); } } +/////////////// +interface XX { + void x(); +} +interface YY { + default void x() { + System.out.println(); + } +} +class ZZ implements YY, XX { + @Override + public void x() { + YY.super.x(); + } +} \ No newline at end of file