Remove LazyResolveTestUtil, refactor usages to use JvmResolveUtil
LazyResolveTestUtil.resolve by now had almost exactly the same code as JvmResolveUtil.analyze. LazyResolveTestUtil.resolveLazily with 3 parameters was only used in LoadBuiltinsTest, inline it there. Move LazyResolveTestUtil.getTopLevelPackagesFromFileList to AbstractDiagnosticsTest, the only place where it was used
This commit is contained in:
@@ -24,29 +24,28 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.codegen.GenerationUtils;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations;
|
||||
|
||||
@@ -104,12 +103,10 @@ public final class LoadDescriptorUtil {
|
||||
KotlinCoreEnvironment environment =
|
||||
KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
|
||||
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
|
||||
ModuleDescriptor module = LazyResolveTestUtil
|
||||
.resolve(environment.getProject(), trace, Collections.<KtFile>emptyList(), environment);
|
||||
AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
|
||||
|
||||
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||
return Pair.create(packageView, trace.getBindingContext());
|
||||
PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
||||
return Pair.create(packageView, analysisResult.getBindingContext());
|
||||
}
|
||||
|
||||
public static void compileJavaWithAnnotationsJar(@NotNull Collection<File> javaFiles, @NotNull File outDir) throws IOException {
|
||||
|
||||
@@ -16,22 +16,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.kotlin.checkers.TestCheckerUtil;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
|
||||
public abstract class AbstractResolveTest extends ExtensibleResolveTestCase {
|
||||
@Override
|
||||
protected ExpectedResolveData getExpectedResolveData() {
|
||||
final Project project = getProject();
|
||||
|
||||
return new ExpectedResolveData(
|
||||
ExpectedResolveDataUtil.prepareDefaultNameToDescriptors(project, getEnvironment()),
|
||||
ExpectedResolveDataUtil.prepareDefaultNameToDeclaration(project, getEnvironment())
|
||||
ExpectedResolveDataUtil.prepareDefaultNameToDescriptors(getEnvironment()),
|
||||
ExpectedResolveDataUtil.prepareDefaultNameToDeclaration(getEnvironment())
|
||||
) {
|
||||
@Override
|
||||
protected KtFile createKtFile(String fileName, String text) {
|
||||
return TestCheckerUtil.createCheckAndReturnPsiFile(fileName, text, project);
|
||||
return TestCheckerUtil.createCheckAndReturnPsiFile(fileName, text, getProject());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
||||
@@ -54,7 +54,9 @@ public class ExpectedResolveDataUtil {
|
||||
private ExpectedResolveDataUtil() {
|
||||
}
|
||||
|
||||
public static Map<String, DeclarationDescriptor> prepareDefaultNameToDescriptors(Project project, KotlinCoreEnvironment environment) {
|
||||
@NotNull
|
||||
public static Map<String, DeclarationDescriptor> prepareDefaultNameToDescriptors(@NotNull KotlinCoreEnvironment environment) {
|
||||
Project project = environment.getProject();
|
||||
KotlinBuiltIns builtIns = DefaultBuiltIns.getInstance();
|
||||
|
||||
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
|
||||
@@ -69,25 +71,27 @@ public class ExpectedResolveDataUtil {
|
||||
return nameToDescriptor;
|
||||
}
|
||||
|
||||
public static Map<String, PsiElement> prepareDefaultNameToDeclaration(Project project, KotlinCoreEnvironment environment) {
|
||||
@NotNull
|
||||
public static Map<String, PsiElement> prepareDefaultNameToDeclaration(@NotNull KotlinCoreEnvironment environment) {
|
||||
Project project = environment.getProject();
|
||||
Map<String, PsiElement> nameToDeclaration = new HashMap<String, PsiElement>();
|
||||
|
||||
PsiClass java_util_Collections = findClass("java.util.Collections", project, environment);
|
||||
PsiClass java_util_Collections = findClass("java.util.Collections", environment);
|
||||
nameToDeclaration.put("java::java.util.Collections.emptyList()", findMethod(java_util_Collections, "emptyList"));
|
||||
nameToDeclaration.put("java::java.util.Collections", java_util_Collections);
|
||||
PsiClass java_util_List = findClass("java.util.ArrayList", project, environment);
|
||||
nameToDeclaration.put("java::java.util.List", findClass("java.util.List", project, environment));
|
||||
PsiClass java_util_List = findClass("java.util.ArrayList", environment);
|
||||
nameToDeclaration.put("java::java.util.List", findClass("java.util.List", environment));
|
||||
nameToDeclaration.put("java::java.util.ArrayList", java_util_List);
|
||||
nameToDeclaration.put("java::java.util.ArrayList.set()", java_util_List.findMethodsByName("set", true)[0]);
|
||||
nameToDeclaration.put("java::java.util.ArrayList.get()", java_util_List.findMethodsByName("get", true)[0]);
|
||||
nameToDeclaration.put("java::java", findPackage("java", project));
|
||||
nameToDeclaration.put("java::java.util", findPackage("java.util", project));
|
||||
nameToDeclaration.put("java::java.lang", findPackage("java.lang", project));
|
||||
nameToDeclaration.put("java::java.lang.Object", findClass("java.lang.Object", project, environment));
|
||||
nameToDeclaration.put("java::java.lang.Comparable", findClass("java.lang.Comparable", project, environment));
|
||||
PsiClass java_lang_System = findClass("java.lang.System", project, environment);
|
||||
nameToDeclaration.put("java::java.lang.Object", findClass("java.lang.Object", environment));
|
||||
nameToDeclaration.put("java::java.lang.Comparable", findClass("java.lang.Comparable", environment));
|
||||
PsiClass java_lang_System = findClass("java.lang.System", environment);
|
||||
nameToDeclaration.put("java::java.lang.System", java_lang_System);
|
||||
PsiMethod[] methods = findClass("java.io.PrintStream", project, environment).findMethodsByName("print", true);
|
||||
PsiMethod[] methods = findClass("java.io.PrintStream", environment).findMethodsByName("print", true);
|
||||
nameToDeclaration.put("java::java.io.PrintStream.print(Object)", methods[8]);
|
||||
nameToDeclaration.put("java::java.io.PrintStream.print(Int)", methods[2]);
|
||||
nameToDeclaration.put("java::java.io.PrintStream.print(char[])", methods[6]);
|
||||
@@ -95,7 +99,7 @@ public class ExpectedResolveDataUtil {
|
||||
PsiField outField = java_lang_System.findFieldByName("out", true);
|
||||
assertNotNull("'out' property wasn't found", outField);
|
||||
nameToDeclaration.put("java::java.lang.System.out", outField);
|
||||
PsiClass java_lang_Number = findClass("java.lang.Number", project, environment);
|
||||
PsiClass java_lang_Number = findClass("java.lang.Number", environment);
|
||||
nameToDeclaration.put("java::java.lang.Number", java_lang_Number);
|
||||
nameToDeclaration.put("java::java.lang.Number.intValue()", java_lang_Number.findMethodsByName("intValue", true)[0]);
|
||||
|
||||
@@ -117,8 +121,8 @@ public class ExpectedResolveDataUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiClass findClass(String qualifiedName, Project project, KotlinCoreEnvironment environment) {
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(project, environment);
|
||||
private static PsiClass findClass(String qualifiedName, KotlinCoreEnvironment environment) {
|
||||
ModuleDescriptor module = JvmResolveUtil.analyze(environment).getModuleDescriptor();
|
||||
ClassDescriptor classDescriptor = DescriptorUtilsKt.resolveTopLevelClass(module, new FqName(qualifiedName), NoLookupLocation.FROM_TEST);
|
||||
assertNotNull("Class descriptor wasn't resolved: " + qualifiedName, classDescriptor);
|
||||
PsiClass psiClass = (PsiClass) DescriptorToSourceUtils.getSourceFromDescriptor(classDescriptor);
|
||||
|
||||
@@ -67,6 +67,11 @@ public class JvmResolveUtil {
|
||||
return analysisResult;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalysisResult analyze(@NotNull KotlinCoreEnvironment environment) {
|
||||
return analyze(Collections.<KtFile>emptySet(), environment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalysisResult analyze(@NotNull KtFile file, @NotNull KotlinCoreEnvironment environment) {
|
||||
return analyze(Collections.singleton(file), environment);
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* 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.resolve.lazy;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.context.ModuleContext;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class LazyResolveTestUtil {
|
||||
private LazyResolveTestUtil() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ModuleDescriptor resolveProject(@NotNull Project project, @NotNull KotlinCoreEnvironment environment) {
|
||||
return resolve(project, Collections.<KtFile>emptyList(), environment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull List<KtFile> sourceFiles, @NotNull KotlinCoreEnvironment environment) {
|
||||
return resolve(project, new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), sourceFiles, environment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ModuleDescriptor resolve(
|
||||
@NotNull Project project,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull List<KtFile> sourceFiles,
|
||||
@NotNull KotlinCoreEnvironment environment
|
||||
) {
|
||||
ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, JvmResolveUtil.TEST_MODULE_NAME);
|
||||
|
||||
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
moduleContext, sourceFiles, trace, environment.getConfiguration(), new JvmPackagePartProvider(environment)
|
||||
);
|
||||
|
||||
return moduleContext.getModule();
|
||||
}
|
||||
|
||||
public static ModuleDescriptor resolveLazily(List<KtFile> files, KotlinCoreEnvironment environment) {
|
||||
return resolveLazily(files, environment, true);
|
||||
}
|
||||
|
||||
public static ModuleDescriptor resolveLazily(List<KtFile> files, KotlinCoreEnvironment environment, boolean addBuiltIns) {
|
||||
return LazyResolveTestUtilsKt.createResolveSessionForFiles(environment.getProject(), files, addBuiltIns).getModuleDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<Name> getTopLevelPackagesFromFileList(@NotNull List<KtFile> files) {
|
||||
Set<Name> shortNames = Sets.newLinkedHashSet();
|
||||
for (KtFile file : files) {
|
||||
List<Name> packageFqNameSegments = file.getPackageFqName().pathSegments();
|
||||
Name name = packageFqNameSegments.isEmpty() ? SpecialNames.ROOT_PACKAGE : packageFqNameSegments.get(0);
|
||||
shortNames.add(name);
|
||||
}
|
||||
return shortNames;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,6 @@ import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.test.util.JetTestUtilsKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
@@ -475,25 +474,25 @@ public class KotlinTestUtils {
|
||||
public static void resolveAllKotlinFiles(KotlinCoreEnvironment environment) throws IOException {
|
||||
List<ContentRoot> paths = environment.getConfiguration().get(CommonConfigurationKeys.CONTENT_ROOTS);
|
||||
if (paths == null) return;
|
||||
List<KtFile> jetFiles = Lists.newArrayList();
|
||||
List<KtFile> ktFiles = new ArrayList<KtFile>();
|
||||
for (ContentRoot root : paths) {
|
||||
if (!(root instanceof KotlinSourceRoot)) continue;
|
||||
|
||||
String path = ((KotlinSourceRoot) root).getPath();
|
||||
File file = new File(path);
|
||||
if (file.isFile()) {
|
||||
jetFiles.add(loadJetFile(environment.getProject(), file));
|
||||
ktFiles.add(loadJetFile(environment.getProject(), file));
|
||||
}
|
||||
else {
|
||||
//noinspection ConstantConditions
|
||||
for (File childFile : file.listFiles()) {
|
||||
if (childFile.getName().endsWith(".kt")) {
|
||||
jetFiles.add(loadJetFile(environment.getProject(), childFile));
|
||||
ktFiles.add(loadJetFile(environment.getProject(), childFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LazyResolveTestUtil.resolve(environment.getProject(), jetFiles, environment);
|
||||
JvmResolveUtil.analyze(ktFiles, environment);
|
||||
}
|
||||
|
||||
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) {
|
||||
|
||||
@@ -38,18 +38,21 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.diagnostics.*;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.platform.JvmBuiltIns;
|
||||
import org.jetbrains.kotlin.psi.Call;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatformKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.storage.ExceptionTracker;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
@@ -68,7 +71,7 @@ import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECUR
|
||||
|
||||
public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
|
||||
public static final Function1<String, String> HASH_SANITIZER = new Function1<String, String>() {
|
||||
private static final Function1<String, String> HASH_SANITIZER = new Function1<String, String>() {
|
||||
@Override
|
||||
public String invoke(String s) {
|
||||
return s.replaceAll("@(\\d)+", "");
|
||||
@@ -295,8 +298,8 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, rootPackageText.toString());
|
||||
}
|
||||
|
||||
public RecursiveDescriptorComparator.Configuration createdAffectedPackagesConfiguration(List<TestFile> testFiles) {
|
||||
final Set<Name> packagesNames = LazyResolveTestUtil.getTopLevelPackagesFromFileList(getJetFiles(testFiles, false));
|
||||
private RecursiveDescriptorComparator.Configuration createdAffectedPackagesConfiguration(List<TestFile> testFiles) {
|
||||
final Set<Name> packagesNames = getTopLevelPackagesFromFileList(getJetFiles(testFiles, false));
|
||||
|
||||
Predicate<DeclarationDescriptor> stepIntoFilter = new Predicate<DeclarationDescriptor>() {
|
||||
@Override
|
||||
@@ -317,6 +320,17 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
return RECURSIVE.filterRecursion(stepIntoFilter).withValidationStrategy(DescriptorValidator.ValidationVisitor.errorTypesAllowed());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<Name> getTopLevelPackagesFromFileList(@NotNull List<KtFile> files) {
|
||||
Set<Name> shortNames = new LinkedHashSet<Name>();
|
||||
for (KtFile file : files) {
|
||||
List<Name> packageFqNameSegments = file.getPackageFqName().pathSegments();
|
||||
Name name = packageFqNameSegments.isEmpty() ? SpecialNames.ROOT_PACKAGE : packageFqNameSegments.get(0);
|
||||
shortNames.add(name);
|
||||
}
|
||||
return shortNames;
|
||||
}
|
||||
|
||||
private Map<TestModule, ModuleDescriptorImpl> createModules(
|
||||
@NotNull Map<TestModule, List<TestFile>> groupedByModule,
|
||||
@NotNull StorageManager storageManager
|
||||
|
||||
+3
-4
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||
@@ -48,7 +47,7 @@ import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.valid
|
||||
public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithTmpdir {
|
||||
// Do not render parameter names because there are test cases where classes inherit from JDK collections,
|
||||
// and some versions of JDK have debug information in the class files (including parameter names), and some don't
|
||||
public static final RecursiveDescriptorComparator.Configuration CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.withRenderer(
|
||||
private static final RecursiveDescriptorComparator.Configuration CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.withRenderer(
|
||||
DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
@@ -81,8 +80,8 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
);
|
||||
|
||||
AnalysisResult exhaust = JvmResolveUtil.analyze(Collections.<KtFile>emptySet(), environment);
|
||||
PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||
AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
|
||||
PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||
assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
|
||||
|
||||
validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile);
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinder
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement
|
||||
@@ -48,7 +48,7 @@ class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() {
|
||||
fun testNestedClass() {
|
||||
val tmpdir = KotlinTestUtils.tmpDirForTest(this)
|
||||
KotlinTestUtils.compileKotlinWithJava(
|
||||
listOf(), listOf(File("compiler/testData/kotlinClassFinder/nestedClass.kt")), tmpdir, testRootDisposable!!, null
|
||||
listOf(), listOf(File("compiler/testData/kotlinClassFinder/nestedClass.kt")), tmpdir, testRootDisposable, null
|
||||
)
|
||||
|
||||
val environment = createEnvironment(tmpdir)
|
||||
@@ -66,14 +66,13 @@ class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() {
|
||||
}
|
||||
|
||||
private fun createEnvironment(tmpdir: File?): KotlinCoreEnvironment {
|
||||
val environment = KotlinCoreEnvironment.createForTests(testRootDisposable!!,
|
||||
KotlinTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
|
||||
// Activate Kotlin light class finder
|
||||
LazyResolveTestUtil.resolveProject(environment.project, environment)
|
||||
|
||||
return environment
|
||||
return KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
).apply {
|
||||
// Activate Kotlin light class finder
|
||||
JvmResolveUtil.analyze(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
@@ -161,25 +161,26 @@ public class ResolveDescriptorsFromExternalLibraries {
|
||||
public void dispose() { }
|
||||
};
|
||||
|
||||
KotlinCoreEnvironment jetCoreEnvironment;
|
||||
KotlinCoreEnvironment environment;
|
||||
if (jar != null) {
|
||||
jetCoreEnvironment = KotlinCoreEnvironment.createForTests(
|
||||
environment = KotlinCoreEnvironment.createForTests(
|
||||
junk,
|
||||
KotlinTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, KotlinTestUtils.getAnnotationsJar(), jar
|
||||
),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
);
|
||||
}
|
||||
else {
|
||||
CompilerConfiguration configuration =
|
||||
KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK);
|
||||
jetCoreEnvironment = KotlinCoreEnvironment.createForTests(junk, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
environment = KotlinCoreEnvironment.createForTests(junk, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
if (!findRtJar().equals(jar)) {
|
||||
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + findRtJar());
|
||||
}
|
||||
}
|
||||
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(jetCoreEnvironment.getProject(), jetCoreEnvironment);
|
||||
ModuleDescriptor module = JvmResolveUtil.analyze(environment).getModuleDescriptor();
|
||||
|
||||
boolean hasErrors;
|
||||
try {
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AdditionalClassPartsProvider;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.PlatformDependentDeclarationFilter;
|
||||
@@ -87,7 +87,8 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
allFilesUnder("core/builtins/src")
|
||||
));
|
||||
|
||||
final ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(files, getEnvironment(), false);
|
||||
ModuleDescriptor module =
|
||||
LazyResolveTestUtilsKt.createResolveSessionForFiles(getEnvironment().getProject(), files, false).getModuleDescriptor();
|
||||
|
||||
for (FqName packageFqName : CollectionsKt.listOf(BUILT_INS_PACKAGE_FQ_NAME, COLLECTIONS_PACKAGE_FQ_NAME, RANGES_PACKAGE_FQ_NAME)) {
|
||||
PackageFragmentDescriptor fromLazyResolve =
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
@@ -27,12 +27,11 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
@Override
|
||||
@@ -71,14 +70,11 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
//}
|
||||
|
||||
private void doTest(String text, String expected) {
|
||||
KtFile jetFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text);
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
|
||||
KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text);
|
||||
ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor();
|
||||
Collection<SimpleFunctionDescriptor> functions =
|
||||
module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
|
||||
assert functions.size() == 1 : "Many functions defined";
|
||||
FunctionDescriptor function = ContainerUtil.getFirstItem(functions);
|
||||
|
||||
FunctionDescriptor substituted = BoundsSubstitutor.substituteBounds(function);
|
||||
FunctionDescriptor substituted = BoundsSubstitutor.substituteBounds(CollectionsKt.single(functions));
|
||||
String actual = DescriptorRenderer.COMPACT.render(substituted);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.types;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
@@ -29,11 +29,10 @@ import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
|
||||
@@ -575,15 +574,9 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
||||
@NotNull
|
||||
private LexicalScope getDeclarationsScope(String path) throws IOException {
|
||||
KtFile ktFile = KotlinTestUtils.loadJetFile(getProject(), new File(path));
|
||||
BindingTrace trace = new CliLightClassGenerationSupport.CliBindingTrace();
|
||||
LazyResolveTestUtil.resolve(
|
||||
getProject(),
|
||||
trace,
|
||||
Collections.singletonList(ktFile),
|
||||
getEnvironment()
|
||||
);
|
||||
|
||||
return trace.get(BindingContext.LEXICAL_SCOPE, ktFile);
|
||||
AnalysisResult result = JvmResolveUtil.analyze(ktFile, getEnvironment());
|
||||
//noinspection ConstantConditions
|
||||
return result.getBindingContext().get(BindingContext.LEXICAL_SCOPE, ktFile);
|
||||
}
|
||||
|
||||
private KotlinType makeType(String typeStr) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
@@ -53,7 +53,6 @@ import org.jetbrains.kotlin.tests.di.InjectionKt;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -84,31 +83,36 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
private LexicalScope getContextScope() throws IOException {
|
||||
// todo comments
|
||||
String text = FileUtil.loadFile(new File("compiler/testData/type-substitutor.kt"), true);
|
||||
KtFile jetFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile(text);
|
||||
BindingTrace trace = new CliLightClassGenerationSupport.CliBindingTrace();
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolve(getProject(), trace, Collections.singletonList(jetFile), getEnvironment());
|
||||
KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile(text);
|
||||
AnalysisResult analysisResult = JvmResolveUtil.analyze(ktFile, getEnvironment());
|
||||
ModuleDescriptor module = analysisResult.getModuleDescriptor();
|
||||
|
||||
LexicalScope topLevelScope = trace.get(BindingContext.LEXICAL_SCOPE, jetFile);
|
||||
final ClassifierDescriptor contextClass = ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST);
|
||||
LexicalScope topLevelScope = analysisResult.getBindingContext().get(BindingContext.LEXICAL_SCOPE, ktFile);
|
||||
final ClassifierDescriptor contextClass =
|
||||
ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST);
|
||||
assert contextClass instanceof ClassDescriptor;
|
||||
LocalRedeclarationChecker redeclarationChecker = new ThrowingLocalRedeclarationChecker(new OverloadChecker(
|
||||
TypeSpecificityComparator.NONE.INSTANCE));
|
||||
LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||
redeclarationChecker,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
|
||||
handler.addClassifierDescriptor(parameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
return new LexicalChainedScope(typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||
Arrays.asList(
|
||||
contextClass.getDefaultType().getMemberScope(),
|
||||
module.getBuiltIns().getBuiltInsPackageScope()
|
||||
));
|
||||
LocalRedeclarationChecker redeclarationChecker =
|
||||
new ThrowingLocalRedeclarationChecker(new OverloadChecker(TypeSpecificityComparator.NONE.INSTANCE));
|
||||
LexicalScope typeParameters = new LexicalScopeImpl(
|
||||
topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||
redeclarationChecker,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
|
||||
handler.addClassifierDescriptor(parameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
}
|
||||
);
|
||||
return new LexicalChainedScope(
|
||||
typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||
Arrays.asList(
|
||||
contextClass.getDefaultType().getMemberScope(),
|
||||
module.getBuiltIns().getBuiltInsPackageScope()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private void doTest(@Nullable String expectedTypeStr, String initialTypeStr, Pair<String, String>... substitutionStrs) {
|
||||
|
||||
Reference in New Issue
Block a user