Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
62c25c03
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,发现更多精彩内容 >>
提交
62c25c03
编写于
10月 09, 2015
作者:
A
Alexey Tsvetkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace `is Array<T>` with `.isArrayOf<T>()`
上级
01cd277d
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
114 addition
and
44 deletion
+114
-44
compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java
...jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java
+1
-0
compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IsArrayOf.kt
.../src/org/jetbrains/kotlin/codegen/intrinsics/IsArrayOf.kt
+43
-0
compiler/testData/codegen/box/arrays/kt602.kt
compiler/testData/codegen/box/arrays/kt602.kt
+0
-2
compiler/testData/codegen/box/controlStructures/forInSmartCastToArray.kt
...ta/codegen/box/controlStructures/forInSmartCastToArray.kt
+3
-3
compiler/testData/codegen/boxWithStdlib/arrays/kt602.kt
compiler/testData/codegen/boxWithStdlib/arrays/kt602.kt
+2
-0
compiler/testData/codegen/boxWithStdlib/arrays/kt7338.kt
compiler/testData/codegen/boxWithStdlib/arrays/kt7338.kt
+1
-1
compiler/testData/codegen/boxWithStdlib/toArray/copyToArray.kt
...ler/testData/codegen/boxWithStdlib/toArray/copyToArray.kt
+1
-1
compiler/testData/codegen/boxWithStdlib/toArray/toArray.kt
compiler/testData/codegen/boxWithStdlib/toArray/toArray.kt
+2
-2
compiler/testData/codegen/boxWithStdlib/toArray/toArrayAlreadyPresent.kt
...ta/codegen/boxWithStdlib/toArray/toArrayAlreadyPresent.kt
+2
-2
compiler/testData/codegen/bytecodeText/isArrayOf.kt
compiler/testData/codegen/bytecodeText/isArrayOf.kt
+3
-0
compiler/testData/diagnostics/tests/cast/IsArray.kt
compiler/testData/diagnostics/tests/cast/IsArray.kt
+1
-1
compiler/testData/diagnostics/tests/cast/IsReified.kt
compiler/testData/diagnostics/tests/cast/IsReified.kt
+1
-1
compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java
...g/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java
+6
-0
compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java
...otlin/codegen/generated/BlackBoxCodegenTestGenerated.java
+0
-27
compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java
...gen/generated/BlackBoxWithStdlibCodegenTestGenerated.java
+18
-0
idea/testData/checker/infos/SmartCasts.kt
idea/testData/checker/infos/SmartCasts.kt
+2
-2
libraries/stdlib/src/kotlin/jvm/IsArrayOf.kt
libraries/stdlib/src/kotlin/jvm/IsArrayOf.kt
+26
-0
libraries/stdlib/test/collections/CollectionJVMTest.kt
libraries/stdlib/test/collections/CollectionJVMTest.kt
+1
-1
libraries/stdlib/test/collections/CollectionTest.kt
libraries/stdlib/test/collections/CollectionTest.kt
+1
-1
未找到文件。
compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java
浏览文件 @
62c25c03
...
...
@@ -66,6 +66,7 @@ public class IntrinsicMethods {
namedMethods
.
put
(
"kotlin.arrays.array"
,
new
JavaClassArray
());
namedMethods
.
put
(
"kotlin.jvm.internal.unsafe.monitorEnter"
,
MonitorInstruction
.
MONITOR_ENTER
);
namedMethods
.
put
(
"kotlin.jvm.internal.unsafe.monitorExit"
,
MonitorInstruction
.
MONITOR_EXIT
);
namedMethods
.
put
(
"kotlin.jvm.isArrayOf"
,
new
IsArrayOf
());
ImmutableList
<
Name
>
primitiveCastMethods
=
OperatorConventions
.
NUMBER_CONVERSIONS
.
asList
();
for
(
Name
method
:
primitiveCastMethods
)
{
...
...
compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IsArrayOf.kt
0 → 100644
浏览文件 @
62c25c03
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jetbrains.kotlin.codegen.intrinsics
import
org.jetbrains.kotlin.codegen.Callable
import
org.jetbrains.kotlin.codegen.ExpressionCodegen
import
org.jetbrains.kotlin.descriptors.FunctionDescriptor
import
org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import
org.jetbrains.kotlin.resolve.descriptorUtil.module
import
org.jetbrains.kotlin.types.Variance
class
IsArrayOf
:
IntrinsicMethod
()
{
override
fun
toCallable
(
fd
:
FunctionDescriptor
,
isSuper
:
Boolean
,
resolvedCall
:
ResolvedCall
<
*
>,
codegen
:
ExpressionCodegen
):
Callable
{
val
typeArguments
=
resolvedCall
.
typeArguments
assert
(
typeArguments
.
size
==
1
)
{
"Expected only one type parameter for Any?.isArrayOf(), got: $typeArguments"
}
val
typeMapper
=
codegen
.
state
.
typeMapper
val
method
=
typeMapper
.
mapToCallableMethod
(
fd
,
false
)
val
builtIns
=
fd
.
module
.
builtIns
val
elementType
=
typeArguments
.
values
().
first
()
val
arrayKtType
=
builtIns
.
getArrayType
(
Variance
.
INVARIANT
,
elementType
)
val
arrayType
=
typeMapper
.
mapType
(
arrayKtType
)
return
createIntrinsicCallable
(
method
)
{
it
.
instanceOf
(
arrayType
)
}
}
}
\ No newline at end of file
compiler/testData/codegen/box/arrays/kt602.kt
已删除
100644 → 0
浏览文件 @
01cd277d
fun
box
()
=
if
(
arrayOfNulls
<
Int
>(
10
)
is
Array
<
java.lang.
Integer
>)
"OK"
else
"fail"
compiler/testData/codegen/box/controlStructures/forInSmartCastToArray.kt
浏览文件 @
62c25c03
fun
f
(
x
:
Any
?):
String
{
if
(
x
is
Array
<
String
>)
{
fun
f
(
x
:
Any
?):
Any
?
{
if
(
x
is
Array
<
*
>)
{
for
(
i
in
x
)
{
return
i
}
...
...
@@ -10,5 +10,5 @@ fun f(x: Any?): String {
fun
box
():
String
{
val
a
=
arrayOfNulls
<
String
>(
1
)
as
Array
<
String
>
a
[
0
]
=
"OK"
return
f
(
a
)
return
f
(
a
)
as
String
}
compiler/testData/codegen/boxWithStdlib/arrays/kt602.kt
0 → 100644
浏览文件 @
62c25c03
fun
box
()
=
if
(
arrayOfNulls
<
Int
>(
10
).
isArrayOf
<
java
.
lang
.
Integer
>())
"OK"
else
"fail"
compiler/testData/codegen/boxWithStdlib/arrays/kt7338.kt
浏览文件 @
62c25c03
fun
foo
(
x
:
Any
):
String
{
return
if
(
x
is
Array
<
String
>)
x
[
0
]
else
"fail"
return
if
(
x
is
Array
<
*
>
&&
x
.
isArrayOf
<
String
>())
(
x
as
Array
<
String
>)
[
0
]
else
"fail"
}
fun
box
():
String
{
...
...
compiler/testData/codegen/boxWithStdlib/toArray/copyToArray.kt
浏览文件 @
62c25c03
...
...
@@ -2,7 +2,7 @@ import java.util.Arrays
fun
box
():
String
{
val
array
=
Arrays
.
asList
(
2
,
3
,
9
).
toTypedArray
()
if
(
array
!
is
Array
<
Int
>
)
return
array
.
javaClass
.
toString
()
if
(
!
array
.
isArrayOf
<
Int
>()
)
return
array
.
javaClass
.
toString
()
val
str
=
Arrays
.
toString
(
array
)
if
(
str
!=
"[2, 3, 9]"
)
return
str
...
...
compiler/testData/codegen/box/toArray/toArray.kt
→
compiler/testData/codegen/box
WithStdlib
/toArray/toArray.kt
浏览文件 @
62c25c03
...
...
@@ -8,8 +8,8 @@ fun box(): String {
val
array1
=
collection
.
toArray
()
val
array2
=
collection
.
toArray
(
arrayOfNulls
<
Int
>(
3
)
as
Array
<
Int
>)
if
(
array1
!
is
Array
<
Any
>
)
return
(
array1
as
Object
).
getClass
().
toString
()
if
(
array2
!
is
Array
<
Int
>
)
return
(
array2
as
Object
).
getClass
().
toString
()
if
(
!
array1
.
isArrayOf
<
Any
>()
)
return
(
array1
as
Object
).
getClass
().
toString
()
if
(
!
array2
.
isArrayOf
<
Int
>()
)
return
(
array2
as
Object
).
getClass
().
toString
()
val
s1
=
Arrays
.
toString
(
array1
)
val
s2
=
Arrays
.
toString
(
array2
)
...
...
compiler/testData/codegen/box/toArray/toArrayAlreadyPresent.kt
→
compiler/testData/codegen/box
WithStdlib
/toArray/toArrayAlreadyPresent.kt
浏览文件 @
62c25c03
...
...
@@ -23,8 +23,8 @@ fun box(): String {
val
array1
=
collection
.
toArray
()
val
array2
=
collection
.
toArray
(
arrayOfNulls
<
Int
>(
3
)
as
Array
<
Int
>)
if
(
array1
!
is
Array
<
Any
>
)
return
(
array1
as
Object
).
getClass
().
toString
()
if
(
array2
!
is
Array
<
Int
>
)
return
(
array2
as
Object
).
getClass
().
toString
()
if
(
!
array1
.
isArrayOf
<
Any
>()
)
return
(
array1
as
Object
).
getClass
().
toString
()
if
(
!
array2
.
isArrayOf
<
Int
>()
)
return
(
array2
as
Object
).
getClass
().
toString
()
val
s1
=
Arrays
.
toString
(
array1
)
val
s2
=
Arrays
.
toString
(
array2
)
...
...
compiler/testData/codegen/bytecodeText/isArrayOf.kt
0 → 100644
浏览文件 @
62c25c03
fun
f
(
x
:
Any
):
Boolean
=
x
is
Array
<
*
>
&&
x
.
isArrayOf
<
String
>()
// 2 INSTANCEOF
\ No newline at end of file
compiler/testData/diagnostics/tests/cast/IsArray.kt
浏览文件 @
62c25c03
fun
f
(
a
:
Array
<
out
Number
>)
=
a
is
Array
<
Int
>
fun
f
(
a
:
Array
<
out
Number
>)
=
a
.
isArrayOf
<
Int
>()
compiler/testData/diagnostics/tests/cast/IsReified.kt
浏览文件 @
62c25c03
fun
ff
(
a
:
Any
)
=
a
is
Array
<
String
>
\ No newline at end of file
fun
ff
(
a
:
Any
)
=
a
is
Array
<
*
>
&&
<!
DEBUG_INFO_SMARTCAST
!>
a
<!>.
isArrayOf
<
String
>()
\ No newline at end of file
compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java
浏览文件 @
62c25c03
...
...
@@ -149,6 +149,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest
(
fileName
);
}
@TestMetadata
(
"isArrayOf.kt"
)
public
void
testIsArrayOf
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/bytecodeText/isArrayOf.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"javaExtensionPropertyIntrinsic.kt"
)
public
void
testJavaExtensionPropertyIntrinsic
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt"
);
...
...
compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java
浏览文件 @
62c25c03
...
...
@@ -286,12 +286,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest
(
fileName
);
}
@TestMetadata
(
"kt602.kt"
)
public
void
testKt602
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/box/arrays/kt602.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"kt7288.kt"
)
public
void
testKt7288
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/box/arrays/kt7288.kt"
);
...
...
@@ -7409,27 +7403,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata
(
"compiler/testData/codegen/box/toArray"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
ToArray
extends
AbstractBlackBoxCodegenTest
{
public
void
testAllFilesPresentInToArray
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"compiler/testData/codegen/box/toArray"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"toArray.kt"
)
public
void
testToArray
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/box/toArray/toArray.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"toArrayAlreadyPresent.kt"
)
public
void
testToArrayAlreadyPresent
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/box/toArray/toArrayAlreadyPresent.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"compiler/testData/codegen/box/traits"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
...
...
compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java
浏览文件 @
62c25c03
...
...
@@ -256,6 +256,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib
(
fileName
);
}
@TestMetadata
(
"kt602.kt"
)
public
void
testKt602
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/boxWithStdlib/arrays/kt602.kt"
);
doTestWithStdlib
(
fileName
);
}
@TestMetadata
(
"kt7009.kt"
)
public
void
testKt7009
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/boxWithStdlib/arrays/kt7009.kt"
);
...
...
@@ -4644,6 +4650,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/boxWithStdlib/toArray/returnCopyToArray.kt"
);
doTestWithStdlib
(
fileName
);
}
@TestMetadata
(
"toArray.kt"
)
public
void
testToArray
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/boxWithStdlib/toArray/toArray.kt"
);
doTestWithStdlib
(
fileName
);
}
@TestMetadata
(
"toArrayAlreadyPresent.kt"
)
public
void
testToArrayAlreadyPresent
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"compiler/testData/codegen/boxWithStdlib/toArray/toArrayAlreadyPresent.kt"
);
doTestWithStdlib
(
fileName
);
}
}
@TestMetadata
(
"compiler/testData/codegen/boxWithStdlib/vararg"
)
...
...
idea/testData/checker/infos/SmartCasts.kt
浏览文件 @
62c25c03
...
...
@@ -227,8 +227,8 @@ fun foo(aa: Any): Int {
}
fun
inForLoop
(
x
:
Any
?)
{
if
(
x
is
Array
<
String
>)
{
for
(
i
in
<
info
descr
=
"Smart cast to kotlin.Array<
kotlin.String
>"
>
x
</
info
>)
{}
if
(
x
is
Array
<
*
>)
{
for
(
i
in
<
info
descr
=
"Smart cast to kotlin.Array<
*
>"
>
x
</
info
>)
{}
}
for
(
i
in
<
error
descr
=
"[ITERATOR_MISSING] For-loop range must have an iterator() method"
>
x
</
error
>)
{}
}
libraries/stdlib/src/kotlin/jvm/IsArrayOf.kt
0 → 100644
浏览文件 @
62c25c03
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
kotlin.jvm
import
kotlin.jvm.internal.Intrinsic
/**
* Checks if array can contain element of type [T].
*/
@Intrinsic
(
"kotlin.jvm.isArrayOf"
)
public
fun
<
reified
T
:
Any
>
Array
<*>.
isArrayOf
():
Boolean
=
T
::
class
.
java
.
isAssignableFrom
(
this
.
javaClass
.
componentType
)
\ No newline at end of file
libraries/stdlib/test/collections/CollectionJVMTest.kt
浏览文件 @
62c25c03
...
...
@@ -123,7 +123,7 @@ class CollectionJVMTest {
assertEquals
(
2
,
arr
.
size
())
todo
{
assertTrue
{
arr
is
Array
<
String
>
arr
.
isArrayOf
<
String
>()
}
}
}
...
...
libraries/stdlib/test/collections/CollectionTest.kt
浏览文件 @
62c25c03
...
...
@@ -403,7 +403,7 @@ class CollectionTest {
assertEquals
(
2
,
arr
.
size
())
todo
{
assertTrue
{
arr
is
Array
<
String
>
arr
.
isArrayOf
<
String
>()
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录