[java-highlighting] IDEA-365996 Constructor in an implicitly declared class is not highlighted as error

(cherry picked from commit 2de45c452608cea2ab314511060ac733259a8c18)

GitOrigin-RevId: daed31a96a3fb96a6cbed183443ed90205b679f3
This commit is contained in:
Mikhail Pyltsin
2025-01-21 19:27:21 +01:00
committed by intellij-monorepo-bot
parent 35c774bf7d
commit b3f8bbb608
6 changed files with 41 additions and 1 deletions

View File

@@ -2341,6 +2341,22 @@ public final class HighlightMethodUtil {
return MethodSignatureUtil.areSignaturesErasureEqual(valueOfMethod, methodSignature);
}
static HighlightInfo.@Nullable Builder checkConstructorInImplicitClass(@NotNull PsiMethod method) {
if (!method.isConstructor()) {
return null;
}
if (!(method.getContainingClass() instanceof PsiImplicitClass)) {
return null;
}
String description = JavaErrorBundle.message("implicit.class.with.explicit.constructor");
TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method);
HighlightInfo.Builder builder =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description);
IntentionAction action = QuickFixFactory.getInstance().createDeleteFix(method);
builder.registerFix(action, null, null, null, null);
return builder;
}
private static final class ReturnModel {
final PsiReturnStatement myStatement;
final PsiType myType;

View File

@@ -934,6 +934,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
@Override
public void visitMethod(@NotNull PsiMethod method) {
super.visitMethod(method);
if (!hasErrorResults()) add(HighlightMethodUtil.checkConstructorInImplicitClass(method));
if (!hasErrorResults()) add(HighlightControlFlowUtil.checkUnreachableStatement(method.getBody()));
if (!hasErrorResults()) add(HighlightMethodUtil.checkConstructorHandleSuperClassExceptions(method));
if (!hasErrorResults()) add(GenericsHighlightUtil.checkSafeVarargsAnnotation(method, myLanguageLevel));