mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[java-inspections] NullableStuffInspectionBase: fix record constructor support
GitOrigin-RevId: defcd306c9f5a32c027cbc2105ac3224878de452
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf4cebe086
commit
b038d3db65
@@ -942,7 +942,9 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
PsiParameter parameter) {
|
||||
if (!REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER || !holder.isOnTheFly()) return;
|
||||
|
||||
PsiVariable owner = Objects.requireNonNullElse(JavaPsiRecordUtil.getComponentForCanonicalConstructorParameter(parameter), parameter);
|
||||
PsiVariable owner = parameter.isPhysical() ? parameter : JavaPsiRecordUtil.getComponentForCanonicalConstructorParameter(parameter);
|
||||
if (owner == null) return;
|
||||
|
||||
PsiElement elementToHighlight = null;
|
||||
NullabilityAnnotationInfo info = nullableManager.findOwnNullabilityInfo(owner);
|
||||
if (info != null && !info.isInferred()) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightCompactConstructorParameter;
|
||||
import com.intellij.psi.impl.light.LightRecordCanonicalConstructor;
|
||||
import com.intellij.psi.impl.light.LightRecordField;
|
||||
import com.intellij.psi.impl.source.DummyHolder;
|
||||
@@ -74,6 +75,9 @@ public final class JavaPsiRecordUtil {
|
||||
* @return record component that corresponds to the parameter
|
||||
*/
|
||||
public static @Nullable PsiRecordComponent getComponentForCanonicalConstructorParameter(@NotNull PsiParameter parameter) {
|
||||
if (parameter instanceof LightCompactConstructorParameter) {
|
||||
return ((LightCompactConstructorParameter)parameter).getRecordComponent();
|
||||
}
|
||||
PsiClass aClass = PsiTreeUtil.getParentOfType(parameter, PsiClass.class);
|
||||
if (aClass == null) return null;
|
||||
String parameterName = parameter.getName();
|
||||
|
||||
@@ -22,11 +22,26 @@ class Main111 {
|
||||
record MyRecord(<warning descr="Parameter annotated @NotNull should not receive 'null' as an argument">@NotNull</warning> Object o,
|
||||
@NotNull Object o2) {}
|
||||
|
||||
record MyRecord2(<warning descr="Parameter annotated @NotNull should not receive 'null' as an argument">@NotNull</warning> Object o,
|
||||
@NotNull Object o2) {
|
||||
MyRecord2 {
|
||||
}
|
||||
}
|
||||
|
||||
record MyRecord3(@NotNull Object o, @NotNull Object o2) {
|
||||
MyRecord3(<warning descr="Parameter annotated @NotNull should not receive 'null' as an argument">@NotNull</warning> Object o, @NotNull Object o2) {
|
||||
this.o = o;
|
||||
this.o2 = o2;
|
||||
}
|
||||
}
|
||||
|
||||
static void main() {
|
||||
new Main111(null);
|
||||
new Main111.SubClass(null);
|
||||
new SubClass2(null);
|
||||
new MyRecord(null, "");
|
||||
new MyRecord2(null, "");
|
||||
new MyRecord3(null, "");
|
||||
|
||||
new ParamerizedRunnable(null) {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user