Java: don't skip marking superclasses when class is an entry point (IDEA-329870)

in "Declaration can have 'final' modifier" inspection

GitOrigin-RevId: 4f2504fc50e2190b8e71b0d1a6f91a3e0e96f9eb
This commit is contained in:
Bas Leijdekkers
2023-08-24 16:09:48 +02:00
committed by intellij-monorepo-bot
parent 9864174cc7
commit 152f8b838c
4 changed files with 15 additions and 11 deletions

View File

@@ -34,7 +34,6 @@ class CanBeFinalAnnotator extends RefGraphAnnotatorEx {
if (refElement instanceof RefClass refClass) {
if (refClass.isEntry()) {
((RefClassImpl)refClass).setFlag(false, CAN_BE_FINAL_MASK);
return;
}
for (RefClass baseClass : refClass.getBaseClasses()) {
baseClass.initializeIfNeeded();
@@ -98,14 +97,7 @@ class CanBeFinalAnnotator extends RefGraphAnnotatorEx {
if (refElement instanceof RefClass) {
final PsiClass psiClass = ObjectUtils.tryCast(refElement.getPsiElement(), PsiClass.class);
if (psiClass != null) {
if (refElement.isEntry()) {
((RefClassImpl)refElement).setFlag(false, CAN_BE_FINAL_MASK);
}
PsiField[] psiFields = psiClass.getFields();
Set<PsiVariable> allFields = new HashSet<>();
ContainerUtil.addAll(allFields, psiFields);
List<PsiVariable> instanceInitializerInitializedFields = new ArrayList<>();

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>

View File

@@ -0,0 +1,6 @@
@Deprecated
public class A extends B {
}
class B {
}

View File

@@ -1,5 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInspection;
import com.intellij.JavaTestUtil;
@@ -26,7 +25,7 @@ public class CanBeFinalInspectionTest extends JavaInspectionTestCase {
}
private void doTest(final CanBeFinalInspection tool) {
doTest("canBeFinal/" + getTestName(false), tool);
doTest("canBeFinal/" + getTestName(false), tool, false, true);
}
public void testsimpleClassInheritanceField() {
@@ -36,6 +35,10 @@ public class CanBeFinalInspectionTest extends JavaInspectionTestCase {
public void testassignedFromLambda() {
doTest();
}
public void testDeprecated() {
doTest();
}
public void testassignedFromLambdaInClassInitializer() {
doTest();