Use new jetbrains annotations with type use target for "load java 8" tests

This commit is contained in:
Victor Petukhov
2020-12-08 15:44:04 +03:00
parent 6f64e2c036
commit 8777d28228
48 changed files with 1254 additions and 895 deletions
@@ -24,15 +24,11 @@ import org.jetbrains.kotlin.utils.JavaTypeEnhancementState
import org.jetbrains.kotlin.utils.ReportLevel
import java.io.File
val FOREIGN_ANNOTATIONS_SOURCES_PATH = "third-party/annotations"
val TEST_ANNOTATIONS_SOURCE_PATH = "compiler/testData/foreignAnnotations/testAnnotations"
const val FOREIGN_ANNOTATIONS_SOURCES_PATH = "third-party/annotations"
const val FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH = "third-party/jdk8-annotations"
const val TEST_ANNOTATIONS_SOURCE_PATH = "compiler/testData/foreignAnnotations/testAnnotations"
abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
private val JSR305_GLOBAL_DIRECTIVE = "JSR305_GLOBAL_REPORT"
private val JSR305_MIGRATION_DIRECTIVE = "JSR305_MIGRATION_REPORT"
private val JSR305_SPECIAL_DIRECTIVE = "JSR305_SPECIAL_REPORT"
private val JSPECIFY_STATE_SPECIAL_DIRECTIVE = "JSPECIFY_STATE"
override fun getExtraClasspath(): List<File> {
val foreignAnnotations = createJarWithForeignAnnotations()
return foreignAnnotations + compileTestAnnotations(foreignAnnotations)
@@ -51,7 +47,7 @@ abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
ForTestCompileRuntime.jvmAnnotationsForTests()
)
open protected val annotationsPath: String
protected open val annotationsPath: String
get() = FOREIGN_ANNOTATIONS_SOURCES_PATH
override fun loadLanguageVersionSettings(module: List<TestFile>): LanguageVersionSettings {
@@ -92,4 +88,11 @@ abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
private fun List<TestFile>.getDirectiveValue(directive: String): ReportLevel? = mapNotNull {
InTextDirectivesUtils.findLinesWithPrefixesRemoved(it.expectedText, directive).firstOrNull()
}.firstOrNull().let { ReportLevel.findByDescription(it) }
companion object {
private const val JSR305_GLOBAL_DIRECTIVE = "JSR305_GLOBAL_REPORT"
private const val JSR305_MIGRATION_DIRECTIVE = "JSR305_MIGRATION_REPORT"
private const val JSR305_SPECIAL_DIRECTIVE = "JSR305_SPECIAL_REPORT"
private const val JSPECIFY_STATE_SPECIAL_DIRECTIVE = "JSPECIFY_STATE"
}
}
@@ -27,7 +27,7 @@ abstract class AbstractJspecifyAnnotationsTest : AbstractDiagnosticsTest() {
super.doMultiFileTest(
wholeFile,
files,
MockLibraryUtil.compileJavaFilesLibraryToJar(FOREIGN_ANNOTATIONS_SOURCES_PATH, "foreign-annotations")
MockLibraryUtil.compileJavaFilesLibraryToJar(FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH, "foreign-annotations")
)
}
@@ -149,7 +149,6 @@ abstract class AbstractJspecifyAnnotationsTest : AbstractDiagnosticsTest() {
}
companion object {
const val FOREIGN_ANNOTATIONS_SOURCES_PATH = "third-party/jdk8-annotations"
const val JSPECIFY_JAVA_SOURCES_PATH = "compiler/testData/foreignAnnotationsJava8/tests/jspecify/java"
const val MAIN_KT_FILE_DIRECTIVE = "// FILE: main.kt\n"
@@ -261,7 +261,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
.replace(TESTDATA_DIR, testDataDir)
.replace(
"$FOREIGN_ANNOTATIONS_DIR$",
new File(AbstractForeignAnnotationsTestKt.getFOREIGN_ANNOTATIONS_SOURCES_PATH()).getPath()
new File(AbstractForeignAnnotationsTestKt.FOREIGN_ANNOTATIONS_SOURCES_PATH).getPath()
).replace(
"$JDK_15$",
KtTestUtil.getJdk15Home().getPath()
@@ -59,6 +59,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
public static final Configuration
COMPARATOR_CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.renderDeclarationsFromOtherModules(true);
protected boolean withForeignAnnotations() { return false; }
protected void doTestCompiledJava(@NotNull String javaFileName) throws Exception {
doTestCompiledJava(javaFileName, COMPARATOR_CONFIGURATION);
}
@@ -148,7 +150,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(
tmpdir, getTestRootDisposable(), getJdkKind(), configurationKind, true, false, useJavacWrapper(),
configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS),
withForeignAnnotations(), configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS),
getExtraClasspath(), this::configureEnvironment
).first;
@@ -274,7 +276,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
Pair<PackageViewDescriptor, BindingContext> javaPackageAndContext = loadTestPackageAndBindingContextFromJavaRoot(
tmpdir, getTestRootDisposable(), getJdkKind(), ConfigurationKind.JDK_ONLY, false,
false, useJavacWrapper(), null);
false, useJavacWrapper(), withForeignAnnotations(), null);
checkJavaPackage(
expectedFile, javaPackageAndContext.first, javaPackageAndContext.second,
@@ -329,9 +331,9 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
@NotNull File outDir,
@NotNull ConfigurationKind configurationKind
) throws IOException {
compileJavaWithAnnotationsJar(javaFiles, outDir, getAdditionalJavacArgs(), getJdkHomeForJavac());
compileJavaWithAnnotationsJar(javaFiles, outDir, getAdditionalJavacArgs(), getJdkHomeForJavac(), withForeignAnnotations());
return loadTestPackageAndBindingContextFromJavaRoot(outDir, getTestRootDisposable(), getJdkKind(), configurationKind, true,
usePsiClassFilesReading(), useJavacWrapper(), null,
usePsiClassFilesReading(), useJavacWrapper(), withForeignAnnotations(), null,
getExtraClasspath(), this::configureEnvironment);
}
@@ -43,10 +43,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestJdkKind;
import org.jetbrains.kotlin.test.*;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
@@ -56,6 +53,8 @@ import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static org.jetbrains.kotlin.checkers.AbstractForeignAnnotationsTestKt.FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH;
public class LoadDescriptorUtil {
@NotNull
public static final FqName TEST_PACKAGE_FQNAME = FqName.topLevel(Name.identifier("test"));
@@ -81,6 +80,7 @@ public class LoadDescriptorUtil {
boolean isBinaryRoot,
boolean usePsiClassReading,
boolean useJavacWrapper,
boolean withForeignAnnotations,
@Nullable LanguageVersionSettings explicitLanguageVersionSettings
) {
return loadTestPackageAndBindingContextFromJavaRoot(
@@ -91,6 +91,7 @@ public class LoadDescriptorUtil {
isBinaryRoot,
usePsiClassReading,
useJavacWrapper,
withForeignAnnotations,
explicitLanguageVersionSettings,
Collections.emptyList(),
(configuration) -> {}
@@ -106,12 +107,16 @@ public class LoadDescriptorUtil {
boolean isBinaryRoot,
boolean usePsiClassReading,
boolean useJavacWrapper,
boolean withForeignAnnotations,
@Nullable LanguageVersionSettings explicitLanguageVersionSettings,
@NotNull List<File> additionalClasspath,
@NotNull Consumer<KotlinCoreEnvironment> configureEnvironment
) {
List<File> javaBinaryRoots = new ArrayList<>();
// TODO: use the same additional binary roots as those were used for compilation
if (withForeignAnnotations) {
javaBinaryRoots.add(MockLibraryUtil.compileJavaFilesLibraryToJar(FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH, "foreign-annotations"));
}
javaBinaryRoots.add(KtTestUtil.getAnnotationsJar());
javaBinaryRoots.add(ForTestCompileRuntime.jvmAnnotationsForTests());
javaBinaryRoots.addAll(additionalClasspath);
@@ -147,7 +152,8 @@ public class LoadDescriptorUtil {
@NotNull Collection<File> javaFiles,
@NotNull File outDir,
@NotNull List<String> additionalArgs,
@Nullable File customJdkHomeForJavac
@Nullable File customJdkHomeForJavac,
boolean useJetbrainsAnnotationsWithTypeUse
) throws IOException {
List<String> args = new ArrayList<>(Arrays.asList(
"-sourcepath", "compiler/testData/loadJava/include",
@@ -157,6 +163,9 @@ public class LoadDescriptorUtil {
List<File> classpath = new ArrayList<>();
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
if (useJetbrainsAnnotationsWithTypeUse) {
classpath.add(MockLibraryUtil.compileJavaFilesLibraryToJar(FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH, "foreign-annotations"));
}
classpath.add(KtTestUtil.getAnnotationsJar());
for (File test : javaFiles) {