Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
aba13415
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,发现更多精彩内容 >>
提交
aba13415
编写于
4月 21, 2011
作者:
D
Dmitry Jemerov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
failing test for property in class
上级
ec9018f2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
7 deletion
+52
-7
idea/src/org/jetbrains/jet/codegen/PropertyCodegen.java
idea/src/org/jetbrains/jet/codegen/PropertyCodegen.java
+6
-3
idea/testData/codegen/privateVar.jet
idea/testData/codegen/privateVar.jet
+6
-0
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
+25
-3
idea/tests/org/jetbrains/jet/codegen/PropertyGenTest.java
idea/tests/org/jetbrains/jet/codegen/PropertyGenTest.java
+15
-1
未找到文件。
idea/src/org/jetbrains/jet/codegen/PropertyCodegen.java
浏览文件 @
aba13415
...
...
@@ -45,7 +45,7 @@ public class PropertyCodegen {
}
public
void
gen
(
JetProperty
p
,
OwnerKind
kind
)
{
if
(
kind
==
OwnerKind
.
NAMESPACE
)
{
if
(
kind
==
OwnerKind
.
NAMESPACE
||
kind
==
OwnerKind
.
IMPLEMENTATION
)
{
final
VariableDescriptor
descriptor
=
context
.
getVariableDescriptor
(
p
);
if
(!(
descriptor
instanceof
PropertyDescriptor
))
{
throw
new
UnsupportedOperationException
(
"expect a property to have a property descriptor"
);
...
...
@@ -59,8 +59,11 @@ public class PropertyCodegen {
value
=
((
JetConstantExpression
)
initializer
).
getValue
();
}
}
v
.
visitField
(
Opcodes
.
ACC_STATIC
|
Opcodes
.
ACC_PRIVATE
,
p
.
getName
(),
int
modifiers
=
Opcodes
.
ACC_PRIVATE
;
if
(
kind
==
OwnerKind
.
NAMESPACE
)
{
modifiers
|=
Opcodes
.
ACC_STATIC
;
}
v
.
visitField
(
modifiers
,
p
.
getName
(),
mapper
.
mapType
(
descriptor
.
getOutType
()).
getDescriptor
(),
null
,
value
);
}
...
...
idea/testData/codegen/privateVar.jet
0 → 100644
浏览文件 @
aba13415
class PrivateVar {
private var x = 0;
fun setValueOfX(val: Int) { x = val }
fun getValueOfX() = x
}
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
浏览文件 @
aba13415
...
...
@@ -16,6 +16,20 @@ import java.util.List;
* @author yole
*/
public
abstract
class
CodegenTestCase
extends
LightCodeInsightFixtureTestCase
{
private
MyClassLoader
myClassLoader
;
@Override
protected
void
setUp
()
throws
Exception
{
super
.
setUp
();
myClassLoader
=
new
MyClassLoader
(
NamespaceGenTest
.
class
.
getClassLoader
());
}
@Override
protected
void
tearDown
()
throws
Exception
{
myClassLoader
=
null
;
super
.
tearDown
();
}
protected
void
loadText
(
final
String
text
)
{
myFixture
.
configureByText
(
JetFileType
.
INSTANCE
,
text
);
}
...
...
@@ -55,8 +69,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
for
(
String
file
:
files
)
{
if
(
file
.
equals
(
fqName
.
replace
(
'.'
,
'/'
)
+
".class"
))
{
final
byte
[]
data
=
state
.
asBytes
(
file
);
MyClassLoader
classLoader
=
new
MyClassLoader
(
NamespaceGenTest
.
class
.
getClassLoader
());
return
classLoader
.
doDefineClass
(
fqName
,
data
);
return
myClassLoader
.
doDefineClass
(
fqName
,
data
);
}
}
...
...
@@ -81,6 +94,10 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
protected
Method
generateFunction
(
String
name
)
{
Class
aClass
=
generateNamespaceClass
();
return
findMethodByName
(
aClass
,
name
);
}
protected
static
Method
findMethodByName
(
Class
aClass
,
String
name
)
{
for
(
Method
method
:
aClass
.
getMethods
())
{
if
(
method
.
getName
().
equals
(
name
))
{
return
method
;
...
...
@@ -89,11 +106,16 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
throw
new
IllegalArgumentException
(
"couldn't find method "
+
name
);
}
protected
void
assertIsCurrentTime
(
long
returnValue
)
{
protected
static
void
assertIsCurrentTime
(
long
returnValue
)
{
long
currentTime
=
System
.
currentTimeMillis
();
assertTrue
(
Math
.
abs
(
returnValue
-
currentTime
)
<=
1L
);
}
protected
Class
loadImplementationClass
(
Codegens
codegens
,
final
String
name
)
{
loadClass
(
name
,
codegens
);
return
loadClass
(
name
+
"$$Impl"
,
codegens
);
}
private
static
class
MyClassLoader
extends
ClassLoader
{
public
MyClassLoader
(
ClassLoader
parent
)
{
super
(
parent
);
...
...
idea/tests/org/jetbrains/jet/codegen/PropertyGenTest.java
浏览文件 @
aba13415
...
...
@@ -11,7 +11,21 @@ public class PropertyGenTest extends CodegenTestCase {
public
void
testPrivateVal
()
throws
Exception
{
loadFile
(
"privateVal.jet"
);
System
.
out
.
println
(
generateToText
());
// TODO
final
Class
aClass
=
loadImplementationClass
(
generateClassesInFile
(),
"PrivateVal"
);
final
Field
[]
fields
=
aClass
.
getDeclaredFields
();
assertEquals
(
1
,
fields
.
length
);
final
Field
field
=
fields
[
0
];
assertEquals
(
"prop"
,
field
.
getName
());
}
public
void
testPrivateVar
()
throws
Exception
{
loadFile
(
"privateVar.jet"
);
final
Class
aClass
=
loadImplementationClass
(
generateClassesInFile
(),
"PrivateVar"
);
final
Object
instance
=
aClass
.
newInstance
();
Method
setter
=
findMethodByName
(
aClass
,
"setValueOfX"
);
setter
.
invoke
(
instance
,
239
);
Method
getter
=
findMethodByName
(
aClass
,
"getValueOfX"
);
assertEquals
(
239
,
((
Integer
)
getter
.
invoke
(
instance
)).
intValue
());
}
public
void
testPropertyInNamespace
()
throws
Exception
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录