Java: remove spurious error highlighting (IDEA-340885)

GitOrigin-RevId: 955d86aca0ceb262cee8f3ae5744856108eeb412
This commit is contained in:
Bas Leijdekkers
2023-12-13 18:17:35 +01:00
committed by intellij-monorepo-bot
parent 9b4e551e2d
commit 88bd39ef0d
9 changed files with 29 additions and 22 deletions

View File

@@ -657,9 +657,9 @@ public final class HighlightClassUtil {
}
return null;
}
if (baseClass.hasModifierProperty(PsiModifier.FINAL)) return null;
String description = JavaErrorBundle.message("no.default.constructor.available", HighlightUtil.formatClass(baseClass));
HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range).descriptionAndTooltip(description);
IntentionAction action = QuickFixFactory.getInstance().createCreateConstructorMatchingSuperFix(aClass);
info.registerFix(action, null, null, null, null);

View File

@@ -1,11 +1,10 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.util;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.*;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.MethodSignatureUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.*;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,17 +24,19 @@ public final class JavaPsiConstructorUtil {
@Nullable
public static PsiMethodCallExpression findThisOrSuperCallInConstructor(@NotNull PsiMethod constructor) {
if (!constructor.isConstructor()) return null;
PsiCodeBlock body = constructor.getBody();
if (body == null) return null;
PsiElement bodyElement = body.getFirstBodyElement();
while (bodyElement != null && !(bodyElement instanceof PsiStatement)) {
bodyElement = bodyElement.getNextSibling();
}
if (!(bodyElement instanceof PsiExpressionStatement)) return null;
PsiMethodCallExpression call =
ObjectUtils.tryCast(((PsiExpressionStatement)bodyElement).getExpression(), PsiMethodCallExpression.class);
if (isConstructorCall(call)) return call;
return null;
return CachedValuesManager.getCachedValue(constructor, () -> {
PsiCodeBlock body = constructor.getBody();
if (body == null) return new CachedValueProvider.Result<>(null, PsiModificationTracker.MODIFICATION_COUNT);
Ref<PsiMethodCallExpression> result = new Ref<>();
PsiTreeUtil.processElements(body, PsiMethodCallExpression.class, call -> {
if (isConstructorCall(call)) {
result.set(call);
return false;
}
return true;
});
return new CachedValueProvider.Result<>(result.get(), PsiModificationTracker.MODIFICATION_COUNT);
});
}
/**

View File

@@ -125,7 +125,7 @@ class.name.expected=Class name expected
no.enclosing.instance.in.scope=No enclosing instance of type ''{0}'' is in scope
is.not.an.enclosing.class=''{0}'' is not an enclosing class
cannot.be.referenced.from.static.context=''{0}'' cannot be referenced from a static context
no.default.constructor.available=There is no default constructor available in ''{0}''
no.default.constructor.available=There is no parameterless constructor available in ''{0}''
missing.return.statement=Missing return statement
unreachable.statement=Unreachable statement
unreachable.statement.false.condition=Loop condition is always false making the loop body unreachable

View File

@@ -39,7 +39,7 @@ class b extends a {
}
}
class O extends <error descr="No enclosing instance of type 'A' is in scope">A.B</error>
class O extends A.B
{
public O(A a)
{

View File

@@ -0,0 +1,5 @@
final class X {
X(int i) {}
}
class A extends <error descr="Cannot inherit from final 'X'">X</error> {
}

View File

@@ -7,11 +7,11 @@ class a {
// super ctr
<error descr="There is no default constructor available in 'a'">class b extends a</error> {
<error descr="There is no parameterless constructor available in 'a'">class b extends a</error> {
}
class c extends a {
<error descr="There is no default constructor available in 'a'">c()</error> {
<error descr="There is no parameterless constructor available in 'a'">c()</error> {
}
c(String s) {

View File

@@ -44,7 +44,7 @@ enum enumWithTypeParameterInValueOf {
<error descr="'valueOf(String)' clashes with 'valueOf(String)'; both methods have same erasure"><error descr="'valueOf(String)' is already defined in 'enumWithTypeParameterInValueOf'">static <T> void valueOf(String s)</error></error> {}
}
<error descr="There is no default constructor available in 'Operation'">class exte extends <error descr="Cannot inherit from enum 'Operation'">Operation</error></error> {
class exte extends <error descr="Cannot inherit from enum 'Operation'">Operation</error> {
}
enum withConstant {

View File

@@ -38,7 +38,7 @@ enum Operation {
<error descr="'valueOf(String)' is already defined in 'Operation'">void valueOf(String s)</error> {}
}
<error descr="There is no default constructor available in 'Operation'">class exte extends <error descr="Cannot inherit from enum 'Operation'">Operation</error></error> {
class exte extends <error descr="Cannot inherit from enum 'Operation'">Operation</error> {
}
class use {

View File

@@ -378,6 +378,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testUnsupportedFeatures() { doTest(false); }
public void testThisBeforeSuper() { doTest(false); }
public void testExplicitConstructorInvocation() { doTest(false); }
public void testExtendFinalClass() { doTest(false); }
public void testThisInInterface() { doTest(false); }
public void testInnerClassConstantReference() { doTest(false); }
public void testIDEA60875() { doTest(false); }