Get rid of module reflection.stub.jvm
Generate K*Function as a supertype for a function reference instead of K*FunctionImpl; this will allow one binary library to be used with or without reflection
This commit is contained in:
Generated
-1
@@ -5,7 +5,6 @@
|
||||
<excludeFromCompile>
|
||||
<directory url="file://$PROJECT_DIR$/core/reflection" includeSubdirectories="true" />
|
||||
<directory url="file://$PROJECT_DIR$/core/reflection.jvm" includeSubdirectories="true" />
|
||||
<directory url="file://$PROJECT_DIR$/core/reflection.stub.jvm" includeSubdirectories="true" />
|
||||
</excludeFromCompile>
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
|
||||
Generated
-1
@@ -46,7 +46,6 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/preloader/preloader.iml" filepath="$PROJECT_DIR$/compiler/preloader/preloader.iml" group="compiler/cli" />
|
||||
<module fileurl="file://$PROJECT_DIR$/core/reflection/reflection.iml" filepath="$PROJECT_DIR$/core/reflection/reflection.iml" group="core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/core/reflection.jvm/reflection.jvm.iml" filepath="$PROJECT_DIR$/core/reflection.jvm/reflection.jvm.iml" group="core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/core/reflection.stub.jvm/reflection.stub.jvm.iml" filepath="$PROJECT_DIR$/core/reflection.stub.jvm/reflection.stub.jvm.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/core/runtime.jvm/runtime.jvm.iml" filepath="$PROJECT_DIR$/core/runtime.jvm/runtime.jvm.iml" group="core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/core/serialization/serialization.iml" filepath="$PROJECT_DIR$/core/serialization/serialization.iml" group="core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/core/serialization.jvm/serialization.jvm.iml" filepath="$PROJECT_DIR$/core/serialization.jvm/serialization.jvm.iml" group="core" />
|
||||
|
||||
@@ -795,28 +795,17 @@
|
||||
</new-kotlinc>
|
||||
</target>
|
||||
|
||||
<target name="reflection-stub">
|
||||
<new-kotlinc output="${output}/classes/reflection-stub">
|
||||
<src>
|
||||
<include name="core/reflection.stub.jvm/src"/>
|
||||
</src>
|
||||
<class-path>
|
||||
<pathelement path="${output.relative}/classes/builtins"/>
|
||||
</class-path>
|
||||
</new-kotlinc>
|
||||
</target>
|
||||
|
||||
<target name="pack-runtime">
|
||||
<macrodef name="do-pack-runtime">
|
||||
<attribute name="reflection-module"/>
|
||||
<attribute name="jar-name"/>
|
||||
<attribute name="implementation-title"/>
|
||||
<element name="reflection-classes" optional="true"/>
|
||||
|
||||
<sequential>
|
||||
<jar destfile="${kotlin-home}/lib/@{jar-name}" duplicate="fail">
|
||||
<fileset dir="${output}/classes/builtins"/>
|
||||
<fileset dir="${output}/classes/stdlib"/>
|
||||
<fileset dir="${output}/classes/@{reflection-module}"/>
|
||||
<reflection-classes/>
|
||||
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
|
||||
|
||||
<manifest>
|
||||
@@ -829,20 +818,20 @@
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<do-pack-runtime reflection-module="reflection"
|
||||
jar-name="kotlin-runtime.jar"
|
||||
implementation-title="${manifest.impl.title.kotlin.jvm.runtime}"/>
|
||||
<do-pack-runtime jar-name="kotlin-runtime.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime}">
|
||||
<reflection-classes>
|
||||
<fileset dir="${output}/classes/reflection"/>
|
||||
</reflection-classes>
|
||||
</do-pack-runtime>
|
||||
|
||||
<do-pack-runtime reflection-module="reflection-stub"
|
||||
jar-name="kotlin-runtime-minimal.jar"
|
||||
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal}"/>
|
||||
<do-pack-runtime jar-name="kotlin-runtime-minimal.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal}"/>
|
||||
</target>
|
||||
|
||||
<target name="pack-runtime-sources">
|
||||
<macrodef name="do-pack-runtime-sources">
|
||||
<attribute name="reflection-module"/>
|
||||
<attribute name="jar-name"/>
|
||||
<attribute name="implementation-title"/>
|
||||
<element name="reflection-sources" optional="true"/>
|
||||
|
||||
<sequential>
|
||||
<jar destfile="${kotlin-home}/lib/@{jar-name}" duplicate="fail">
|
||||
@@ -850,7 +839,7 @@
|
||||
<fileset dir="${basedir}/core/builtins/src" includes="**/*"/>
|
||||
<fileset dir="${basedir}/core/runtime.jvm/src" includes="**/*"/>
|
||||
<fileset dir="${basedir}/core/reflection/src" includes="**/*"/>
|
||||
<fileset dir="${basedir}/core/@{reflection-module}/src" includes="**/*"/>
|
||||
<reflection-sources/>
|
||||
<fileset dir="${basedir}/libraries/stdlib/src" includes="**/*"/>
|
||||
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
|
||||
|
||||
@@ -864,17 +853,19 @@
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<do-pack-runtime-sources reflection-module="reflection.jvm"
|
||||
jar-name="kotlin-runtime-sources.jar"
|
||||
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.sources}"/>
|
||||
<do-pack-runtime-sources jar-name="kotlin-runtime-sources.jar"
|
||||
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.sources}">
|
||||
<reflection-sources>
|
||||
<fileset dir="${basedir}/core/reflection.jvm/src" includes="**/*"/>
|
||||
</reflection-sources>
|
||||
</do-pack-runtime-sources>
|
||||
|
||||
<do-pack-runtime-sources reflection-module="reflection.stub.jvm"
|
||||
jar-name="kotlin-runtime-minimal-sources.jar"
|
||||
<do-pack-runtime-sources jar-name="kotlin-runtime-minimal-sources.jar"
|
||||
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal.sources}"/>
|
||||
</target>
|
||||
|
||||
<target name="runtime"
|
||||
depends="builtins,stdlib,reflection,reflection-stub,pack-runtime,pack-runtime-sources"/>
|
||||
depends="builtins,stdlib,reflection,pack-runtime,pack-runtime-sources"/>
|
||||
|
||||
<target name="dist"
|
||||
depends="clean,init,prepare-dist,preloader,serialize-builtins,compiler,compiler-sources,ant-tools,jdk-annotations,android-sdk-annotations,runtime,kotlin-js-stdlib,android-compiler-plugin"
|
||||
|
||||
@@ -20,45 +20,40 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap;
|
||||
import org.jetbrains.kotlin.resolve.ImportPath;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils;
|
||||
import org.jetbrains.kotlin.types.reflect.ReflectionTypes;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.createJavaModule;
|
||||
|
||||
public class JvmRuntimeTypes {
|
||||
private final ReflectionTypes reflectionTypes;
|
||||
|
||||
private final ClassDescriptor functionImpl;
|
||||
private final ClassDescriptor memberFunctionImpl;
|
||||
private final ClassDescriptor extensionFunctionImpl;
|
||||
private final ClassDescriptor kFunctionImpl;
|
||||
private final ClassDescriptor kMemberFunctionImpl;
|
||||
private final ClassDescriptor kExtensionFunctionImpl;
|
||||
|
||||
public JvmRuntimeTypes(@NotNull ReflectionTypes reflectionTypes) {
|
||||
this.reflectionTypes = reflectionTypes;
|
||||
|
||||
ModuleDescriptor fakeModule = new ModuleDescriptorImpl(Name.special("<fake module for functions impl>"),
|
||||
Collections.<ImportPath>emptyList(), JavaToKotlinClassMap.INSTANCE);
|
||||
|
||||
PackageFragmentDescriptor kotlinJvmInternal =
|
||||
new MutablePackageFragmentDescriptor(fakeModule, new FqName("kotlin.jvm.internal"));
|
||||
PackageFragmentDescriptor kotlinReflectJvmInternal =
|
||||
new MutablePackageFragmentDescriptor(fakeModule, new FqName("kotlin.reflect.jvm.internal"));
|
||||
PackageFragmentDescriptor kotlinJvmInternal = new MutablePackageFragmentDescriptor(
|
||||
createJavaModule("<jvm functions impl>"),
|
||||
new FqName("kotlin.jvm.internal")
|
||||
);
|
||||
|
||||
this.functionImpl = createClass(kotlinJvmInternal, "FunctionImpl", "out R");
|
||||
this.memberFunctionImpl = createClass(kotlinJvmInternal, "MemberFunctionImpl", "in T", "out R");
|
||||
this.extensionFunctionImpl = createClass(kotlinJvmInternal, "ExtensionFunctionImpl", "in T", "out R");
|
||||
this.kFunctionImpl = createClass(kotlinReflectJvmInternal, "KFunctionImpl", "out R");
|
||||
this.kExtensionFunctionImpl = createClass(kotlinReflectJvmInternal, "KExtensionFunctionImpl", "in T", "out R");
|
||||
this.kMemberFunctionImpl = createClass(kotlinReflectJvmInternal, "KMemberFunctionImpl", "in T", "out R");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -67,8 +62,8 @@ public class JvmRuntimeTypes {
|
||||
@NotNull String name,
|
||||
@NotNull String... typeParameters
|
||||
) {
|
||||
MutableClassDescriptor descriptor = new MutableClassDescriptor(packageFragment, packageFragment.getMemberScope(),
|
||||
ClassKind.CLASS, false, Name.identifier(name), SourceElement.NO_SOURCE);
|
||||
MutableClassDescriptor descriptor = new MutableClassDescriptor(packageFragment, packageFragment.getMemberScope(), ClassKind.CLASS,
|
||||
false, Name.identifier(name), SourceElement.NO_SOURCE);
|
||||
List<TypeParameterDescriptor> typeParameterDescriptors = new ArrayList<TypeParameterDescriptor>(typeParameters.length);
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
String[] s = typeParameters[i].split(" ");
|
||||
@@ -135,24 +130,24 @@ public class JvmRuntimeTypes {
|
||||
ClassDescriptor classDescriptor;
|
||||
JetType receiverType;
|
||||
if (extensionReceiver != null) {
|
||||
classDescriptor = kExtensionFunctionImpl;
|
||||
classDescriptor = extensionFunctionImpl;
|
||||
receiverType = extensionReceiver.getType();
|
||||
typeArguments.add(new TypeProjectionImpl(receiverType));
|
||||
}
|
||||
else if (dispatchReceiver != null) {
|
||||
classDescriptor = kMemberFunctionImpl;
|
||||
classDescriptor = memberFunctionImpl;
|
||||
receiverType = dispatchReceiver.getType();
|
||||
typeArguments.add(new TypeProjectionImpl(receiverType));
|
||||
}
|
||||
else {
|
||||
classDescriptor = kFunctionImpl;
|
||||
classDescriptor = functionImpl;
|
||||
receiverType = null;
|
||||
}
|
||||
|
||||
//noinspection ConstantConditions
|
||||
typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType()));
|
||||
|
||||
JetType kFunctionImplType = new JetTypeImpl(
|
||||
JetType functionImplType = new JetTypeImpl(
|
||||
classDescriptor.getDefaultType().getAnnotations(),
|
||||
classDescriptor.getTypeConstructor(),
|
||||
false,
|
||||
@@ -168,6 +163,6 @@ public class JvmRuntimeTypes {
|
||||
extensionReceiver != null
|
||||
);
|
||||
|
||||
return Arrays.asList(kFunctionImplType, kFunctionType);
|
||||
return Arrays.asList(functionImplType, kFunctionType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="reflection" />
|
||||
</component>
|
||||
</module>
|
||||
+4
-3
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.reflect.jvm.internal;
|
||||
package kotlin.jvm.internal
|
||||
|
||||
import kotlin.jvm.internal.FunctionImpl;
|
||||
import java.io.Serializable
|
||||
|
||||
public abstract class KFunctionImpl extends FunctionImpl {
|
||||
public abstract class MemberFunctionImpl<in T, out R> : Serializable {
|
||||
override fun toString() = "${(this as Object).getClass().getGenericInterfaces()[0]}"
|
||||
}
|
||||
Reference in New Issue
Block a user