Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
e8f9a9f3
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8f9a9f3
编写于
10月 12, 2015
作者:
M
Michael Bogdanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support reflection on @JvmField properties inside class companion
上级
f4b7913d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
0 deletion
+48
-0
core/reflection.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt
...ion.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt
+30
-0
core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt
...tion.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt
+18
-0
未找到文件。
core/reflection.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt
浏览文件 @
e8f9a9f3
...
...
@@ -158,6 +158,21 @@ internal abstract class FunctionCaller<out M : Member>(
}
}
class
ClassCompanionFieldGetter
(
field
:
ReflectField
,
klass
:
Class
<
*
>
)
:
FunctionCaller
<
ReflectField
>(
field
,
field
.
genericType
,
klass
,
emptyArray
()
)
{
override
fun
call
(
args
:
Array
<
*
>):
Any
?
{
checkArguments
(
args
)
return
member
.
get
(
args
.
first
())
}
}
class
StaticFieldSetter
(
field
:
ReflectField
,
notNull
:
Boolean
)
:
FieldSetter
(
field
,
notNull
)
class
InstanceFieldSetter
(
field
:
ReflectField
,
notNull
:
Boolean
)
:
FieldSetter
(
field
,
notNull
)
...
...
@@ -168,4 +183,19 @@ internal abstract class FunctionCaller<out M : Member>(
checkObjectInstance
(
args
.
firstOrNull
())
}
}
class
ClassCompanionFieldSetter
(
field
:
ReflectField
,
klass
:
Class
<
*
>
)
:
FunctionCaller
<
ReflectField
>(
field
,
Void
.
TYPE
,
klass
,
arrayOf
(
field
.
genericType
)
)
{
override
fun
call
(
args
:
Array
<
*
>):
Any
?
{
checkArguments
(
args
)
return
member
.
set
(
instanceClass
,
args
.
last
())
}
}
}
core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt
浏览文件 @
e8f9a9f3
...
...
@@ -18,7 +18,10 @@ package kotlin.reflect.jvm.internal
import
org.jetbrains.kotlin.descriptors.*
import
org.jetbrains.kotlin.descriptors.annotations.Annotations
import
org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
import
org.jetbrains.kotlin.load.kotlin.reflect.ReflectKotlinClass
import
org.jetbrains.kotlin.resolve.DescriptorFactory
import
org.jetbrains.kotlin.resolve.DescriptorUtils
import
org.jetbrains.kotlin.types.TypeUtils
import
java.lang.reflect.Field
import
java.lang.reflect.Modifier
...
...
@@ -86,14 +89,29 @@ internal interface KMutablePropertyImpl<R> : KMutableProperty<R>, KPropertyImpl<
private
fun
KPropertyImpl
.
Accessor
<*>.
computeCallerForAccessor
(
isGetter
:
Boolean
):
FunctionCaller
<
*
>
{
fun
isInsideClassCompanionObject
():
Boolean
{
val
possibleCompanionObject
=
property
.
descriptor
.
containingDeclaration
if
(
DescriptorUtils
.
isCompanionObject
(
possibleCompanionObject
)
&&
!
DescriptorUtils
.
isInterface
(
possibleCompanionObject
.
containingDeclaration
))
{
return
true
}
return
false
}
fun
isJvmStaticProperty
()
=
property
.
descriptor
.
annotations
.
findAnnotation
(
PLATFORM_STATIC
)
!=
null
||
property
.
descriptor
.
annotations
.
findAnnotation
(
JVM_STATIC
)
!=
null
fun
isNotNullProperty
()
=
!
TypeUtils
.
isNullableType
(
property
.
descriptor
.
type
)
fun
computeFieldCaller
(
field
:
Field
):
FunctionCaller
<
Field
>
=
when
{
isInsideClassCompanionObject
()
->
{
val
containingDeclaration
=
descriptor
.
containingDeclaration
as
ClassDescriptor
val
sourceElement
=
containingDeclaration
.
source
as
KotlinJvmBinarySourceElement
val
klass
=
(
sourceElement
.
binaryClass
as
ReflectKotlinClass
).
klass
if
(
isGetter
)
FunctionCaller
.
ClassCompanionFieldGetter
(
field
,
klass
)
else
FunctionCaller
.
ClassCompanionFieldSetter
(
field
,
klass
)
}
!
Modifier
.
isStatic
(
field
.
modifiers
)
->
if
(
isGetter
)
FunctionCaller
.
InstanceFieldGetter
(
field
)
else
FunctionCaller
.
InstanceFieldSetter
(
field
,
isNotNullProperty
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录