Don't verify mapping files and proper packagemapper propagation
This commit is contained in:
@@ -29,7 +29,7 @@ public abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
||||
val ktFile = File(filename)
|
||||
val txtFile = File(ktFile.parent, ktFile.nameWithoutExtension + ".txt")
|
||||
val generatedFiles = CodegenTestUtil.generateFiles(myEnvironment, myFiles)
|
||||
.asList()
|
||||
.getClassFiles()
|
||||
.sortedBy { it.relativePath }
|
||||
.map {
|
||||
val cr = ClassReader(it.asByteArray())
|
||||
|
||||
@@ -117,7 +117,7 @@ public class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
||||
private static List<Integer> extractActualLineNumbersFromBytecode(@NotNull GenerationState state, boolean testFunInvoke) {
|
||||
ClassFileFactory factory = state.getFactory();
|
||||
List<Integer> actualLineNumbers = Lists.newArrayList();
|
||||
for (OutputFile outputFile : factory.asList()) {
|
||||
for (OutputFile outputFile : CodegenPackage.getClassFiles(factory)) {
|
||||
if (PackageClassUtils.isPackageClassFqName(new FqName(FileUtil.getNameWithoutExtension(outputFile.getRelativePath())))) {
|
||||
// Don't test line numbers in *Package facade classes
|
||||
continue;
|
||||
|
||||
@@ -236,7 +236,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
|
||||
private static boolean verifyAllFilesWithAsm(ClassFileFactory factory, ClassLoader loader) {
|
||||
boolean noErrors = true;
|
||||
for (OutputFile file : factory.asList()) {
|
||||
for (OutputFile file : CodegenPackage.getClassFiles(factory)) {
|
||||
noErrors &= verifyWithAsm(file, loader);
|
||||
}
|
||||
return noErrors;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmPackageMappingProvider;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.utils.UtilsPackage;
|
||||
@@ -51,7 +52,8 @@ public class CodegenTestUtil {
|
||||
public static ClassFileFactory generateFiles(@NotNull KotlinCoreEnvironment environment, @NotNull CodegenTestFiles files) {
|
||||
AnalysisResult analysisResult = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||
environment.getProject(),
|
||||
files.getPsiFiles()
|
||||
files.getPsiFiles(),
|
||||
new JvmPackageMappingProvider(environment)
|
||||
);
|
||||
analysisResult.throwIfError();
|
||||
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DxChecker {
|
||||
array[0] = "testArgs";
|
||||
arguments.parse(array);
|
||||
|
||||
for (OutputFile file : outputFiles.asList()) {
|
||||
for (OutputFile file : CodegenPackage.getClassFiles(outputFiles)) {
|
||||
try {
|
||||
byte[] bytes = file.asByteArray();
|
||||
checkFileWithDx(bytes, file.getRelativePath(), arguments);
|
||||
|
||||
@@ -16,23 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.utils.join
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import java.util.ArrayList
|
||||
@@ -43,7 +35,7 @@ public object InlineTestUtil {
|
||||
|
||||
public val INLINE_ANNOTATION_CLASS: String = "kotlin/inline"
|
||||
|
||||
public fun checkNoCallsToInline(files: List<OutputFile>, sourceFiles: List<JetFile>) {
|
||||
public fun checkNoCallsToInline(files: Iterable<OutputFile>, sourceFiles: List<JetFile>) {
|
||||
val inlineInfo = obtainInlineInfo(files)
|
||||
val inlineMethods = inlineInfo.inlineMethods
|
||||
assert(!inlineMethods.isEmpty(), "There are no inline methods")
|
||||
@@ -64,7 +56,7 @@ public object InlineTestUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private fun obtainInlineInfo(files: List<OutputFile>): InlineInfo {
|
||||
private fun obtainInlineInfo(files: Iterable<OutputFile>): InlineInfo {
|
||||
val inlineMethods = HashSet<MethodInfo>()
|
||||
val classHeaders = hashMapOf<String, KotlinClassHeader>()
|
||||
|
||||
@@ -93,7 +85,7 @@ public object InlineTestUtil {
|
||||
return InlineInfo(inlineMethods, classHeaders)
|
||||
}
|
||||
|
||||
private fun checkInlineMethodNotInvoked(files: List<OutputFile>, inlinedMethods: Set<MethodInfo>): List<NotInlinedCall> {
|
||||
private fun checkInlineMethodNotInvoked(files: Iterable<OutputFile>, inlinedMethods: Set<MethodInfo>): List<NotInlinedCall> {
|
||||
val notInlined = ArrayList<NotInlinedCall>()
|
||||
|
||||
files.forEach { file ->
|
||||
@@ -128,7 +120,7 @@ public object InlineTestUtil {
|
||||
return notInlined
|
||||
}
|
||||
|
||||
private fun checkParametersInlined(files: List<OutputFile>, inlineInfo: InlineInfo): ArrayList<NotInlinedParameter> {
|
||||
private fun checkParametersInlined(files: Iterable<OutputFile>, inlineInfo: InlineInfo): ArrayList<NotInlinedParameter> {
|
||||
val inlinedMethods = inlineInfo.inlineMethods
|
||||
val notInlinedParameters = ArrayList<NotInlinedParameter>()
|
||||
for (file in files) {
|
||||
|
||||
+4
-2
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.kotlin.codegen.generated
|
||||
|
||||
import org.jetbrains.kotlin.codegen.InlineTestUtil
|
||||
import org.jetbrains.kotlin.codegen.filterClassFiles
|
||||
import org.jetbrains.kotlin.codegen.getClassFiles
|
||||
import org.jetbrains.kotlin.jvm.compiler.AbstractSMAPBaseTest
|
||||
import java.io.File
|
||||
|
||||
@@ -28,8 +30,8 @@ public abstract class AbstractBlackBoxInlineCodegenTest : AbstractBlackBoxCodege
|
||||
|
||||
doTestMultiFile(inputFiles)
|
||||
try {
|
||||
InlineTestUtil.checkNoCallsToInline(initializedClassLoader.getAllGeneratedFiles(), myFiles.getPsiFiles())
|
||||
checkSMAP(myFiles.getPsiFiles(), generateClassesInFile().asList())
|
||||
InlineTestUtil.checkNoCallsToInline(initializedClassLoader.allGeneratedFiles.filterClassFiles(), myFiles.getPsiFiles())
|
||||
checkSMAP(myFiles.getPsiFiles(), generateClassesInFile().getClassFiles())
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
System.out.println(generateToText())
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.codegen
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile
|
||||
|
||||
fun ClassFileFactory.getClassFiles(): Iterable<OutputFile> {
|
||||
return asList().filterClassFiles()
|
||||
}
|
||||
|
||||
fun List<OutputFile>.filterClassFiles(): Iterable<OutputFile> {
|
||||
return filter { it.relativePath.endsWith(".class") }
|
||||
}
|
||||
+3
-2
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.codegen.ClassFileFactory
|
||||
import org.jetbrains.kotlin.codegen.InlineTestUtil
|
||||
import org.jetbrains.kotlin.codegen.filterClassFiles
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
|
||||
@@ -31,8 +32,8 @@ public abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCom
|
||||
|
||||
try {
|
||||
val sourceFiles = factory1.getInputFiles() + factory2.getInputFiles()
|
||||
InlineTestUtil.checkNoCallsToInline(allGeneratedFiles, sourceFiles)
|
||||
checkSMAP(sourceFiles, allGeneratedFiles)
|
||||
InlineTestUtil.checkNoCallsToInline(allGeneratedFiles.filterClassFiles(), sourceFiles)
|
||||
checkSMAP(sourceFiles, allGeneratedFiles.filterClassFiles())
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
System.out.println(factory1.createText() + "\n" + factory2.createText())
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.TopDownAnalysisMode;
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmPackageMappingProvider;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
@@ -156,7 +156,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
environment.getSourceFiles(),
|
||||
trace,
|
||||
TopDownAnalysisMode.TopLevelDeclarations,
|
||||
PackageMappingProvider.EMPTY
|
||||
new JvmPackageMappingProvider(environment)
|
||||
);
|
||||
|
||||
PackageViewDescriptor packageView = moduleContext.getModule().getPackage(TEST_PACKAGE_FQNAME);
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.io.File
|
||||
|
||||
public trait AbstractSMAPBaseTest {
|
||||
|
||||
private fun extractSMAPFromClasses(outputFiles: List<OutputFile>): List<SMAPAndFile> {
|
||||
private fun extractSMAPFromClasses(outputFiles: Iterable<OutputFile>): List<SMAPAndFile> {
|
||||
return outputFiles.map { outputFile ->
|
||||
if (PackageClassUtils.isPackageClassFqName(FqName(FileUtil.getNameWithoutExtension(outputFile.relativePath).replace('/', '.')))) {
|
||||
// Don't test line numbers in *Package facade classes
|
||||
@@ -65,7 +65,7 @@ public trait AbstractSMAPBaseTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
fun checkSMAP(inputFiles: List<JetFile>, outputFiles: List<OutputFile>) {
|
||||
fun checkSMAP(inputFiles: List<JetFile>, outputFiles: Iterable<OutputFile>) {
|
||||
if (!InlineCodegenUtil.GENERATE_SMAP) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,12 +51,21 @@ public class JvmResolveUtil {
|
||||
public static AnalysisResult analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files
|
||||
) {
|
||||
return analyzeFilesWithJavaIntegrationAndCheckForErrors(project, files, PackageMappingProvider.EMPTY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalysisResult analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull PackageMappingProvider packageMappingProvider
|
||||
) {
|
||||
for (JetFile file : files) {
|
||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||
}
|
||||
|
||||
AnalysisResult analysisResult = analyzeFilesWithJavaIntegration(project, files);
|
||||
AnalysisResult analysisResult = analyzeFilesWithJavaIntegration(project, files, packageMappingProvider);
|
||||
|
||||
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
||||
|
||||
@@ -67,11 +76,20 @@ public class JvmResolveUtil {
|
||||
public static AnalysisResult analyzeFilesWithJavaIntegration(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files
|
||||
) {
|
||||
return analyzeFilesWithJavaIntegration(project, files, PackageMappingProvider.EMPTY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalysisResult analyzeFilesWithJavaIntegration(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull PackageMappingProvider packageMappingProvider
|
||||
) {
|
||||
ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, "java-integration-test");
|
||||
|
||||
BindingTrace trace = new CliLightClassGenerationSupport.CliBindingTrace();
|
||||
|
||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(moduleContext, files, trace, null, null, PackageMappingProvider.EMPTY);
|
||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(moduleContext, files, trace, null, null, packageMappingProvider);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user