mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-10 08:31:32 +00:00
Ignore built-in type qualifier defaults when Jsr305State=IGNORE
This commit is contained in:
35
compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.kt
vendored
Normal file
35
compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.kt
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_ANNOTATIONS_IGNORE
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
import javax.annotation.*;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class A {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main(a: A) {
|
||||
// foo is platform
|
||||
a.foo("", "", null)?.length
|
||||
a.foo("", "", null).length
|
||||
a.foo(null, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
13
compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.txt
vendored
Normal file
13
compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public fun main(/*0*/ a: A): kotlin.Unit
|
||||
|
||||
@javax.annotation.ParametersAreNonnullByDefault public open class A {
|
||||
public constructor A()
|
||||
@javax.annotation.Nullable public final var field: kotlin.String?
|
||||
@javax.annotation.Nonnull public open fun bar(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun foo(/*0*/ q: kotlin.String!, /*1*/ @javax.annotation.Nonnull x: kotlin.String, /*2*/ @javax.annotation.CheckForNull y: kotlin.CharSequence?): kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -29,6 +29,7 @@ val TEST_ANNOTATIONS_SOURCE_PATH = "compiler/testData/foreignAnnotations/testAnn
|
||||
|
||||
abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
|
||||
private val WARNING_FOR_JSR305_ANNOTATIONS_DIRECTIVE = "WARNING_FOR_JSR305_ANNOTATIONS"
|
||||
private val JSR305_ANNOTATIONS_IGNORE_DIRECTIVE = "JSR305_ANNOTATIONS_IGNORE"
|
||||
|
||||
override fun getExtraClasspath(): List<File> {
|
||||
val foreignAnnotations = listOf(MockLibraryUtil.compileJvmLibraryToJar(annotationsPath, "foreign-annotations"))
|
||||
@@ -54,7 +55,16 @@ abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
|
||||
InTextDirectivesUtils.isDirectiveDefined(it.expectedText, WARNING_FOR_JSR305_ANNOTATIONS_DIRECTIVE)
|
||||
}
|
||||
|
||||
val jsr305State = if (hasWarningDirective) Jsr305State.WARN else Jsr305State.STRICT
|
||||
val hasIgnoreDirective = module.any {
|
||||
InTextDirectivesUtils.isDirectiveDefined(it.expectedText, JSR305_ANNOTATIONS_IGNORE_DIRECTIVE)
|
||||
}
|
||||
|
||||
val jsr305State = when {
|
||||
hasIgnoreDirective -> Jsr305State.IGNORE
|
||||
hasWarningDirective -> Jsr305State.WARN
|
||||
else -> Jsr305State.STRICT
|
||||
}
|
||||
|
||||
return LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE,
|
||||
mapOf(AnalysisFlag.jsr305 to jsr305State)
|
||||
)
|
||||
|
||||
@@ -90,6 +90,21 @@ public class ForeignAnnotationsNoAnnotationInClasspathTestGenerated extends Abst
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jsr305Ignore extends AbstractForeignAnnotationsNoAnnotationInClasspathTest {
|
||||
public void testAllFilesPresentInJsr305Ignore() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305Ignore"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("parametersAreNonnullByDefault.kt")
|
||||
public void testParametersAreNonnullByDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -90,6 +90,21 @@ public class ForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTestGe
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jsr305Ignore extends AbstractForeignAnnotationsNoAnnotationInClasspathWithFastClassReadingTest {
|
||||
public void testAllFilesPresentInJsr305Ignore() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305Ignore"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("parametersAreNonnullByDefault.kt")
|
||||
public void testParametersAreNonnullByDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -90,6 +90,21 @@ public class ForeignAnnotationsTestGenerated extends AbstractForeignAnnotationsT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jsr305Ignore extends AbstractForeignAnnotationsTest {
|
||||
public void testAllFilesPresentInJsr305Ignore() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305Ignore"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("parametersAreNonnullByDefault.kt")
|
||||
public void testParametersAreNonnullByDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -90,6 +90,21 @@ public class JavacForeignAnnotationsTestGenerated extends AbstractJavacForeignAn
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jsr305Ignore extends AbstractJavacForeignAnnotationsTest {
|
||||
public void testAllFilesPresentInJsr305Ignore() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotations/tests/jsr305Ignore"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("parametersAreNonnullByDefault.kt")
|
||||
public void testParametersAreNonnullByDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/jsr305Ignore/parametersAreNonnullByDefault.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -112,6 +112,8 @@ fun LazyJavaResolverContext.child(
|
||||
fun LazyJavaResolverContext.computeNewDefaultTypeQualifiers(
|
||||
additionalAnnotations: Annotations
|
||||
): JavaTypeQualifiersByElementType? {
|
||||
if (components.annotationTypeQualifierResolver.jsr305State.isIgnored()) return defaultTypeQualifiers
|
||||
|
||||
val nullabilityQualifiersWithApplicability =
|
||||
additionalAnnotations.mapNotNull(this::extractDefaultNullabilityQualifier)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user