Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
225b81f6
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,发现更多精彩内容 >>
提交
225b81f6
编写于
4月 21, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
$field is accessible from constructors
上级
ca579e25
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
55 addition
and
19 deletion
+55
-19
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+50
-19
idea/testData/checker/Properties.jet
idea/testData/checker/Properties.jet
+5
-0
未找到文件。
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
浏览文件 @
225b81f6
package
org.jetbrains.jet.lang.resolve
;
import
com.google.common.collect.ArrayListMultimap
;
import
com.google.common.collect.Multimap
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.JetSemanticServices
;
import
org.jetbrains.jet.lang.cfg.JetControlFlowProcessor
;
...
...
@@ -21,25 +23,38 @@ public class TopDownAnalyzer {
private
final
Map
<
JetDeclaration
,
FunctionDescriptor
>
functions
=
new
LinkedHashMap
<
JetDeclaration
,
FunctionDescriptor
>();
private
final
Map
<
JetProperty
,
PropertyDescriptor
>
properties
=
new
LinkedHashMap
<
JetProperty
,
PropertyDescriptor
>();
private
final
Map
<
JetDeclaration
,
WritableScope
>
declaringScopes
=
new
HashMap
<
JetDeclaration
,
WritableScope
>();
private
final
Multimap
<
DeclarationDescriptor
,
PropertyDescriptor
>
declaringScopesToProperties
=
ArrayListMultimap
.
create
();
private
final
JetSemanticServices
semanticServices
;
private
final
ClassDescriptorResolver
classDescriptorResolver
;
private
final
BindingTrace
trace
;
private
final
BindingTrace
Context
trace
;
private
final
JetControlFlowDataTraceFactory
flowDataTraceFactory
;
private
boolean
readyToProcessExpressions
=
false
;
private
final
BindingTraceAdapter
traceForConstructors
;
public
TopDownAnalyzer
(
JetSemanticServices
semanticServices
,
@NotNull
BindingTrace
bindingTrace
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
public
TopDownAnalyzer
(
JetSemanticServices
semanticServices
,
@NotNull
BindingTrace
Context
bindingTrace
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
this
.
semanticServices
=
semanticServices
;
this
.
classDescriptorResolver
=
new
ClassDescriptorResolver
(
semanticServices
,
bindingTrace
);
this
.
trace
=
bindingTrace
;
this
.
flowDataTraceFactory
=
flowDataTraceFactory
;
this
.
traceForConstructors
=
new
BindingTraceAdapter
(
trace
)
{
@Override
public
void
recordReferenceResolution
(
@NotNull
JetReferenceExpression
expression
,
@NotNull
DeclarationDescriptor
descriptor
)
{
super
.
recordReferenceResolution
(
expression
,
descriptor
);
if
(
expression
instanceof
JetSimpleNameExpression
)
{
JetSimpleNameExpression
simpleNameExpression
=
(
JetSimpleNameExpression
)
expression
;
if
(
simpleNameExpression
.
getReferencedNameElementType
()
==
JetTokens
.
FIELD_IDENTIFIER
)
{
if
(!
trace
.
hasBackingField
((
PropertyDescriptor
)
descriptor
))
{
TopDownAnalyzer
.
this
.
semanticServices
.
getErrorHandler
().
genericError
(
expression
.
getNode
(),
"This property does not have a backing field"
);
}
}
}
}
};
}
public
TopDownAnalyzer
(
JetSemanticServices
semanticServices
,
@NotNull
BindingTrace
bindingTrace
)
{
this
.
semanticServices
=
semanticServices
;
this
.
classDescriptorResolver
=
new
ClassDescriptorResolver
(
semanticServices
,
bindingTrace
);
this
.
trace
=
bindingTrace
;
this
.
flowDataTraceFactory
=
JetControlFlowDataTraceFactory
.
EMPTY
;
public
TopDownAnalyzer
(
JetSemanticServices
semanticServices
,
@NotNull
BindingTraceContext
bindingTrace
)
{
this
(
semanticServices
,
bindingTrace
,
JetControlFlowDataTraceFactory
.
EMPTY
);
}
public
void
process
(
@NotNull
JetScope
outerScope
,
@NotNull
JetDeclaration
declaration
)
{
...
...
@@ -244,6 +259,7 @@ public class TopDownAnalyzer {
declaringScopes
.
put
(
property
,
declaringScope
);
PropertyDescriptor
descriptor
=
classDescriptorResolver
.
resolvePropertyDescriptor
(
declaringScope
.
getContainingDeclaration
(),
declaringScope
,
property
);
declaringScope
.
addVariableDescriptor
(
descriptor
);
declaringScopesToProperties
.
put
(
declaringScope
.
getContainingDeclaration
(),
descriptor
);
properties
.
put
(
property
,
descriptor
);
}
...
...
@@ -254,6 +270,11 @@ public class TopDownAnalyzer {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private
void
resolveBehaviorDeclarationBodies
()
{
resolvePropertyDeclarationBodies
();
resolveFunctionDeclarationBodies
();
}
private
void
resolveFunctionDeclarationBodies
()
{
for
(
Map
.
Entry
<
JetDeclaration
,
FunctionDescriptor
>
entry
:
functions
.
entrySet
())
{
JetDeclaration
declaration
=
entry
.
getKey
();
FunctionDescriptor
descriptor
=
entry
.
getValue
();
...
...
@@ -261,26 +282,36 @@ public class TopDownAnalyzer {
WritableScope
declaringScope
=
declaringScopes
.
get
(
declaration
);
assert
declaringScope
!=
null
;
assert
declaration
instanceof
JetFunction
||
declaration
instanceof
JetConstructor
;
JetDeclarationWithBody
declarationWithBody
=
(
JetDeclarationWithBody
)
declaration
;
JetExpression
bodyExpression
=
declarationWithBody
.
getBodyExpression
();
if
(
declaration
instanceof
JetFunction
)
{
resolveFunctionBody
(
trace
,
(
JetFunction
)
declaration
,
(
FunctionDescriptorImpl
)
descriptor
,
declaringScope
);
}
else
if
(
declaration
instanceof
JetConstructor
)
{
resolveConstructorBody
((
JetConstructor
)
declaration
,
descriptor
,
declaringScope
);
}
else
{
throw
new
UnsupportedOperationException
();
// TODO
}
assert
descriptor
.
getUnsubstitutedReturnType
()
!=
null
;
}
}
private
void
resolveConstructorBody
(
JetConstructor
declaration
,
FunctionDescriptor
descriptor
,
WritableScope
declaringScope
)
{
JetExpression
bodyExpression
=
declaration
.
getBodyExpression
();
if
(
bodyExpression
!=
null
)
{
computeFlowData
(
declaration
,
bodyExpression
);
JetFlowInformationProvider
flowInformationProvider
=
computeFlowData
(
declaration
,
bodyExpression
);
JetTypeInferrer
typeInferrer
=
semanticServices
.
getTypeInferrer
(
trace
,
flowInformationProvider
);
typeInferrer
.
getType
(
FunctionDescriptorUtil
.
getFunctionInnerScope
(
declaringScope
,
descriptor
,
semanticServices
),
bodyExpression
,
true
);
JetTypeInferrer
typeInferrer
=
semanticServices
.
getTypeInferrer
(
traceForConstructors
,
flowInformationProvider
);
WritableScope
constructorScope
=
semanticServices
.
createWritableScope
(
declaringScope
,
declaringScope
.
getContainingDeclaration
());
for
(
PropertyDescriptor
propertyDescriptor
:
declaringScopesToProperties
.
get
(
descriptor
.
getContainingDeclaration
()))
{
constructorScope
.
addPropertyDescriptorByFieldName
(
"$"
+
propertyDescriptor
.
getName
(),
propertyDescriptor
);
}
typeInferrer
.
getType
(
FunctionDescriptorUtil
.
getFunctionInnerScope
(
constructorScope
,
descriptor
,
semanticServices
),
bodyExpression
,
true
);
}
assert
descriptor
.
getUnsubstitutedReturnType
()
!=
null
;
}
private
void
resolvePropertyDeclarationBodies
()
{
for
(
Map
.
Entry
<
JetProperty
,
PropertyDescriptor
>
entry
:
properties
.
entrySet
())
{
JetProperty
declaration
=
entry
.
getKey
();
final
PropertyDescriptor
propertyDescriptor
=
entry
.
getValue
();
...
...
idea/testData/checker/Properties.jet
浏览文件 @
225b81f6
...
...
@@ -14,6 +14,11 @@ class Test {
var b : Int get() = <error>$a</error>; set(x) {a = x; <error>$a</error> = x}
this() {
<error>$b</error> = $a
$a = <error>$b</error>
a = <error>$b</error>
}
fun f() {
<error>$b</error> = <error>$a</error>
a = <error>$b</error>
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录