mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Unit test for IDEA-211140 (IDEA-CR-46794)
GitOrigin-RevId: 1b8b24a4bc6d5ffc2d611d30fea6308aef7ac688
This commit is contained in:
committed by
intellij-monorepo-bot
parent
827eb494d9
commit
1267e002aa
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
package pkg;
|
||||
|
||||
interface Conflict {
|
||||
String getNullableSomething();
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
package pkg;
|
||||
|
||||
interface Conflict {
|
||||
@javax.annotation.Nullable String getNullableSomething();
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
package pkg;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.PACKAGE)
|
||||
@javax.annotation.Nonnull
|
||||
@javax.annotation.meta.TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
package pkg;
|
||||
|
||||
class Test {
|
||||
String foo() {return "foo";}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
// Recompile if necessary adding jsr305-3.0.2.jar to classpath
|
||||
// e.g. javac -cp %USERPROFILE%\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar pkg/*.java
|
||||
@NonNullApi
|
||||
package pkg;
|
||||
+56
-3
@@ -1,11 +1,24 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInsight.NullableNotNullManagerImpl;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.*;
|
||||
import com.intellij.java.testutil.MavenDependencyUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.LightPlatformTestCase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assume;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,6 +34,23 @@ public class NullableNotNullManagerTest extends LightPlatformTestCase {
|
||||
myManager = (NullableNotNullManagerImpl)manager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
super.configureModule(module, model, contentEntry);
|
||||
VirtualFile file =
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(JavaTestUtil.getJavaTestDataPath() + "/nullableAnnotations/");
|
||||
MavenDependencyUtil.addFromMaven(model, "com.google.code.findbugs:jsr305:3.0.2");
|
||||
// Library order is important
|
||||
PsiTestUtil.newLibrary("lib_2.0").classesRoot(file.findChild("lib_2.0")).addTo(model);
|
||||
PsiTestUtil.newLibrary("lib_1.0").classesRoot(file.findChild("lib_1.0")).addTo(model);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
@@ -33,6 +63,29 @@ public class NullableNotNullManagerTest extends LightPlatformTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testSplitPackageContainerAnnotation() {
|
||||
// Check that annotations work normally
|
||||
NullabilityAnnotationInfo fooNullability = getMethodReturnNullability("pkg.Test", "foo");
|
||||
assertNotNull(fooNullability);
|
||||
assertEquals(Nullability.NOT_NULL, fooNullability.getNullability());
|
||||
assertTrue(fooNullability.isContainer());
|
||||
|
||||
// Check the conflicting case
|
||||
NullabilityAnnotationInfo nullability = getMethodReturnNullability("pkg.Conflict", "getNullableSomething");
|
||||
assertNull(nullability);
|
||||
}
|
||||
|
||||
private static NullabilityAnnotationInfo getMethodReturnNullability(String className, String methodName) {
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
|
||||
NullableNotNullManager manager = NullableNotNullManager.getInstance(getProject());
|
||||
PsiClass testClass = facade.findClass(className, scope);
|
||||
assertNotNull(testClass);
|
||||
PsiMethod[] fooMethods = testClass.findMethodsByName(methodName, false);
|
||||
assertSize(1, fooMethods);
|
||||
return manager.findEffectiveNullabilityInfo(fooMethods[0]);
|
||||
}
|
||||
|
||||
public void testCannotAddNotNullToNullable() {
|
||||
assertNotNull(myManager);
|
||||
|
||||
Reference in New Issue
Block a user