This commit is contained in:
Michael Bogdanov
2015-08-27 10:37:15 +03:00
parent 42d14f6837
commit 843241848f
14 changed files with 62 additions and 40 deletions
@@ -56,9 +56,9 @@ import java.util.*
@TestOnly
public @jvmStatic fun getDefaultPartFqName(facadeClassFqName: FqName, file: VirtualFile): FqName =
getDefaultPartFqNameForFilePath(facadeClassFqName.parent(), file.name)
getPackagePartFqName(facadeClassFqName.parent(), file.name)
private @jvmStatic fun getDefaultPartFqNameForFilePath(packageFqName: FqName, fileName: String): FqName {
public @jvmStatic fun getPackagePartFqName(packageFqName: FqName, fileName: String): FqName {
val partClassName = getPartClassName(FileUtil.getNameWithoutExtension(fileName))
return packageFqName.child(Name.identifier(partClassName))
}
@@ -73,7 +73,8 @@ import java.util.*
JvmClassName.byFqNameWithoutInnerClasses(getPackagePartFqName(file)).internalName
public @jvmStatic fun getPackagePartFqName(file: JetFile): FqName =
getDefaultPartFqNameForFilePath(file.packageFqName, file.name)
getPackagePartFqName(file.packageFqName, file.name)
public @jvmStatic fun getPackagePartFqName(callable: DeserializedCallableMemberDescriptor): FqName {
val implClassName = callable.nameResolver.getName(callable.proto.getExtension(JvmProtoBuf.implClassName))
+1
View File
@@ -10,6 +10,7 @@ where possible options include:
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlin-home <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-module-name Module name
-nowarn Generate no warnings
-verbose Enable verbose logging output
-version Display compiler version
+1
View File
@@ -11,6 +11,7 @@ where possible options include:
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlin-home <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-module-name Module name
-nowarn Generate no warnings
-verbose Enable verbose logging output
-version Display compiler version
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.serialization.PackageData;
import org.jetbrains.kotlin.serialization.ProtoBuf;
@@ -41,7 +42,7 @@ public class KotlinPackageAnnotationTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
public void testPackageKotlinInfo() throws Exception {
public void testOldPackageKotlinInfo() throws Exception {
loadText("package " + PACKAGE_NAME + "\n" +
"\n" +
"fun foo() = 42\n" +
@@ -62,6 +63,31 @@ public class KotlinPackageAnnotationTest extends CodegenTestCase {
assertNotNull(data);
PackageData packageData = JvmProtoBufUtil.readPackageDataFrom(data);
Set<String> callableNames = collectCallableNames(packageData.getPackageProto().getMemberList(), packageData.getNameResolver());
assertEmpty(callableNames);
}
public void testPackagePartKotlinInfo() throws Exception {
loadText("package " + PACKAGE_NAME + "\n" +
"\n" +
"fun foo() = 42\n" +
"val bar = 239\n" +
"\n" +
"class A\n" +
"class B\n" +
"object C\n");
Class aClass = generateClass(PackagePartClassUtils.getPackagePartFqName(PACKAGE_NAME, DEFAULT_TEST_FILE_NAME).asString());
Class<? extends Annotation> annotationClass = loadAnnotationClassQuietly(JvmAnnotationNames.KOTLIN_FILE_FACADE.asString());
assertTrue(aClass.isAnnotationPresent(annotationClass));
assertTrue(aClass.isAnnotationPresent(annotationClass));
Annotation kotlinPackage = aClass.getAnnotation(annotationClass);
String[] data = (String[]) CodegenTestUtil.getAnnotationAttribute(kotlinPackage, "data");
assertNotNull(data);
PackageData packageData = JvmProtoBufUtil.readPackageDataFrom(data);
Set<String> callableNames = collectCallableNames(packageData.getPackageProto().getMemberList(), packageData.getNameResolver());
assertSameElements(callableNames, Arrays.asList("foo", "bar"));
}
@@ -48,14 +48,6 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
}
public void testPackagePart() {
doTestKotlinSyntheticClass(
"fun foo() = 42",
KotlinPackage.capitalize(DEFAULT_TEST_FILE_NAME),
PACKAGE_PART
);
}
public void testTraitImpl() {
doTestKotlinSyntheticClass(
"trait A { fun foo() = 42 }",
@@ -79,8 +79,7 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
ModuleDescriptor module = LazyResolveTestUtil.resolve(
commonEnvironment.getProject(), trace, Collections.<JetFile>emptyList(),
new JvmPackageMappingProvider(commonEnvironment)
commonEnvironment.getProject(), trace, Collections.<JetFile>emptyList(), commonEnvironment
);
AlternativeSignatureErrorFindingVisitor visitor =
@@ -73,7 +73,7 @@ public class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() {
EnvironmentConfigFiles.JVM_CONFIG_FILES)
// Activate Kotlin light class finder
LazyResolveTestUtil.resolveProject(environment.project)
LazyResolveTestUtil.resolveProject(environment.project, environment)
return environment
}
@@ -104,7 +104,7 @@ public final class LoadDescriptorUtil {
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
ModuleDescriptor module = LazyResolveTestUtil
.resolve(environment.getProject(), trace, Collections.<JetFile>emptyList(), new JvmPackageMappingProvider(environment));
.resolve(environment.getProject(), trace, Collections.<JetFile>emptyList(), environment);
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
return Pair.create(packageView, trace.getBindingContext());
@@ -178,7 +178,7 @@ public class ResolveDescriptorsFromExternalLibraries {
}
}
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(jetCoreEnvironment.getProject());
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(jetCoreEnvironment.getProject(), jetCoreEnvironment);
boolean hasErrors;
try {
@@ -26,8 +26,8 @@ public abstract class AbstractResolveTest extends ExtensibleResolveTestCase {
Project project = getProject();
return new ExpectedResolveData(
JetExpectedResolveDataUtil.prepareDefaultNameToDescriptors(project),
JetExpectedResolveDataUtil.prepareDefaultNameToDeclaration(project)
JetExpectedResolveDataUtil.prepareDefaultNameToDescriptors(project, getEnvironment()),
JetExpectedResolveDataUtil.prepareDefaultNameToDeclaration(project, getEnvironment())
) {
@Override
protected JetFile createJetFile(String fileName, String text) {
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
@@ -50,7 +51,7 @@ public class JetExpectedResolveDataUtil {
private JetExpectedResolveDataUtil() {
}
public static Map<String, DeclarationDescriptor> prepareDefaultNameToDescriptors(Project project) {
public static Map<String, DeclarationDescriptor> prepareDefaultNameToDescriptors(Project project, KotlinCoreEnvironment environment) {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
@@ -65,25 +66,25 @@ public class JetExpectedResolveDataUtil {
return nameToDescriptor;
}
public static Map<String, PsiElement> prepareDefaultNameToDeclaration(Project project) {
public static Map<String, PsiElement> prepareDefaultNameToDeclaration(Project project, KotlinCoreEnvironment environment) {
Map<String, PsiElement> nameToDeclaration = new HashMap<String, PsiElement>();
PsiClass java_util_Collections = findClass("java.util.Collections", project);
PsiClass java_util_Collections = findClass("java.util.Collections", project, 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);
nameToDeclaration.put("java::java.util.List", findClass("java.util.List", project));
PsiClass java_util_List = findClass("java.util.ArrayList", project, environment);
nameToDeclaration.put("java::java.util.List", findClass("java.util.List", project, 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));
nameToDeclaration.put("java::java.lang.Comparable", findClass("java.lang.Comparable", project));
PsiClass java_lang_System = findClass("java.lang.System", 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.System", java_lang_System);
PsiMethod[] methods = findClass("java.io.PrintStream", project).findMethodsByName("print", true);
PsiMethod[] methods = findClass("java.io.PrintStream", project, 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]);
@@ -91,7 +92,7 @@ public class JetExpectedResolveDataUtil {
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);
PsiClass java_lang_Number = findClass("java.lang.Number", project, environment);
nameToDeclaration.put("java::java.lang.Number", java_lang_Number);
nameToDeclaration.put("java::java.lang.Number.intValue()", java_lang_Number.findMethodsByName("intValue", true)[0]);
@@ -113,8 +114,8 @@ public class JetExpectedResolveDataUtil {
}
@NotNull
private static PsiClass findClass(String qualifiedName, Project project) {
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(project);
private static PsiClass findClass(String qualifiedName, Project project, KotlinCoreEnvironment environment) {
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(project, environment);
ClassDescriptor classDescriptor = DescriptorUtilPackage.resolveTopLevelClass(module, new FqName(qualifiedName), NoLookupLocation.FROM_TEST);
assertNotNull("Class descriptor wasn't resolved: " + qualifiedName, classDescriptor);
PsiClass psiClass = (PsiClass) DescriptorToSourceUtils.getSourceFromDescriptor(classDescriptor);
@@ -42,13 +42,13 @@ public class LazyResolveTestUtil {
}
@NotNull
public static ModuleDescriptor resolveProject(@NotNull Project project) {
return resolve(project, Collections.<JetFile>emptyList());
public static ModuleDescriptor resolveProject(@NotNull Project project, @NotNull KotlinCoreEnvironment environment) {
return resolve(project, Collections.<JetFile>emptyList(), environment);
}
@NotNull
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull List<JetFile> sourceFiles) {
return resolve(project, new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), sourceFiles, PackageMappingProvider.EMPTY);
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull List<JetFile> sourceFiles, @NotNull KotlinCoreEnvironment environment) {
return resolve(project, new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), sourceFiles, environment);
}
@NotNull
@@ -56,13 +56,13 @@ public class LazyResolveTestUtil {
@NotNull Project project,
@NotNull BindingTrace trace,
@NotNull List<JetFile> sourceFiles,
@NotNull PackageMappingProvider packageMappingProvider
@NotNull KotlinCoreEnvironment environment
) {
ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, "test");
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(
moduleContext, sourceFiles, trace, TopDownAnalysisMode.TopLevelDeclarations,
packageMappingProvider
new JvmPackageMappingProvider(environment)
);
return moduleContext.getModule();
@@ -505,7 +505,7 @@ public class JetTestUtils {
}
}
}
LazyResolveTestUtil.resolve(environment.getProject(), jetFiles);
LazyResolveTestUtil.resolve(environment.getProject(), jetFiles, environment);
}
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull String actual) {
@@ -599,7 +599,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
private JetScope getDeclarationsScope(String path) throws IOException {
ModuleDescriptor moduleDescriptor = LazyResolveTestUtil.resolve(
getProject(),
Collections.singletonList(JetTestUtils.loadJetFile(getProject(), new File(path)))
Collections.singletonList(JetTestUtils.loadJetFile(getProject(), new File(path))),
getEnvironment()
);
FqName fqName = new FqName("testData");
@@ -616,7 +617,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
List<JetScope> scopeChain = new ArrayList<JetScope>();
scopeChain.add(writableScope);
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(getProject());
ModuleDescriptor module = LazyResolveTestUtil.resolveProject(getProject(), getEnvironment());
for (ImportPath defaultImport : module.getDefaultImports()) {
FqName fqName = defaultImport.fqnPart();
if (defaultImport.isAllUnder()) {