Introduce abstract class FunctionReference, which is supposed to be a
superclass for all anonymous classes generated for function references. Each
anonymous subclass will have statically-generated symbol info, which will be
used by reflection to locate the symbol
It has its arity precomputed, as opposed to the future KFunctionImpl inheriting
from FunctionImpl, for which the computation of arity can take some time and so
it shouldn't be passed in the constructor and saved as a field
Add a file in package 'kotlin.jvm.functions' to the project and replace
explicit imports of functions 'kotlin.Function{n}' to two imports 'kotlin.*'
and 'kotlin.jvm.functions.*', so that the codebase can be compiled both by the
old and by the new compiler
Get rid of multiple usages of IntrinsicObjects where JavaToKotlinClassMap was
already used, simplify code, and support loading of *CompanionObject as Kotlin
built-in companions from Java code.
Also fix a small bug where Boolean was considered a class with an intrinsic
companion in IntrinsicObjects, although it was not
Properties obtained by KClass.properties were having strong references to
descriptors (captured by closures, which are strongly retained by
DescriptorBasedProperty). Support initial value in lazy soft properties
The cache in moduleByClassLoader.kt contains weak references to instances of
RuntimeModuleData. However, prior to this change no one else had any _strong_
reference to the corresponding RuntimeModuleData: KClassImpl depends on the
ModuleDescriptor almost directly. Therefore the weak references were sometimes
garbage collected and a new module was constructed for a new reflection object,
which resulted in broken equality between two reflection objects.
No test added because it was rather hard to come up with (and, more
importantly, to support) a test case.
- use ConcurrentHashMap as a cache of class loaders to module descriptors
- KClassImpl now has a lazy class descriptor and it manages property creation
by looking (also lazily) for the property descriptor in the corresponding
scope
- since deserialized descriptors have full information about where a JVM symbol
is located and what signature it has, new tests will begin to pass where
Kotlin model and Java reflection model differ, see classObjectVar.kt
This class needs to be written in Java because no Kotlin classes can be used in
KClassImpl constructor (otherwise since each Kotlin class creates a KClassImpl
in its static initializer, this would result in infinite recursion)
The former name clashes with java.lang.IllegalAccessException and proved to be
inconvenient because it should always be qualified in the source.
Also use java.lang exception's message as kotlin.reflect exception's message
Introduce an abstract factory class ReflectionFactory which is responsible for creating
reflection objects (KClass, KProperty, ...). The meaningful implementation is
located in "reflection.jvm" where KClassImpl/KPropertyImpl/... are accessible
and can be instantiated. The default implementation will be used in the lite
runtime with no reflection and will return nulls / throw exceptions there.
Put all functions, calls to which are generated by JVM back-end, in one place:
the class named Reflection which contains only static methods. Previously these
functions were scattered across different files in module "reflection.jvm".
The code using reflection may now be compiled against either runtime, but
reflection features will work if and only if reflection is accessible at
runtime