Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
6dfa8ca8
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,发现更多精彩内容 >>
提交
6dfa8ca8
编写于
5月 27, 2011
作者:
D
Dmitry Jemerov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
don't forget to put receiver on stack when calling extension functions
上级
ff6fcabd
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
53 addition
and
22 deletion
+53
-22
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+7
-3
idea/testData/codegen/extensionFunctions/whenFail.jet
idea/testData/codegen/extensionFunctions/whenFail.jet
+14
-0
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
+25
-10
idea/tests/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java
...sts/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java
+6
-0
idea/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
.../tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
+1
-9
未找到文件。
idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
6dfa8ca8
...
...
@@ -722,13 +722,17 @@ public class ExpressionCodegen extends JetVisitor {
methodDescriptor
.
getDescriptor
());
}
else
{
methodDescriptor
=
typeMapper
.
mapSignature
((
JetFunction
)
declarationPsiElement
);
if
(
functionParent
instanceof
NamespaceDescriptorImpl
&&
declarationPsiElement
instanceof
JetFunction
)
{
final
JetFunction
jetFunction
=
(
JetFunction
)
declarationPsiElement
;
methodDescriptor
=
typeMapper
.
mapSignature
(
jetFunction
);
if
(
functionParent
instanceof
NamespaceDescriptorImpl
)
{
if
(
jetFunction
.
getReceiverTypeRef
()
!=
null
)
{
ensureReceiverOnStack
(
expression
);
}
pushMethodArguments
(
expression
,
methodDescriptor
);
final
String
owner
=
NamespaceCodegen
.
getJVMClassName
(
DescriptorRenderer
.
getFQName
(
functionParent
));
v
.
invokestatic
(
owner
,
methodDescriptor
.
getName
(),
methodDescriptor
.
getDescriptor
());
}
else
if
(
functionParent
instanceof
ClassDescriptor
&&
declarationPsiElement
instanceof
JetFunction
)
{
else
if
(
functionParent
instanceof
ClassDescriptor
)
{
ensureReceiverOnStack
(
expression
);
pushMethodArguments
(
expression
,
methodDescriptor
);
final
String
owner
=
JetTypeMapper
.
jvmNameForInterface
((
ClassDescriptor
)
functionParent
);
...
...
idea/testData/codegen/extensionFunctions/whenFail.jet
0 → 100644
浏览文件 @
6dfa8ca8
fun StringBuilder.takeFirst(): Char {
if (this.length() == 0) return '\0'
val c = this.charAt(0)
this.deleteCharAt(0)
return c
}
fun foo(expr: StringBuilder): Int {
val c = expr.takeFirst()
when(c) {
'\0' => throw new Exception("zero")
else => throw new Exception("nonzero" + c)
}
}
idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
浏览文件 @
6dfa8ca8
...
...
@@ -12,9 +12,8 @@ import org.jetbrains.jet.lang.psi.JetNamespace;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
import
org.jetbrains.jet.parsing.JetParsingTest
;
import
java
x.swing.JComponent
;
import
java
.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.nio.channels.NonWritableChannelException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -25,6 +24,17 @@ import java.util.Map;
public
abstract
class
CodegenTestCase
extends
LightCodeInsightFixtureTestCase
{
private
MyClassLoader
myClassLoader
;
protected
static
void
assertThrows
(
Method
foo
,
Class
<?
extends
Throwable
>
exceptionClass
,
Object
instance
,
Object
...
args
)
throws
IllegalAccessException
{
boolean
caught
=
false
;
try
{
foo
.
invoke
(
instance
,
args
);
}
catch
(
InvocationTargetException
ex
)
{
caught
=
exceptionClass
.
isInstance
(
ex
.
getTargetException
());
}
assertTrue
(
caught
);
}
@Override
protected
void
setUp
()
throws
Exception
{
super
.
setUp
();
...
...
@@ -128,6 +138,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
}
protected
Codegens
generateClassesInFile
()
{
try
{
Codegens
state
=
new
Codegens
(
getProject
(),
false
);
JetFile
jetFile
=
(
JetFile
)
myFixture
.
getFile
();
AnalyzingUtils
.
checkForSyntacticErrors
(
jetFile
);
...
...
@@ -136,6 +147,10 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
NamespaceCodegen
codegen
=
state
.
forNamespace
(
namespace
);
codegen
.
generate
(
namespace
);
return
state
;
}
catch
(
RuntimeException
e
)
{
System
.
out
.
println
(
generateToText
());
throw
e
;
}
}
protected
Method
generateFunction
()
{
...
...
idea/tests/org/jetbrains/jet/codegen/ExtensionFunctionsTest.java
浏览文件 @
6dfa8ca8
...
...
@@ -17,4 +17,10 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
final
Character
c
=
(
Character
)
foo
.
invoke
(
null
);
assertEquals
(
'f'
,
c
.
charValue
());
}
public
void
testWhenFail
()
throws
Exception
{
loadFile
();
Method
foo
=
generateFunction
(
"foo"
);
assertThrows
(
foo
,
Exception
.
class
,
null
,
new
StringBuilder
());
}
}
idea/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java
浏览文件 @
6dfa8ca8
...
...
@@ -2,7 +2,6 @@ package org.jetbrains.jet.codegen;
import
jet.NoPatternMatchedException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
/**
...
...
@@ -25,14 +24,7 @@ public class PatternMatchingTest extends CodegenTestCase {
loadFile
();
Method
foo
=
generateFunction
();
assertTrue
((
Boolean
)
foo
.
invoke
(
null
,
0
));
boolean
caught
=
false
;
try
{
foo
.
invoke
(
null
,
1
);
}
catch
(
InvocationTargetException
ex
)
{
caught
=
ex
.
getTargetException
()
instanceof
NoPatternMatchedException
;
}
assertTrue
(
caught
);
assertThrows
(
foo
,
NoPatternMatchedException
.
class
,
null
,
1
);
}
public
void
testPattern
()
throws
Exception
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录