Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
904a8b21
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,发现更多精彩内容 >>
提交
904a8b21
编写于
2月 03, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Types for function literals
上级
87ba0420
变更
17
显示空白变更内容
内联
并排
Showing
17 changed file
with
476 addition
and
260 deletion
+476
-260
idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java
idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java
+4
-2
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
...g/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
+10
-8
idea/src/org/jetbrains/jet/lang/resolve/TypeResolver.java
idea/src/org/jetbrains/jet/lang/resolve/TypeResolver.java
+15
-0
idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
.../src/org/jetbrains/jet/lang/types/JetStandardClasses.java
+57
-1
idea/src/org/jetbrains/jet/lang/types/JetTypeChecker.java
idea/src/org/jetbrains/jet/lang/types/JetTypeChecker.java
+61
-0
idea/src/org/jetbrains/jet/lang/types/PropertyDescriptor.java
.../src/org/jetbrains/jet/lang/types/PropertyDescriptor.java
+17
-1
idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java
idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java
+2
-1
idea/testData/psi/FunctionTypes.txt
idea/testData/psi/FunctionTypes.txt
+66
-56
idea/testData/psi/FunctionTypes_ERR.txt
idea/testData/psi/FunctionTypes_ERR.txt
+20
-18
idea/testData/psi/Functions.txt
idea/testData/psi/Functions.txt
+72
-64
idea/testData/psi/Functions_ERR.txt
idea/testData/psi/Functions_ERR.txt
+18
-16
idea/testData/psi/When.txt
idea/testData/psi/When.txt
+5
-4
idea/testData/psi/examples/FunctionsAndTypes.txt
idea/testData/psi/examples/FunctionsAndTypes.txt
+67
-57
idea/testData/psi/examples/Graph.txt
idea/testData/psi/examples/Graph.txt
+15
-12
idea/testData/psi/examples/PolymorphicClassObjects.txt
idea/testData/psi/examples/PolymorphicClassObjects.txt
+5
-4
idea/testData/psi/examples/util/Comparison.txt
idea/testData/psi/examples/util/Comparison.txt
+20
-16
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
+22
-0
未找到文件。
idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java
浏览文件 @
904a8b21
...
...
@@ -1412,8 +1412,10 @@ public class JetParsing extends AbstractJetParsing {
}
if
(
isFunctionTypeContents
)
{
if
(!
tryParseValueParameter
())
{
PsiBuilder
.
Marker
valueParameter
=
mark
();
parseModifierList
();
// lazy, out, ref
parseTypeRef
();
valueParameter
.
done
(
VALUE_PARAMETER
);
}
}
else
{
parseValueParameter
();
...
...
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
浏览文件 @
904a8b21
...
...
@@ -2,14 +2,8 @@ package org.jetbrains.jet.lang.resolve;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.psi.JetClass
;
import
org.jetbrains.jet.lang.psi.JetDelegationSpecifier
;
import
org.jetbrains.jet.lang.psi.JetTypeParameter
;
import
org.jetbrains.jet.lang.psi.JetTypeReference
;
import
org.jetbrains.jet.lang.types.ClassDescriptor
;
import
org.jetbrains.jet.lang.types.JetStandardClasses
;
import
org.jetbrains.jet.lang.types.Type
;
import
org.jetbrains.jet.lang.types.TypeParameterDescriptor
;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.lang.types.*
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
java.util.*
;
...
...
@@ -106,4 +100,12 @@ public class ClassDescriptorResolver {
return
super
.
getTypeParameterDescriptor
(
name
);
}
}
@NotNull
public
PropertyDescriptor
resolvePropertyDescriptor
(
@NotNull
JetScope
scope
,
@NotNull
JetParameter
parameter
)
{
return
new
PropertyDescriptor
(
AttributeResolver
.
INSTANCE
.
resolveAttributes
(
parameter
.
getModifierList
()),
parameter
.
getName
(),
TypeResolver
.
INSTANCE
.
resolveType
(
scope
,
parameter
.
getTypeReference
()));
}
}
idea/src/org/jetbrains/jet/lang/resolve/TypeResolver.java
浏览文件 @
904a8b21
...
...
@@ -70,6 +70,21 @@ public class TypeResolver {
result
[
0
]
=
JetStandardClasses
.
getTupleType
(
resolveTypes
(
scope
,
type
.
getComponentTypeRefs
()));
}
@Override
public
void
visitFunctionType
(
JetFunctionType
type
)
{
JetTypeReference
receiverTypeRef
=
type
.
getReceiverTypeRef
();
Type
receiverType
=
receiverTypeRef
==
null
?
null
:
resolveType
(
scope
,
receiverTypeRef
);
List
<
Type
>
parameterTypes
=
new
ArrayList
<
Type
>();
for
(
JetParameter
parameter
:
type
.
getParameters
())
{
parameterTypes
.
add
(
resolveType
(
scope
,
parameter
.
getTypeReference
()));
}
Type
returnType
=
resolveType
(
scope
,
type
.
getReturnTypeRef
());
result
[
0
]
=
JetStandardClasses
.
getFunctionType
(
attributes
,
receiverType
,
parameterTypes
,
returnType
);
}
@Override
public
void
visitJetElement
(
JetElement
elem
)
{
throw
new
IllegalArgumentException
(
"Unsupported type: "
+
elem
);
...
...
idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
浏览文件 @
904a8b21
package
org.jetbrains.jet.lang.types
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.*
;
...
...
@@ -62,7 +63,7 @@ public class JetStandardClasses {
parameters
.
add
(
new
TypeParameterDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
Variance
.
OUT_VARIANCE
,
"T"
+
j
,
Collections
.
<
Type
>
emptySet
(
)));
Collections
.
singleton
(
getNullableAnyType
()
)));
}
TUPLE
[
i
]
=
new
ClassDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
...
...
@@ -73,6 +74,42 @@ public class JetStandardClasses {
}
}
public
static
final
int
FUNCTION_COUNT
=
22
;
private
static
final
ClassDescriptor
[]
FUNCTION
=
new
ClassDescriptor
[
FUNCTION_COUNT
];
private
static
final
ClassDescriptor
[]
RECEIVER_FUNCTION
=
new
ClassDescriptor
[
FUNCTION_COUNT
];
static
{
for
(
int
i
=
0
;
i
<
FUNCTION_COUNT
;
i
++)
{
List
<
TypeParameterDescriptor
>
parameters
=
new
ArrayList
<
TypeParameterDescriptor
>();
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
parameters
.
add
(
new
TypeParameterDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
Variance
.
IN_VARIANCE
,
"P"
+
j
,
Collections
.
singleton
(
getNullableAnyType
())));
}
parameters
.
add
(
new
TypeParameterDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
Variance
.
OUT_VARIANCE
,
"R"
,
Collections
.
singleton
(
getNullableAnyType
())));
FUNCTION
[
i
]
=
new
ClassDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
false
,
"Function"
+
i
,
parameters
,
Collections
.
singleton
(
JetStandardClasses
.
getAnyType
()));
parameters
.
add
(
0
,
new
TypeParameterDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
Variance
.
IN_VARIANCE
,
"T"
,
Collections
.
singleton
(
getNullableAnyType
())));
RECEIVER_FUNCTION
[
i
]
=
new
ClassDescriptor
(
Collections
.<
Attribute
>
emptyList
(),
false
,
"ReceiverFunction"
+
i
,
parameters
,
Collections
.
singleton
(
JetStandardClasses
.
getAnyType
()));
}
}
public
static
final
TypeMemberDomain
STUB
=
new
TypeMemberDomain
()
{
@Override
public
ClassDescriptor
getClassDescriptor
(
@NotNull
Type
type
)
{
...
...
@@ -259,4 +296,23 @@ public class JetStandardClasses {
}
return
result
;
}
// TODO : labeled version?
public
static
Type
getFunctionType
(
List
<
Attribute
>
attributes
,
@Nullable
Type
receiverType
,
@NotNull
List
<
Type
>
parameterTypes
,
@NotNull
Type
returnType
)
{
List
<
TypeProjection
>
arguments
=
new
ArrayList
<
TypeProjection
>();
if
(
receiverType
!=
null
)
{
arguments
.
add
(
defaultProjection
(
receiverType
));
}
for
(
Type
parameterType
:
parameterTypes
)
{
arguments
.
add
(
defaultProjection
(
parameterType
));
}
arguments
.
add
(
defaultProjection
(
returnType
));
int
size
=
parameterTypes
.
size
();
TypeConstructor
constructor
=
receiverType
==
null
?
FUNCTION
[
size
].
getTypeConstructor
()
:
RECEIVER_FUNCTION
[
size
].
getTypeConstructor
();
return
new
TypeImpl
(
attributes
,
constructor
,
false
,
arguments
,
STUB
);
}
private
static
TypeProjection
defaultProjection
(
Type
returnType
)
{
return
new
TypeProjection
(
Variance
.
INVARIANT
,
returnType
);
}
}
idea/src/org/jetbrains/jet/lang/types/JetTypeChecker.java
浏览文件 @
904a8b21
...
...
@@ -5,7 +5,9 @@ import org.jetbrains.annotations.NotNull;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.JetNodeTypes
;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.lang.resolve.ClassDescriptorResolver
;
import
org.jetbrains.jet.lang.resolve.JetScope
;
import
org.jetbrains.jet.lang.resolve.JetScopeAdapter
;
import
org.jetbrains.jet.lang.resolve.TypeResolver
;
import
org.jetbrains.jet.lexer.JetTokens
;
...
...
@@ -34,6 +36,65 @@ public class JetTypeChecker {
public
Type
getType
(
@NotNull
final
JetScope
scope
,
@NotNull
JetExpression
expression
)
{
final
Type
[]
result
=
new
Type
[
1
];
expression
.
accept
(
new
JetVisitor
()
{
@Override
public
void
visitReferenceExpression
(
JetReferenceExpression
expression
)
{
// TODO : other members
// TODO : type substitutions???
PropertyDescriptor
property
=
scope
.
getProperty
(
expression
.
getReferencedName
());
if
(
property
!=
null
)
{
result
[
0
]
=
property
.
getType
();
}
}
@Override
public
void
visitFunctionLiteralExpression
(
JetFunctionLiteralExpression
expression
)
{
JetTypeReference
returnTypeRef
=
expression
.
getReturnTypeRef
();
JetTypeReference
receiverTypeRef
=
expression
.
getReceiverTypeRef
();
final
Type
thisType
;
if
(
receiverTypeRef
!=
null
)
{
thisType
=
TypeResolver
.
INSTANCE
.
resolveType
(
scope
,
receiverTypeRef
);
}
else
{
thisType
=
scope
.
getThisType
();
}
List
<
JetExpression
>
body
=
expression
.
getBody
();
final
Map
<
String
,
PropertyDescriptor
>
parameterDescriptors
=
new
HashMap
<
String
,
PropertyDescriptor
>();
List
<
Type
>
parameterTypes
=
new
ArrayList
<
Type
>();
for
(
JetParameter
parameter
:
expression
.
getParameters
())
{
JetTypeReference
typeReference
=
parameter
.
getTypeReference
();
if
(
typeReference
==
null
)
{
throw
new
UnsupportedOperationException
(
"Type inference for parameters is not implemented yet"
);
}
PropertyDescriptor
propertyDescriptor
=
ClassDescriptorResolver
.
INSTANCE
.
resolvePropertyDescriptor
(
scope
,
parameter
);
parameterDescriptors
.
put
(
parameter
.
getName
(),
propertyDescriptor
);
parameterTypes
.
add
(
propertyDescriptor
.
getType
());
}
Type
returnType
;
if
(
returnTypeRef
!=
null
)
{
returnType
=
TypeResolver
.
INSTANCE
.
resolveType
(
scope
,
returnTypeRef
);
}
else
if
(
body
.
isEmpty
())
{
returnType
=
JetStandardClasses
.
getUnitType
();
}
else
{
returnType
=
getType
(
new
JetScopeAdapter
(
scope
)
{
@Override
public
Type
getThisType
()
{
return
thisType
;
}
@Override
public
PropertyDescriptor
getProperty
(
String
name
)
{
PropertyDescriptor
propertyDescriptor
=
parameterDescriptors
.
get
(
name
);
if
(
propertyDescriptor
==
null
)
{
return
super
.
getProperty
(
name
);
}
return
propertyDescriptor
;
}
},
body
.
get
(
body
.
size
()
-
1
));
}
result
[
0
]
=
JetStandardClasses
.
getFunctionType
(
null
,
receiverTypeRef
==
null
?
null
:
thisType
,
parameterTypes
,
returnType
);
}
@Override
public
void
visitParenthesizedExpression
(
JetParenthesizedExpression
expression
)
{
result
[
0
]
=
getType
(
scope
,
expression
.
getExpression
());
...
...
idea/src/org/jetbrains/jet/lang/types/PropertyDescriptor.java
浏览文件 @
904a8b21
package
org.jetbrains.jet.lang.types
;
import
java.util.List
;
/**
* @author abreslav
*/
public
class
PropertyDescriptor
{
public
class
PropertyDescriptor
extends
MemberDescriptorImpl
{
private
Type
type
;
public
PropertyDescriptor
(
List
<
Attribute
>
attributes
,
String
name
,
Type
type
)
{
super
(
attributes
,
name
);
this
.
type
=
type
;
}
public
PropertyDescriptor
(
List
<
Attribute
>
attributes
,
String
name
)
{
this
(
attributes
,
name
,
null
);
}
public
Type
getType
()
{
return
type
;
}
}
idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java
浏览文件 @
904a8b21
package
org.jetbrains.jet.lang.types
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -16,7 +17,7 @@ public class TypeConstructor extends AnnotatedImpl {
super
(
attributes
);
this
.
sealed
=
sealed
;
this
.
debugName
=
debugName
;
this
.
parameters
=
parameters
;
this
.
parameters
=
new
ArrayList
<
TypeParameterDescriptor
>(
parameters
)
;
this
.
supertypes
=
supertypes
;
}
...
...
idea/testData/psi/FunctionTypes.txt
浏览文件 @
904a8b21
...
...
@@ -14,6 +14,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
MODIFIER_LIST
ATTRIBUTE_ANNOTATION
PsiElement(LBRACKET)('[')
...
...
@@ -52,6 +53,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -280,6 +282,7 @@ JetFile: FunctionTypes.jet
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -319,6 +322,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -358,6 +362,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -374,6 +379,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -411,6 +417,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -427,6 +434,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -474,6 +482,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
MODIFIER_LIST
PsiElement(ref)('ref')
PsiWhiteSpace(' ')
...
...
@@ -496,6 +505,7 @@ JetFile: FunctionTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
MODIFIER_LIST
PsiElement(ref)('ref')
PsiWhiteSpace(' ')
...
...
idea/testData/psi/FunctionTypes_ERR.txt
浏览文件 @
904a8b21
...
...
@@ -14,6 +14,7 @@ JetFile: FunctionTypes_ERR.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
MODIFIER_LIST
ATTRIBUTE_ANNOTATION
PsiElement(LBRACKET)('[')
...
...
@@ -52,6 +53,7 @@ JetFile: FunctionTypes_ERR.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/Functions.txt
浏览文件 @
904a8b21
...
...
@@ -83,6 +83,7 @@ JetFile: Functions.jet
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -185,6 +186,7 @@ JetFile: Functions.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -305,6 +307,7 @@ JetFile: Functions.jet
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -409,6 +412,7 @@ JetFile: Functions.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -539,6 +543,7 @@ JetFile: Functions.jet
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -649,6 +654,7 @@ JetFile: Functions.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -726,6 +732,7 @@ JetFile: Functions.jet
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -801,6 +808,7 @@ JetFile: Functions.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/Functions_ERR.txt
浏览文件 @
904a8b21
...
...
@@ -109,6 +109,7 @@ JetFile: Functions_ERR.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -416,6 +417,7 @@ JetFile: Functions_ERR.jet
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/When.txt
浏览文件 @
904a8b21
...
...
@@ -746,6 +746,7 @@ JetFile: When.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/examples/FunctionsAndTypes.txt
浏览文件 @
904a8b21
...
...
@@ -14,6 +14,7 @@ JetFile: FunctionsAndTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -44,12 +45,14 @@ JetFile: FunctionsAndTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -80,6 +83,7 @@ JetFile: FunctionsAndTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
TUPLE_TYPE
PsiElement(LPAR)('(')
...
...
@@ -121,6 +125,7 @@ JetFile: FunctionsAndTypes.jet
PsiWhiteSpace(' ')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -134,6 +139,7 @@ JetFile: FunctionsAndTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -167,11 +173,13 @@ JetFile: FunctionsAndTypes.jet
PsiWhiteSpace(' ')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -194,6 +202,7 @@ JetFile: FunctionsAndTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -643,6 +652,7 @@ JetFile: FunctionsAndTypes.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/examples/Graph.txt
浏览文件 @
904a8b21
...
...
@@ -494,6 +494,7 @@ JetFile: Graph.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -641,6 +642,7 @@ JetFile: Graph.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -812,6 +814,7 @@ JetFile: Graph.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/examples/PolymorphicClassObjects.txt
浏览文件 @
904a8b21
...
...
@@ -299,6 +299,7 @@ JetFile: PolymorphicClassObjects.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/testData/psi/examples/util/Comparison.txt
浏览文件 @
904a8b21
...
...
@@ -20,12 +20,14 @@ JetFile: Comparison.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
@@ -254,12 +256,14 @@ JetFile: Comparison.jet
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
...
...
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
浏览文件 @
904a8b21
...
...
@@ -274,6 +274,28 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
assertType
(
"for (i in 1) {1}"
,
"Unit"
);
}
public
void
testFunctionLiterals
()
throws
Exception
{
assertType
(
"{() => }"
,
"{() : Unit}"
);
assertType
(
"{() : Int => }"
,
"{() : Int}"
);
assertType
(
"{() => 1}"
,
"{() : Int}"
);
assertType
(
"{(a : Int) => 1}"
,
"{(a : Int) : Int}"
);
assertType
(
"{(a : Int, b : String) => 1}"
,
"{(a : Int, b : String) : Int}"
);
assertType
(
"{(a : Int) => 1}"
,
"{(Int) : Int}"
);
assertType
(
"{(a : Int, b : String) => 1}"
,
"{(Int, String) : Int}"
);
assertType
(
"{Any.() => 1}"
,
"{Any.() : Int}"
);
assertType
(
"{Any.(a : Int) => 1}"
,
"{Any.(a : Int) : Int}"
);
assertType
(
"{Any.(a : Int, b : String) => 1}"
,
"{Any.(a : Int, b : String) : Int}"
);
assertType
(
"{Any.(a : Int) => 1}"
,
"{Any.(Int) : Int}"
);
assertType
(
"{Any.(a : Int, b : String) => 1}"
,
"{Any.(Int, String) : Int}"
);
assertType
(
"{Any.(a : Int, b : String) => b}"
,
"{Any.(Int, String) : String}"
);
}
public
void
testImplicitConversions
()
throws
Exception
{
assertConvertibleTo
(
"1"
,
JetStandardClasses
.
getByteType
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录