mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
[java-analysis] Support container annotations on JPMS module
Fixes IDEA-323691 JSpecify's NullMarked not considered when Java module is annotated GitOrigin-RevId: d84fe78d9e2f0c4a2bbe7471855310762e833ba4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
87c2fae2e8
commit
e4d46e812c
@@ -3,6 +3,7 @@ package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.annoPackages.AnnotationPackageSupport;
|
||||
import com.intellij.codeInsight.annoPackages.Jsr305Support;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaModuleGraphUtil;
|
||||
import com.intellij.codeInspection.dataFlow.HardcodedContracts;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.ide.plugins.DynamicPluginListener;
|
||||
@@ -413,4 +414,14 @@ public class NullableNotNullManagerImpl extends NullableNotNullManager implement
|
||||
public long getModificationCount() {
|
||||
return myTracker.getModificationCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable NullabilityAnnotationInfo findNullityDefaultOnModule(PsiAnnotation.@NotNull TargetType @NotNull [] targetTypes,
|
||||
@NotNull PsiElement element) {
|
||||
PsiJavaModule module = JavaModuleGraphUtil.findDescriptorByElement(element);
|
||||
if (module != null) {
|
||||
return getNullityDefault(module, targetTypes, element, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,8 +319,12 @@ public abstract class NullableNotNullManager {
|
||||
|
||||
if (element instanceof PsiClassOwner) {
|
||||
String packageName = ((PsiClassOwner)element).getPackageName();
|
||||
return findNullityDefaultOnPackage(placeTargetTypes, JavaPsiFacade.getInstance(element.getProject()).findPackage(packageName),
|
||||
place);
|
||||
PsiPackage psiPackage = JavaPsiFacade.getInstance(element.getProject()).findPackage(packageName);
|
||||
NullabilityAnnotationInfo fromPackage = findNullityDefaultOnPackage(placeTargetTypes, psiPackage, place);
|
||||
if (fromPackage != null) {
|
||||
return fromPackage;
|
||||
}
|
||||
return findNullityDefaultOnModule(placeTargetTypes, element);
|
||||
}
|
||||
|
||||
element = element.getContext();
|
||||
@@ -328,6 +332,11 @@ public abstract class NullableNotNullManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected @Nullable NullabilityAnnotationInfo findNullityDefaultOnModule(PsiAnnotation.@NotNull TargetType @NotNull [] types,
|
||||
@NotNull PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private @Nullable NullabilityAnnotationInfo findNullityDefaultOnPackage(PsiAnnotation.TargetType @NotNull [] placeTargetTypes,
|
||||
@Nullable PsiPackage psiPackage,
|
||||
PsiElement context) {
|
||||
@@ -432,7 +441,7 @@ public abstract class NullableNotNullManager {
|
||||
return result.get();
|
||||
}
|
||||
|
||||
interface NullabilityAnnotationDataHolder {
|
||||
protected interface NullabilityAnnotationDataHolder {
|
||||
/**
|
||||
* @return qualified names of all recognized annotations
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example;
|
||||
|
||||
public class NullabilityAnnotationOnModule {
|
||||
public static void main(String[] args) {
|
||||
if (<warning descr="Condition 'args == null' is always 'false'">args == null</warning>) return;
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.intellij.java.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DataFlowInspection9Test extends DataFlowInspectionTestCase {
|
||||
@@ -24,4 +25,22 @@ public class DataFlowInspection9Test extends DataFlowInspectionTestCase {
|
||||
public void testNewCollectionAliasing() { doTest(); }
|
||||
|
||||
public void testOptionalStreamInlining() { doTest(); }
|
||||
|
||||
public void testNullabilityAnnotationOnModule() {
|
||||
@Language("JAVA") String nullMarked =
|
||||
"""
|
||||
package org.jspecify.annotations;
|
||||
import java.lang.annotation.*;
|
||||
@Target(ElementType.MODULE)
|
||||
public @interface NullMarked {}""";
|
||||
myFixture.addClass(nullMarked);
|
||||
myFixture.addFileToProject("module-info.java", """
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
module jspecifysample {
|
||||
requires org.jspecify;
|
||||
}""");
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user