Use module instead of KotlinBuiltIns in ReflectionTypes
This commit is contained in:
@@ -27,10 +27,22 @@ import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl
|
||||
|
||||
public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
// TODO: use module instead of built-ins
|
||||
public fun getKFunction(n: Int): ClassDescriptor = KotlinBuiltIns.getInstance().getKFunction(n)
|
||||
public fun getKExtensionFunction(n: Int): ClassDescriptor = KotlinBuiltIns.getInstance().getKExtensionFunction(n)
|
||||
public fun getKMemberFunction(n: Int): ClassDescriptor = KotlinBuiltIns.getInstance().getKMemberFunction(n)
|
||||
private val kotlinReflect: JetScope by Delegates.lazy {
|
||||
// TODO: handle errors gracefully (error types)
|
||||
val kotlin = module.getPackage(FqName("kotlin")) ?: error("Package kotlin not found in $module")
|
||||
// TODO: move K*FunctionN under kotlin.reflect.*
|
||||
// val reflect = kotlin.getMemberScope().getPackage(Name.identifier("reflect")) ?: error("Package reflect not found in $kotlin")
|
||||
kotlin.getMemberScope()
|
||||
}
|
||||
|
||||
fun find(className: String): ClassDescriptor {
|
||||
val name = Name.identifier(className)
|
||||
return kotlinReflect.getClassifier(name) as? ClassDescriptor ?: error("Reflection class not found: $name")
|
||||
}
|
||||
|
||||
public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n")
|
||||
public fun getKExtensionFunction(n: Int): ClassDescriptor = find("KExtensionFunction$n")
|
||||
public fun getKMemberFunction(n: Int): ClassDescriptor = find("KMemberFunction$n")
|
||||
|
||||
public fun getKFunctionType(
|
||||
annotations: Annotations,
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.jet.context.GlobalContext;
|
||||
import org.jetbrains.jet.context.GlobalContextImpl;
|
||||
import org.jetbrains.jet.di.InjectorForLazyResolve;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerBasic;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor;
|
||||
@@ -39,7 +38,6 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
@@ -204,10 +202,6 @@ public class TopDownAnalyzer {
|
||||
@NotNull final DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetClassOrObject object
|
||||
) {
|
||||
ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl(Name.special("<dummy for object>"),
|
||||
Collections.<ImportPath>emptyList(),
|
||||
PlatformToKotlinClassMap.EMPTY);
|
||||
|
||||
TopDownAnalysisParameters topDownAnalysisParameters =
|
||||
TopDownAnalysisParameters.createForLocalDeclarations(
|
||||
globalContext.getStorageManager(),
|
||||
@@ -216,7 +210,7 @@ public class TopDownAnalyzer {
|
||||
);
|
||||
|
||||
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
||||
object.getProject(), topDownAnalysisParameters, context.trace, moduleDescriptor
|
||||
object.getProject(), topDownAnalysisParameters, context.trace, DescriptorUtils.getContainingModule(containingDeclaration)
|
||||
);
|
||||
|
||||
TopDownAnalysisContext c = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
|
||||
@@ -275,21 +275,6 @@ public class KotlinBuiltIns {
|
||||
return getBuiltInClassByName("ExtensionFunction" + parameterCount);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getKFunction(int parameterCount) {
|
||||
return getBuiltInClassByName("KFunction" + parameterCount);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getKMemberFunction(int parameterCount) {
|
||||
return getBuiltInClassByName("KMemberFunction" + parameterCount);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getKExtensionFunction(int parameterCount) {
|
||||
return getBuiltInClassByName("KExtensionFunction" + parameterCount);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getThrowable() {
|
||||
return getBuiltInClassByName("Throwable");
|
||||
@@ -300,6 +285,7 @@ public class KotlinBuiltIns {
|
||||
return getBuiltInClassByName("data");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getNoinlineClassAnnotation() {
|
||||
return getBuiltInClassByName("noinline");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user