提交 a644dd3a 编写于 作者: D Denis Zharkov

Create tests for TYPE_USE nullability annotations

- tests and declarations for checkerframework has been moved,
because they only Java 8 targeted
- tests for eclipse annotations has been just copied,
because there are two jars: one for Java 8 and other for earlier versions
上级 3f3c2bb2
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/foreignAnnotationsJava8/tests")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class ForeignJava8AnnotationsTestGenerated extends AbstractForeignJava8AnnotationsTest {
public void testAllFilesPresentInTests() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("checkerFramework.kt")
public void testCheckerFramework() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotationsJava8/tests/checkerFramework.kt");
doTest(fileName);
}
@TestMetadata("eclipse.kt")
public void testEclipse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotationsJava8/tests/eclipse.kt");
doTest(fileName);
}
}
...@@ -35,7 +35,6 @@ import java.lang.annotation.Target; ...@@ -35,7 +35,6 @@ import java.lang.annotation.Target;
*/ */
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
// TODO: originally it's target was: TYPE_USE, TYPE_PARAMETER @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE })
public @interface NonNull { public @interface NonNull {
} }
\ No newline at end of file
...@@ -22,7 +22,6 @@ import java.lang.annotation.Target; ...@@ -22,7 +22,6 @@ import java.lang.annotation.Target;
*/ */
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
// TODO: originally it's target was: TYPE_USE, TYPE_PARAMETER @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE })
public @interface Nullable { public @interface Nullable {
} }
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2011, 2013 Stephan Herrmann and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Stephan Herrmann - initial API and implementation
* IBM Corporation - bug fixes
*******************************************************************************/
package org.eclipse.jdt.annotation;
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Qualifier for a reference type in a {@link ElementType#TYPE_USE TYPE_USE} position:
* The type that has this annotation is intended to not include the value <code>null</code>.
* <p>
* If annotation based null analysis is enabled using this annotation has two consequences:
* </p>
* <ol>
* <li>Dereferencing an expression of this type is safe, i.e., no <code>NullPointerException</code> can occur at runtime.</li>
* <li>An attempt to bind a <code>null</code> value to an entity (field, local variable, method parameter or method return value)
* of this type is a compile time error.</li>
* </ol>
* For the second case, diagnostics issued by the compiler should distinguish three situations:
* <ol>
* <li>Nullness of the value can be statically determined, the entity is definitely bound from either of:
* <ul><li>the value <code>null</code>, or</li>
* <li>an entity with a {@link Nullable @Nullable} type.</li></ul></li>
* <li>Nullness cannot definitely be determined, because different code branches yield different results.</li>
* <li>Nullness cannot be determined, because other program elements are involved for which
* null annotations are lacking.</li>
* </ol>
* <p>
* <b>Note:</b> Since org.eclipse.jdt.annotation 2.0.0, the
* <code>@Target</code> is <code>{TYPE_USE}</code>. For the old API, see
* <a href="http://help.eclipse.org/kepler/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/annotation/NonNull.html">
* <code>@NonNull</code> in 1.1.0</a>.
* </p>
* @since 1.0
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ TYPE_USE })
public @interface NonNull {
// marker annotation with no members
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2011, 2013 Stephan Herrmann and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Stephan Herrmann - initial API and implementation
* IBM Corporation - bug fixes
*******************************************************************************/
package org.eclipse.jdt.annotation;
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Qualifier for a reference type in a {@link ElementType#TYPE_USE TYPE_USE} position:
* The type that has this annotation explicitly includes the value <code>null</code>.
* <p>
* If annotation based null analysis is enabled using this annotation has two consequences:
* </p>
* <ol>
* <li>Binding a <code>null</code> value to an entity (field, local variable, method parameter or method return value)
* of this type is legal.</li>
* <li>Dereferencing an expression of this type is unsafe, i.e., a <code>NullPointerException</code> can occur at runtime.</li>
* </ol>
* <p>
* <b>Note:</b> Since org.eclipse.jdt.annotation 2.0.0, the
* <code>@Target</code> is <code>{TYPE_USE}</code>. For the old API, see
* <a href="http://help.eclipse.org/kepler/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/annotation/Nullable.html">
* <code>@Nullable</code> in 1.1.0</a>.
* </p>
* @since 1.0
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ TYPE_USE })
public @interface Nullable {
// marker annotation with no members
}
\ No newline at end of file
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// FILE: A.java
import org.eclipse.jdt.annotation.*;
public class A<T> {
@Nullable public String field = null;
@Nullable
public String foo(@NonNull String x, @Nullable CharSequence y) {
return "";
}
@NonNull
public String bar() {
return "";
}
@Nullable
public T baz(@NonNull T x) { return x; }
}
// FILE: main.kt
fun main(a: A<String>, a1: A<String?>) {
a.foo("", null)?.length
a.foo("", null)<!UNSAFE_CALL!>.<!>length
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.bar().length
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field?.length
a.field<!UNSAFE_CALL!>.<!>length
a.baz("")<!UNSAFE_CALL!>.<!>length
a.baz("")?.length
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
a1.baz("")!!.length
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
}
package
public fun main(/*0*/ a: A<kotlin.String>, /*1*/ a1: A<kotlin.String?>): kotlin.Unit
public open class A</*0*/ T : kotlin.Any!> {
public constructor A</*0*/ T : kotlin.Any!>()
@org.eclipse.jdt.annotation.Nullable() public final var field: kotlin.String?
@org.eclipse.jdt.annotation.NonNull() public open fun bar(): kotlin.String
@org.eclipse.jdt.annotation.Nullable() public open fun baz(/*0*/ @org.eclipse.jdt.annotation.NonNull() x: T): T?
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@org.eclipse.jdt.annotation.Nullable() public open fun foo(/*0*/ @org.eclipse.jdt.annotation.NonNull() x: kotlin.String, /*1*/ @org.eclipse.jdt.annotation.Nullable() 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
}
...@@ -22,8 +22,11 @@ import java.io.File ...@@ -22,8 +22,11 @@ import java.io.File
abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() { abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
override fun getExtraClasspath(): List<File> { override fun getExtraClasspath(): List<File> {
return listOf(MockLibraryUtil.compileLibraryToJar( return listOf(MockLibraryUtil.compileLibraryToJar(
"compiler/testData/foreignAnnotations/annotations", annotationsPath,
"foreign-annotations", /* addSources = */false, /* allowKotlinPackage = */ false "foreign-annotations", /* addSources = */false, /* allowKotlinPackage = */ false
)) ))
} }
open protected val annotationsPath: String
get() = "compiler/testData/foreignAnnotations/annotations"
} }
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.checkers
abstract class AbstractForeignJava8AnnotationsTest : AbstractForeignAnnotationsTest() {
override val annotationsPath: String
get() = "compiler/testData/foreignAnnotationsJava8/annotations"
}
...@@ -47,12 +47,6 @@ public class ForeignAnnotationsTestGenerated extends AbstractForeignAnnotationsT ...@@ -47,12 +47,6 @@ public class ForeignAnnotationsTestGenerated extends AbstractForeignAnnotationsT
doTest(fileName); doTest(fileName);
} }
@TestMetadata("checkerFramework.kt")
public void testCheckerFramework() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/checkerFramework.kt");
doTest(fileName);
}
@TestMetadata("eclipse.kt") @TestMetadata("eclipse.kt")
public void testEclipse() throws Exception { public void testEclipse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/eclipse.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/foreignAnnotations/tests/eclipse.kt");
......
...@@ -343,6 +343,9 @@ fun main(args: Array<String>) { ...@@ -343,6 +343,9 @@ fun main(args: Array<String>) {
testClass<AbstractDiagnosticsWithFullJdkTest>("DiagnosticsWithJava8TestGenerated") { testClass<AbstractDiagnosticsWithFullJdkTest>("DiagnosticsWithJava8TestGenerated") {
model("diagnostics/testsWithJava8") model("diagnostics/testsWithJava8")
} }
testClass<AbstractForeignJava8AnnotationsTest>() {
model("foreignAnnotationsJava8/tests")
}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册