Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
d7d3a50d
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,发现更多精彩内容 >>
提交
d7d3a50d
编写于
3月 16, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
?: supported
上级
1e0d077a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
15 deletion
+39
-15
idea/src/org/jetbrains/jet/lang/types/JetTypeChecker.java
idea/src/org/jetbrains/jet/lang/types/JetTypeChecker.java
+19
-9
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
+12
-0
idea/src/org/jetbrains/jet/lang/types/TypeUtils.java
idea/src/org/jetbrains/jet/lang/types/TypeUtils.java
+7
-6
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
+1
-0
未找到文件。
idea/src/org/jetbrains/jet/lang/types/JetTypeChecker.java
浏览文件 @
d7d3a50d
...
...
@@ -17,6 +17,7 @@ public class JetTypeChecker {
this
.
standardLibrary
=
standardLibrary
;
}
@NotNull
private
Map
<
TypeConstructor
,
Set
<
TypeConstructor
>>
getConversionMap
()
{
// if (conversionMap.size() == 0) {
// addConversion(standardLibrary.getByte(),
...
...
@@ -62,7 +63,13 @@ public class JetTypeChecker {
// conversionMap.put(actual.getTypeConstructor(), new HashSet<TypeConstructor>(Arrays.asList(constructors)));
// }
//
public
JetType
commonSupertype
(
Collection
<
JetType
>
types
)
{
@NotNull
public
JetType
commonSupertype
(
@NotNull
JetType
...
types
)
{
return
commonSupertype
(
Arrays
.
asList
(
types
));
}
@NotNull
public
JetType
commonSupertype
(
@NotNull
Collection
<
JetType
>
types
)
{
Collection
<
JetType
>
typeSet
=
new
HashSet
<
JetType
>(
types
);
assert
!
typeSet
.
isEmpty
();
boolean
nullable
=
false
;
...
...
@@ -98,7 +105,8 @@ public class JetTypeChecker {
return
TypeUtils
.
makeNullableIfNeeded
(
result
,
nullable
);
}
private
JetType
computeSupertypeProjections
(
TypeConstructor
constructor
,
Set
<
JetType
>
types
)
{
@NotNull
private
JetType
computeSupertypeProjections
(
@NotNull
TypeConstructor
constructor
,
@NotNull
Set
<
JetType
>
types
)
{
// we assume that all the given types are applications of the same type constructor
assert
!
types
.
isEmpty
();
...
...
@@ -127,7 +135,8 @@ public class JetTypeChecker {
return
new
JetTypeImpl
(
Collections
.<
Attribute
>
emptyList
(),
constructor
,
nullable
,
newProjections
,
JetStandardClasses
.
STUB
);
}
private
TypeProjection
computeSupertypeProjection
(
TypeParameterDescriptor
parameterDescriptor
,
Set
<
TypeProjection
>
typeProjections
)
{
@NotNull
private
TypeProjection
computeSupertypeProjection
(
@NotNull
TypeParameterDescriptor
parameterDescriptor
,
@NotNull
Set
<
TypeProjection
>
typeProjections
)
{
if
(
typeProjections
.
size
()
==
1
)
{
return
typeProjections
.
iterator
().
next
();
}
...
...
@@ -183,7 +192,8 @@ public class JetTypeChecker {
}
}
private
Map
<
TypeConstructor
,
Set
<
JetType
>>
computeCommonRawSupertypes
(
Collection
<
JetType
>
types
)
{
@NotNull
private
Map
<
TypeConstructor
,
Set
<
JetType
>>
computeCommonRawSupertypes
(
@NotNull
Collection
<
JetType
>
types
)
{
assert
!
types
.
isEmpty
();
final
Map
<
TypeConstructor
,
Set
<
JetType
>>
constructorToAllInstances
=
new
HashMap
<
TypeConstructor
,
Set
<
JetType
>>();
...
...
@@ -244,19 +254,19 @@ public class JetTypeChecker {
return
result
;
}
private
void
markAll
(
TypeConstructor
typeConstructor
,
Set
<
TypeConstructor
>
markerSet
)
{
private
void
markAll
(
@NotNull
TypeConstructor
typeConstructor
,
@NotNull
Set
<
TypeConstructor
>
markerSet
)
{
markerSet
.
add
(
typeConstructor
);
for
(
JetType
type
:
typeConstructor
.
getSupertypes
())
{
markAll
(
type
.
getConstructor
(),
markerSet
);
}
}
private
<
R
>
R
dfs
(
JetType
current
,
Set
<
TypeConstructor
>
visited
,
DfsNodeHandler
<
R
>
handler
)
{
private
<
R
>
R
dfs
(
@NotNull
JetType
current
,
@NotNull
Set
<
TypeConstructor
>
visited
,
@NotNull
DfsNodeHandler
<
R
>
handler
)
{
doDfs
(
current
,
visited
,
handler
);
return
handler
.
result
();
}
private
void
doDfs
(
JetType
current
,
Set
<
TypeConstructor
>
visited
,
DfsNodeHandler
<?>
handler
)
{
private
void
doDfs
(
@NotNull
JetType
current
,
@NotNull
Set
<
TypeConstructor
>
visited
,
@NotNull
DfsNodeHandler
<?>
handler
)
{
if
(!
visited
.
add
(
current
.
getConstructor
()))
{
return
;
}
...
...
@@ -307,7 +317,7 @@ public class JetTypeChecker {
// This method returns the supertype of the first parameter that has the same constructor
// as the second parameter, applying the substitution of type arguments to it
@Nullable
private
JetType
findCorrespondingSupertype
(
JetType
subtype
,
JetType
supertype
)
{
private
JetType
findCorrespondingSupertype
(
@NotNull
JetType
subtype
,
@NotNull
JetType
supertype
)
{
TypeConstructor
constructor
=
subtype
.
getConstructor
();
if
(
constructor
.
equals
(
supertype
.
getConstructor
()))
{
return
subtype
;
...
...
@@ -321,7 +331,7 @@ public class JetTypeChecker {
return
null
;
}
private
boolean
checkSubtypeForTheSameConstructor
(
JetType
subtype
,
JetType
supertype
)
{
private
boolean
checkSubtypeForTheSameConstructor
(
@NotNull
JetType
subtype
,
@NotNull
JetType
supertype
)
{
TypeConstructor
constructor
=
subtype
.
getConstructor
();
assert
constructor
.
equals
(
supertype
.
getConstructor
());
...
...
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
浏览文件 @
d7d3a50d
...
...
@@ -728,6 +728,18 @@ public class JetTypeInferrer {
}
result
=
semanticServices
.
getStandardLibrary
().
getBooleanType
();
}
else
if
(
operationType
==
JetTokens
.
ELVIS
)
{
JetType
leftType
=
getType
(
scope
,
left
,
false
);
JetType
rightType
=
right
==
null
?
null
:
getType
(
scope
,
right
,
false
);
if
(
leftType
!=
null
)
{
if
(!
leftType
.
isNullable
())
{
semanticServices
.
getErrorHandler
().
genericWarning
(
left
.
getNode
(),
"Elvis operator (?:) is always returns the left operand of non-nullable type "
+
leftType
);
}
if
(
rightType
!=
null
)
{
result
=
TypeUtils
.
makeNullableAsSpecified
(
semanticServices
.
getTypeChecker
().
commonSupertype
(
leftType
,
rightType
),
rightType
.
isNullable
());
}
}
}
else
{
semanticServices
.
getErrorHandler
().
genericError
(
operationSign
.
getNode
(),
"Unknown operation"
);
}
...
...
idea/src/org/jetbrains/jet/lang/types/TypeUtils.java
浏览文件 @
d7d3a50d
...
...
@@ -12,17 +12,18 @@ import java.util.Set;
*/
public
class
TypeUtils
{
public
static
JetType
makeNullable
(
JetType
type
)
{
if
(
type
.
isNullable
())
{
return
type
;
}
return
new
JetTypeImpl
(
type
.
getAttributes
(),
type
.
getConstructor
(),
true
,
type
.
getArguments
(),
type
.
getMemberScope
());
return
makeNullableAsSpecified
(
type
,
true
);
}
public
static
JetType
makeNotNullable
(
JetType
type
)
{
if
(!
type
.
isNullable
())
{
return
makeNullableAsSpecified
(
type
,
false
);
}
public
static
JetType
makeNullableAsSpecified
(
JetType
type
,
boolean
nullable
)
{
if
(
type
.
isNullable
()
==
nullable
)
{
return
type
;
}
return
new
JetTypeImpl
(
type
.
getAttributes
(),
type
.
getConstructor
(),
fals
e
,
type
.
getArguments
(),
type
.
getMemberScope
());
return
new
JetTypeImpl
(
type
.
getAttributes
(),
type
.
getConstructor
(),
nullabl
e
,
type
.
getArguments
(),
type
.
getMemberScope
());
}
@Nullable
...
...
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
浏览文件 @
d7d3a50d
...
...
@@ -405,6 +405,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
assertType
(
"1 !== null"
,
"Boolean"
);
assertType
(
"true && false"
,
"Boolean"
);
assertType
(
"true || false"
,
"Boolean"
);
assertType
(
"null ?: false"
,
"Boolean"
);
}
private
void
assertSubtype
(
String
type1
,
String
type2
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录