Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
7f6440c4
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,发现更多精彩内容 >>
提交
7f6440c4
编写于
5月 10, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactoring of the TopDownAnalyzer in progress
上级
6caaf6ec
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
261 addition
and
129 deletion
+261
-129
idea/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java
...src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java
+16
-0
idea/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java
...tbrains/jet/lang/descriptors/TypeParameterDescriptor.java
+35
-21
idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java
idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java
+0
-2
idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java
idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java
+0
-6
idea/src/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java
...c/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java
+0
-4
idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java
...c/org/jetbrains/jet/lang/resolve/BindingTraceContext.java
+1
-12
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
...g/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
+59
-4
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+131
-51
idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
...tbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+10
-20
idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
.../src/org/jetbrains/jet/lang/types/JetStandardClasses.java
+8
-6
idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
.../src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
+1
-3
未找到文件。
idea/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java
0 → 100644
浏览文件 @
7f6440c4
package
org.jetbrains.jet.lang.descriptors
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
/**
* @author abreslav
*/
public
interface
NamespaceLike
extends
DeclarationDescriptor
{
@Nullable
NamespaceDescriptor
getNamespace
(
String
name
);
void
addNamespace
(
@NotNull
NamespaceDescriptor
namespaceDescriptor
);
void
addClassifierDescriptor
(
MutableClassDescriptor
classDescriptor
);
}
idea/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java
浏览文件 @
7f6440c4
package
org.jetbrains.jet.lang.descriptors
;
import
com.google.common.collect.Sets
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.types.*
;
...
...
@@ -11,22 +12,38 @@ import java.util.Set;
* @author abreslav
*/
public
class
TypeParameterDescriptor
extends
DeclarationDescriptorImpl
implements
ClassifierDescriptor
{
public
static
TypeParameterDescriptor
createWithDefaultBound
(
@NotNull
DeclarationDescriptor
containingDeclaration
,
@NotNull
List
<
Annotation
>
annotations
,
@NotNull
Variance
variance
,
@NotNull
String
name
)
{
TypeParameterDescriptor
typeParameterDescriptor
=
createForFurtherModification
(
containingDeclaration
,
annotations
,
variance
,
name
);
typeParameterDescriptor
.
addUpperBound
(
JetStandardClasses
.
getDefaultBound
());
return
typeParameterDescriptor
;
}
public
static
TypeParameterDescriptor
createForFurtherModification
(
@NotNull
DeclarationDescriptor
containingDeclaration
,
@NotNull
List
<
Annotation
>
annotations
,
@NotNull
Variance
variance
,
@NotNull
String
name
)
{
return
new
TypeParameterDescriptor
(
containingDeclaration
,
annotations
,
variance
,
name
);
}
private
final
Variance
variance
;
private
final
Set
<
JetType
>
upperBounds
;
private
final
TypeConstructor
typeConstructor
;
private
final
JetType
boundsAsType
;
private
JetType
boundsAsType
;
private
JetType
type
;
p
ublic
TypeParameterDescriptor
(
p
rivate
TypeParameterDescriptor
(
@NotNull
DeclarationDescriptor
containingDeclaration
,
@NotNull
List
<
Annotation
>
annotations
,
@NotNull
Variance
variance
,
@NotNull
String
name
,
@NotNull
Set
<
JetType
>
upperBounds
,
@NotNull
JetType
boundsAsType
)
{
@NotNull
String
name
)
{
super
(
containingDeclaration
,
annotations
,
name
);
this
.
variance
=
variance
;
this
.
upperBounds
=
upperBounds
;
this
.
upperBounds
=
Sets
.
newLinkedHashSet
()
;
// TODO: Should we actually pass the annotations on to the type constructor?
this
.
typeConstructor
=
new
TypeConstructorImpl
(
this
,
...
...
@@ -35,27 +52,16 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
"&"
+
name
,
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
upperBounds
);
this
.
boundsAsType
=
boundsAsType
;
}
public
TypeParameterDescriptor
(
@NotNull
DeclarationDescriptor
containingDeclaration
,
@NotNull
List
<
Annotation
>
annotations
,
@NotNull
Variance
variance
,
@NotNull
String
name
)
{
this
(
containingDeclaration
,
annotations
,
variance
,
name
,
Collections
.
singleton
(
JetStandardClasses
.
getNullableAnyType
()),
JetStandardClasses
.
getNullableAnyType
());
}
public
Variance
getVariance
()
{
return
variance
;
}
public
void
addUpperBound
(
@NotNull
JetType
bound
)
{
upperBounds
.
add
(
bound
);
}
public
Set
<
JetType
>
getUpperBounds
()
{
return
upperBounds
;
}
...
...
@@ -73,6 +79,14 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@NotNull
public
JetType
getBoundsAsType
()
{
if
(
boundsAsType
==
null
)
{
assert
upperBounds
!=
null
;
assert
upperBounds
.
size
()
>
0
;
boundsAsType
=
upperBounds
.
size
()
==
1
?
upperBounds
.
iterator
().
next
()
:
TypeUtils
.
intersect
(
JetTypeChecker
.
INSTANCE
,
upperBounds
);
if
(
boundsAsType
==
null
)
{
boundsAsType
=
JetStandardClasses
.
getNothingType
();
// TODO : some error message?
}
}
return
boundsAsType
;
}
...
...
idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java
浏览文件 @
7f6440c4
...
...
@@ -29,8 +29,6 @@ public interface BindingContext {
JetType
getExpressionType
(
JetExpression
expression
);
JetScope
getTopLevelScope
();
DeclarationDescriptor
resolveReferenceExpression
(
JetReferenceExpression
referenceExpression
);
JetType
resolveTypeReference
(
JetTypeReference
typeReference
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/BindingTrace.java
浏览文件 @
7f6440c4
...
...
@@ -39,10 +39,6 @@ public interface BindingTrace {
public
void
recordTypeResolution
(
@NotNull
JetTypeReference
typeReference
,
@NotNull
JetType
type
)
{
}
@Override
public
void
setToplevelScope
(
JetScope
toplevelScope
)
{
}
@Override
public
void
recordBlock
(
JetFunctionLiteralExpression
expression
)
{
}
...
...
@@ -82,8 +78,6 @@ public interface BindingTrace {
public
void
recordTypeResolution
(
@NotNull
JetTypeReference
typeReference
,
@NotNull
JetType
type
);
public
void
setToplevelScope
(
JetScope
toplevelScope
);
public
void
recordBlock
(
JetFunctionLiteralExpression
expression
);
public
void
recordStatement
(
@NotNull
JetElement
statement
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/BindingTraceAdapter.java
浏览文件 @
7f6440c4
...
...
@@ -43,10 +43,6 @@ public class BindingTraceAdapter implements BindingTrace {
originalTrace
.
recordTypeResolution
(
typeReference
,
type
);
}
public
void
setToplevelScope
(
JetScope
toplevelScope
)
{
originalTrace
.
setToplevelScope
(
toplevelScope
);
}
public
void
recordBlock
(
JetFunctionLiteralExpression
expression
)
{
originalTrace
.
recordBlock
(
expression
);
}
...
...
idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java
浏览文件 @
7f6440c4
...
...
@@ -60,8 +60,6 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
}
};
private
JetScope
toplevelScope
;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@NotNull
...
...
@@ -149,11 +147,7 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
statements
.
remove
(
statement
);
}
public
void
setToplevelScope
(
JetScope
toplevelScope
)
{
this
.
toplevelScope
=
toplevelScope
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
...
...
@@ -220,11 +214,6 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
return
resolutionResults
.
get
(
referenceExpression
);
}
@Override
public
JetScope
getTopLevelScope
()
{
return
toplevelScope
;
}
@Override
public
PsiElement
resolveToDeclarationPsiElement
(
JetReferenceExpression
referenceExpression
)
{
DeclarationDescriptor
declarationDescriptor
=
resolveReferenceExpression
(
referenceExpression
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
浏览文件 @
7f6440c4
package
org.jetbrains.jet.lang.resolve
;
import
com.google.common.collect.Lists
;
import
com.intellij.lang.ASTNode
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
...
...
@@ -73,6 +74,61 @@ public class ClassDescriptorResolver {
);
}
public
void
resolveMutableClassDescriptor
(
@NotNull
JetClass
classElement
,
@NotNull
MutableClassDescriptor
descriptor
)
{
descriptor
.
setName
(
JetPsiUtil
.
safeName
(
classElement
.
getName
()));
descriptor
.
getClassHeaderScope
().
addLabeledDeclaration
(
descriptor
);
WritableScope
parameterScope
=
descriptor
.
getClassHeaderScope
();
// TODO : Where-clause
List
<
TypeParameterDescriptor
>
typeParameters
=
Lists
.
newArrayList
();
for
(
JetTypeParameter
typeParameter
:
classElement
.
getTypeParameters
())
{
TypeParameterDescriptor
typeParameterDescriptor
=
TypeParameterDescriptor
.
createForFurtherModification
(
descriptor
,
AnnotationResolver
.
INSTANCE
.
resolveAnnotations
(
typeParameter
.
getModifierList
()),
typeParameter
.
getVariance
(),
JetPsiUtil
.
safeName
(
typeParameter
.
getName
())
);
parameterScope
.
addTypeParameterDescriptor
(
typeParameterDescriptor
);
trace
.
recordDeclarationResolution
(
typeParameter
,
typeParameterDescriptor
);
typeParameters
.
add
(
typeParameterDescriptor
);
}
boolean
open
=
classElement
.
hasModifier
(
JetTokens
.
OPEN_KEYWORD
);
List
<
JetType
>
supertypes
=
new
ArrayList
<
JetType
>();
TypeConstructorImpl
typeConstructor
=
new
TypeConstructorImpl
(
descriptor
,
AnnotationResolver
.
INSTANCE
.
resolveAnnotations
(
classElement
.
getModifierList
()),
!
open
,
JetPsiUtil
.
safeName
(
classElement
.
getName
()),
typeParameters
,
supertypes
);
descriptor
.
setTypeConstructor
(
typeConstructor
);
// List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic
// Collection<? extends JetType> superclasses = delegationSpecifiers.isEmpty()
// ? Collections.singleton(JetStandardClasses.getAnyType())
// : resolveDelegationSpecifiers(parameterScope, delegationSpecifiers);
// TODO : UGLY HACK
// supertypes.addAll(superclasses);
// TODO : importing may be a bad idea
// for (JetType supertype : superclasses) {
// assert supertype != null : classElement.getName();
// parameterScope.importScope(supertype.getMemberScope());
// }
descriptor
.
getClassHeaderScope
().
setThisType
(
descriptor
.
getDefaultType
());
trace
.
recordDeclarationResolution
(
classElement
,
descriptor
);
}
public
void
resolveMutableClassDescriptor
(
@NotNull
JetScope
scope
,
@NotNull
JetClass
classElement
,
@NotNull
MutableClassDescriptor
descriptor
)
{
descriptor
.
setName
(
JetPsiUtil
.
safeName
(
classElement
.
getName
()));
descriptor
.
getClassHeaderScope
().
addLabeledDeclaration
(
descriptor
);
...
...
@@ -249,14 +305,13 @@ public class ClassDescriptorResolver {
JetType
bound
=
extendsBound
==
null
?
JetStandardClasses
.
getDefaultBound
()
:
typeResolver
.
resolveType
(
extensibleScope
,
extendsBound
);
TypeParameterDescriptor
typeParameterDescriptor
=
new
TypeParameterDescriptor
(
TypeParameterDescriptor
typeParameterDescriptor
=
TypeParameterDescriptor
.
createForFurtherModification
(
containingDescriptor
,
AnnotationResolver
.
INSTANCE
.
resolveAnnotations
(
typeParameter
.
getModifierList
()),
typeParameter
.
getVariance
(),
JetPsiUtil
.
safeName
(
typeParameter
.
getName
()),
Collections
.
singleton
(
bound
),
bound
JetPsiUtil
.
safeName
(
typeParameter
.
getName
())
);
typeParameterDescriptor
.
addUpperBound
(
bound
);
extensibleScope
.
addTypeParameterDescriptor
(
typeParameterDescriptor
);
trace
.
recordDeclarationResolution
(
typeParameter
,
typeParameterDescriptor
);
return
typeParameterDescriptor
;
...
...
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
浏览文件 @
7f6440c4
...
...
@@ -24,12 +24,12 @@ import java.util.*;
*/
public
class
TopDownAnalyzer
{
private
final
Map
<
JetClass
,
MutableClassDescriptor
>
classes
=
new
LinkedHashMap
<
JetClass
,
MutableClassDescriptor
>
();
private
final
Map
<
JetClass
,
MutableClassDescriptor
>
classes
=
Maps
.
newLinkedHashMap
();
private
final
Map
<
JetNamespace
,
WritableScope
>
namespaceScopes
=
new
LinkedHashMap
<
JetNamespace
,
WritableScope
>();
private
final
Map
<
JetDeclaration
,
FunctionDescriptorImpl
>
functions
=
Maps
.
newLinkedHashMap
();
private
final
Map
<
JetDeclaration
,
ConstructorDescriptor
>
constructors
=
Maps
.
newLinkedHashMap
();
private
final
Map
<
JetProperty
,
PropertyDescriptor
>
properties
=
new
LinkedHashMap
<
JetProperty
,
PropertyDescriptor
>();
private
final
Map
<
JetDeclaration
,
WritableScope
>
declaringScopes
=
new
HashMap
<
JetDeclaration
,
WritableScope
>
();
private
final
Map
<
JetDeclaration
,
JetScope
>
declaringScopes
=
Maps
.
newHashMap
();
private
final
Multimap
<
DeclarationDescriptor
,
PropertyDescriptor
>
declaringScopesToProperties
=
ArrayListMultimap
.
create
();
private
final
Set
<
PropertyDescriptor
>
primaryConstructorParameterProperties
=
Sets
.
newHashSet
();
...
...
@@ -86,56 +86,137 @@ public class TopDownAnalyzer {
process
(
outerScope
,
Collections
.
singletonList
(
declaration
));
}
public
void
process
(
@NotNull
JetScope
outerScope
,
@NotNull
List
<
JetDeclaration
>
declarations
)
{
final
WritableScope
toplevelScope
=
new
WritableScopeImpl
(
outerScope
,
outerScope
.
getContainingDeclaration
(),
trace
.
getErrorHandler
(),
null
);
// TODO ?!
trace
.
setToplevelScope
(
toplevelScope
);
// TODO : this is a hack
collectTypeDeclarators
(
toplevelScope
,
declarations
);
resolveTypeDeclarations
();
processBehaviorDeclarators
(
toplevelScope
,
declarations
);
readyToProcessExpressions
=
true
;
resolveBehaviorDeclarationBodies
();
}
public
<
T
extends
NamespaceDescriptor
&
NamespaceLike
>
void
process
(
@NotNull
WritableScope
outerScope
,
T
owner
,
@NotNull
List
<
JetDeclaration
>
declarations
)
{
collectNamespacesAndClassifiers
(
outerScope
,
owner
,
declarations
);
// namespaceScopes, classes
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
createTypeConstructors
();
// create type constructors for classes and generic parameters
resolveTypesInClassHeaders
();
// Generic bounds and types in supertype lists (no expressions or constructor resolution)
checkGenericBoundsInClassHeaders
();
// For the types resolved so far
resolveFunctionAndPropertyHeaders
();
// TODO : for now, fail fast if something is unknown yet (i.e. some type annotation is omitted)
resolveExecutableCode
();
}
private
void
collectNamespacesAndClassifiers
(
@NotNull
final
JetScope
outerScope
,
@NotNull
final
NamespaceLike
owner
,
@NotNull
Collection
<
JetDeclaration
>
declarations
)
{
for
(
JetDeclaration
declaration
:
declarations
)
{
declaration
.
accept
(
new
JetVisitor
()
{
@Override
public
void
visitNamespace
(
JetNamespace
namespace
)
{
super
.
visitNamespace
(
namespace
);
// TODO
List
<
JetImportDirective
>
importDirectives
=
namespace
.
getImportDirectives
();
String
name
=
namespace
.
getName
();
if
(
name
==
null
)
{
name
=
"<no name provided>"
;
}
NamespaceDescriptor
namespaceDescriptor
=
owner
.
getNamespace
(
name
);
if
(
namespaceDescriptor
==
null
)
{
namespaceDescriptor
=
new
NamespaceDescriptor
(
owner
,
//declaringScope.getContainingDeclaration(),
Collections
.<
Annotation
>
emptyList
(),
// TODO
name
);
namespaceDescriptor
.
initialize
(
new
WritableScopeImpl
(
JetScope
.
EMPTY
,
namespaceDescriptor
,
trace
.
getErrorHandler
(),
null
));
owner
.
addNamespace
(
namespaceDescriptor
);
trace
.
recordDeclarationResolution
(
namespace
,
namespaceDescriptor
);
}
WritableScope
namespaceScope
=
new
WritableScopeImpl
(
outerScope
,
owner
,
trace
.
getErrorHandler
(),
null
);
namespaceScopes
.
put
(
namespace
,
namespaceScope
);
for
(
JetImportDirective
importDirective
:
importDirectives
)
{
if
(
importDirective
.
isAbsoluteInRootNamespace
())
{
throw
new
UnsupportedOperationException
();
}
if
(
importDirective
.
isAllUnder
())
{
JetExpression
importedReference
=
importDirective
.
getImportedReference
();
if
(
importedReference
!=
null
)
{
JetType
type
=
semanticServices
.
getTypeInferrer
(
trace
,
JetFlowInformationProvider
.
THROW_EXCEPTION
).
getTypeWithNamespaces
(
namespaceScope
,
importedReference
,
false
);
if
(
type
!=
null
)
{
namespaceScope
.
importScope
(
type
.
getMemberScope
());
}
}
}
else
{
throw
new
UnsupportedOperationException
();
}
}
// TODO: !!!
// collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations());
}
@Override
public
void
visitClass
(
JetClass
klass
)
{
super
.
visitClass
(
klass
);
// TODO
MutableClassDescriptor
mutableClassDescriptor
=
new
MutableClassDescriptor
(
trace
,
owner
,
outerScope
);
mutableClassDescriptor
.
setName
(
JetPsiUtil
.
safeName
(
klass
.
getName
()));
owner
.
addClassifierDescriptor
(
mutableClassDescriptor
);
classes
.
put
(
klass
,
mutableClassDescriptor
);
declaringScopes
.
put
(
klass
,
outerScope
);
WritableScope
classScope
=
mutableClassDescriptor
.
getWritableUnsubstitutedMemberScope
();
collectTypeDeclarators
(
classScope
,
klass
.
getDeclarations
());
}
@Override
public
void
visitTypedef
(
JetTypedef
typedef
)
{
super
.
visitTypedef
(
typedef
);
// TODO
trace
.
getErrorHandler
().
genericError
(
typedef
.
getNode
(),
"Unsupported [TopDownAnalyzer]"
);
}
@Override
public
void
visitExtension
(
JetExtension
extension
)
{
super
.
visitExtension
(
extension
);
// TODO
trace
.
getErrorHandler
().
genericError
(
extension
.
getNode
(),
"Unsupported [TopDownAnalyzer]"
);
}
});
}
}
private
void
createTypeConstructors
()
{
for
(
Map
.
Entry
<
JetClass
,
MutableClassDescriptor
>
entry
:
classes
.
entrySet
())
{
JetClass
jetClass
=
entry
.
getKey
();
MutableClassDescriptor
descriptor
=
entry
.
getValue
();
classDescriptorResolver
.
resolveMutableClassDescriptor
(
jetClass
,
descriptor
);
}
}
private
void
resolveTypesInClassHeaders
()
{
throw
new
UnsupportedOperationException
();
// TODO
}
private
void
checkGenericBoundsInClassHeaders
()
{
throw
new
UnsupportedOperationException
();
// TODO
}
private
void
resolveFunctionAndPropertyHeaders
()
{
throw
new
UnsupportedOperationException
();
// TODO
}
private
void
resolveExecutableCode
()
{
throw
new
UnsupportedOperationException
();
// TODO
}
@NotNull
public
JetScope
process
(
@NotNull
JetScope
outerScope
,
@NotNull
List
<
JetDeclaration
>
declarations
)
{
final
WritableScope
toplevelScope
=
new
WritableScopeImpl
(
outerScope
,
outerScope
.
getContainingDeclaration
(),
trace
.
getErrorHandler
(),
null
);
// TODO ?!
collectTypeDeclarators
(
toplevelScope
,
declarations
);
resolveTypeDeclarations
();
processBehaviorDeclarators
(
toplevelScope
,
declarations
);
readyToProcessExpressions
=
true
;
resolveBehaviorDeclarationBodies
();
return
toplevelScope
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private
void
collectTypeDeclarators
(
@NotNull
final
WritableScope
declaringScope
,
List
<
JetDeclaration
>
declarations
)
{
for
(
JetDeclaration
declaration
:
declarations
)
{
declaration
.
accept
(
new
JetVisitor
()
{
@Override
public
void
visitClass
(
JetClass
klass
)
{
WritableScope
classScope
=
processClass
(
declaringScope
,
klass
);
collectTypeDeclarators
(
classScope
,
klass
.
getDeclarations
());
}
@Override
public
void
visitNamespace
(
JetNamespace
namespace
)
{
List
<
JetImportDirective
>
importDirectives
=
namespace
.
getImportDirectives
();
...
...
@@ -179,9 +260,28 @@ public class TopDownAnalyzer {
collectTypeDeclarators
(
namespaceScope
,
namespace
.
getDeclarations
());
}
@Override
public
void
visitClass
(
JetClass
klass
)
{
MutableClassDescriptor
mutableClassDescriptor
=
new
MutableClassDescriptor
(
trace
,
declaringScope
.
getContainingDeclaration
(),
declaringScope
);
mutableClassDescriptor
.
setName
(
JetPsiUtil
.
safeName
(
klass
.
getName
()));
declaringScope
.
addClassifierDescriptor
(
mutableClassDescriptor
);
classes
.
put
(
klass
,
mutableClassDescriptor
);
declaringScopes
.
put
(
klass
,
declaringScope
);
WritableScope
classScope
=
mutableClassDescriptor
.
getWritableUnsubstitutedMemberScope
();
collectTypeDeclarators
(
classScope
,
klass
.
getDeclarations
());
}
@Override
public
void
visitTypedef
(
JetTypedef
typedef
)
{
processTypeDef
(
typedef
);
trace
.
getErrorHandler
().
genericError
(
typedef
.
getNode
(),
"Unsupported [TopDownAnalyzer]"
);
}
@Override
public
void
visitExtension
(
JetExtension
extension
)
{
trace
.
getErrorHandler
().
genericError
(
extension
.
getNode
(),
"Unsupported [TopDownAnalyzer]"
);
}
@Override
...
...
@@ -192,27 +292,7 @@ public class TopDownAnalyzer {
}
}
private
WritableScope
processClass
(
@NotNull
WritableScope
declaringScope
,
JetClass
klass
)
{
MutableClassDescriptor
mutableClassDescriptor
=
new
MutableClassDescriptor
(
trace
,
declaringScope
.
getContainingDeclaration
(),
declaringScope
);
mutableClassDescriptor
.
setName
(
JetPsiUtil
.
safeName
(
klass
.
getName
()));
declaringScope
.
addClassifierDescriptor
(
mutableClassDescriptor
);
classes
.
put
(
klass
,
mutableClassDescriptor
);
declaringScopes
.
put
(
klass
,
declaringScope
);
return
mutableClassDescriptor
.
getWritableUnsubstitutedMemberScope
();
}
private
void
processExtension
(
JetExtension
extension
)
{
throw
new
UnsupportedOperationException
(
extension
.
getText
());
// TODO
}
private
void
processTypeDef
(
@NotNull
JetTypedef
typedef
)
{
throw
new
UnsupportedOperationException
(
typedef
.
getText
());
// TODO
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private
void
resolveTypeDeclarations
()
{
for
(
Map
.
Entry
<
JetClass
,
MutableClassDescriptor
>
entry
:
classes
.
entrySet
())
{
...
...
@@ -494,7 +574,7 @@ public class TopDownAnalyzer {
JetDeclaration
declaration
=
entry
.
getKey
();
ConstructorDescriptor
descriptor
=
entry
.
getValue
();
Writable
Scope
declaringScope
=
declaringScopes
.
get
(
declaration
);
Jet
Scope
declaringScope
=
declaringScopes
.
get
(
declaration
);
assert
declaringScope
!=
null
;
resolveSecondaryConstructorBody
((
JetConstructor
)
declaration
,
descriptor
,
declaringScope
);
...
...
@@ -503,7 +583,7 @@ public class TopDownAnalyzer {
}
}
private
void
resolveSecondaryConstructorBody
(
JetConstructor
declaration
,
final
ConstructorDescriptor
descriptor
,
final
Writable
Scope
declaringScope
)
{
private
void
resolveSecondaryConstructorBody
(
JetConstructor
declaration
,
final
ConstructorDescriptor
descriptor
,
final
Jet
Scope
declaringScope
)
{
final
JetScope
functionInnerScope
=
getInnerScopeForConstructor
(
descriptor
,
declaringScope
);
final
JetTypeInferrer
typeInferrerForInitializers
=
semanticServices
.
getTypeInferrer
(
traceForConstructors
,
JetFlowInformationProvider
.
NONE
);
...
...
@@ -593,7 +673,7 @@ public class TopDownAnalyzer {
final
PropertyDescriptor
propertyDescriptor
=
properties
.
get
(
property
);
assert
propertyDescriptor
!=
null
;
Writable
Scope
declaringScope
=
declaringScopes
.
get
(
property
);
Jet
Scope
declaringScope
=
declaringScopes
.
get
(
property
);
JetExpression
initializer
=
property
.
getInitializer
();
if
(
initializer
!=
null
)
{
...
...
@@ -618,7 +698,7 @@ public class TopDownAnalyzer {
if
(
processed
.
contains
(
property
))
continue
;
final
PropertyDescriptor
propertyDescriptor
=
entry
.
getValue
();
Writable
Scope
declaringScope
=
declaringScopes
.
get
(
property
);
Jet
Scope
declaringScope
=
declaringScopes
.
get
(
property
);
JetExpression
initializer
=
property
.
getInitializer
();
if
(
initializer
!=
null
)
{
...
...
@@ -629,7 +709,7 @@ public class TopDownAnalyzer {
}
}
private
void
resolvePropertyAccessors
(
JetProperty
property
,
PropertyDescriptor
propertyDescriptor
,
Writable
Scope
declaringScope
)
{
private
void
resolvePropertyAccessors
(
JetProperty
property
,
PropertyDescriptor
propertyDescriptor
,
Jet
Scope
declaringScope
)
{
BindingTraceAdapter
fieldAccessTrackingTrace
=
createFieldTrackingTrace
(
propertyDescriptor
);
WritableScope
accessorScope
=
new
WritableScopeImpl
(
declaringScope
,
declaringScope
.
getContainingDeclaration
(),
trace
.
getErrorHandler
(),
null
);
...
...
@@ -698,7 +778,7 @@ public class TopDownAnalyzer {
JetDeclaration
declaration
=
entry
.
getKey
();
FunctionDescriptor
descriptor
=
entry
.
getValue
();
Writable
Scope
declaringScope
=
declaringScopes
.
get
(
declaration
);
Jet
Scope
declaringScope
=
declaringScopes
.
get
(
declaration
);
assert
declaringScope
!=
null
;
resolveFunctionBody
(
traceForMembers
,
(
JetFunction
)
declaration
,
(
FunctionDescriptorImpl
)
descriptor
,
declaringScope
);
...
...
@@ -711,7 +791,7 @@ public class TopDownAnalyzer {
@NotNull
BindingTrace
trace
,
@NotNull
JetDeclarationWithBody
function
,
@NotNull
MutableFunctionDescriptor
functionDescriptor
,
@NotNull
Writable
Scope
declaringScope
)
{
@NotNull
Jet
Scope
declaringScope
)
{
JetExpression
bodyExpression
=
function
.
getBodyExpression
();
if
(
bodyExpression
!=
null
)
{
JetFlowInformationProvider
flowInformationProvider
=
computeFlowData
(
function
.
asElement
(),
bodyExpression
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
浏览文件 @
7f6440c4
...
...
@@ -2,15 +2,12 @@ package org.jetbrains.jet.lang.resolve.java;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.psi.*
;
import
com.intellij.psi.search.GlobalSearchScope
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.descriptors.MutableClassDescriptor
;
import
org.jetbrains.jet.lang.descriptors.WritableFunctionGroup
;
import
org.jetbrains.jet.lang.types.*
;
import
java.util.*
;
...
...
@@ -124,32 +121,25 @@ public class JavaDescriptorResolver {
}
private
TypeParameterDescriptor
createJavaTypeParameterDescriptor
(
@NotNull
DeclarationDescriptor
owner
,
@NotNull
PsiTypeParameter
typeParameter
)
{
TypeParameterDescriptor
typeParameterDescriptor
=
TypeParameterDescriptor
.
createForFurtherModification
(
owner
,
Collections
.<
Annotation
>
emptyList
(),
// TODO
Variance
.
INVARIANT
,
typeParameter
.
getName
()
);
PsiClassType
[]
referencedTypes
=
typeParameter
.
getExtendsList
().
getReferencedTypes
();
Set
<
JetType
>
upperBounds
;
JetType
boundsAsType
;
if
(
referencedTypes
.
length
==
0
){
boundsAsType
=
JetStandardClasses
.
getNullableAnyType
();
upperBounds
=
Collections
.
singleton
(
boundsAsType
);
typeParameterDescriptor
.
addUpperBound
(
JetStandardClasses
.
getNullableAnyType
());
}
else
if
(
referencedTypes
.
length
==
1
)
{
boundsAsType
=
semanticServices
.
getTypeTransformer
().
transformToType
(
referencedTypes
[
0
]);
upperBounds
=
Collections
.
singleton
(
boundsAsType
);
typeParameterDescriptor
.
addUpperBound
(
semanticServices
.
getTypeTransformer
().
transformToType
(
referencedTypes
[
0
]));
}
else
{
upperBounds
=
Sets
.
newLinkedHashSet
();
for
(
PsiClassType
referencedType
:
referencedTypes
)
{
upperBounds
.
ad
d
(
semanticServices
.
getTypeTransformer
().
transformToType
(
referencedType
));
typeParameterDescriptor
.
addUpperBoun
d
(
semanticServices
.
getTypeTransformer
().
transformToType
(
referencedType
));
}
boundsAsType
=
TypeUtils
.
safeIntersect
(
semanticServices
.
getJetSemanticServices
().
getTypeChecker
(),
upperBounds
);
}
return
new
TypeParameterDescriptor
(
owner
,
Collections
.<
Annotation
>
emptyList
(),
// TODO
Variance
.
INVARIANT
,
typeParameter
.
getName
(),
upperBounds
,
boundsAsType
);
return
typeParameterDescriptor
;
}
@NotNull
...
...
idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
浏览文件 @
7f6440c4
...
...
@@ -77,6 +77,10 @@ public class JetStandardClasses {
private
static
final
JetType
ANY_TYPE
=
new
JetTypeImpl
(
ANY
.
getTypeConstructor
(),
JetScope
.
EMPTY
);
private
static
final
JetType
NULLABLE_ANY_TYPE
=
TypeUtils
.
makeNullable
(
ANY_TYPE
);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private
static
final
JetType
DEFAULT_BOUND
=
getNullableAnyType
();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public
static
final
JetScope
STUB
=
JetScope
.
EMPTY
;
...
...
@@ -95,7 +99,7 @@ public class JetStandardClasses {
Collections
.<
Annotation
>
emptyList
(),
"Tuple"
+
i
);
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
parameters
.
add
(
new
TypeParameterDescriptor
(
parameters
.
add
(
TypeParameterDescriptor
.
createWithDefaultBound
(
classDescriptor
,
Collections
.<
Annotation
>
emptyList
(),
Variance
.
OUT_VARIANCE
,
"T"
+
j
));
...
...
@@ -133,7 +137,7 @@ public class JetStandardClasses {
Collections
.<
Annotation
>
emptyList
(),
"ReceiverFunction"
+
i
);
List
<
TypeParameterDescriptor
>
parameters
=
createTypeParameters
(
i
,
receiverFunction
);
parameters
.
add
(
0
,
new
TypeParameterDescriptor
(
parameters
.
add
(
0
,
TypeParameterDescriptor
.
createWithDefaultBound
(
receiverFunction
,
Collections
.<
Annotation
>
emptyList
(),
Variance
.
IN_VARIANCE
,
"T"
));
...
...
@@ -147,12 +151,12 @@ public class JetStandardClasses {
private
static
List
<
TypeParameterDescriptor
>
createTypeParameters
(
int
parameterCount
,
ClassDescriptorImpl
function
)
{
List
<
TypeParameterDescriptor
>
parameters
=
new
ArrayList
<
TypeParameterDescriptor
>();
for
(
int
j
=
0
;
j
<
parameterCount
;
j
++)
{
parameters
.
add
(
new
TypeParameterDescriptor
(
parameters
.
add
(
TypeParameterDescriptor
.
createWithDefaultBound
(
function
,
Collections
.<
Annotation
>
emptyList
(),
Variance
.
IN_VARIANCE
,
"P"
+
j
));
}
parameters
.
add
(
new
TypeParameterDescriptor
(
parameters
.
add
(
TypeParameterDescriptor
.
createWithDefaultBound
(
function
,
Collections
.<
Annotation
>
emptyList
(),
Variance
.
OUT_VARIANCE
,
"R"
));
...
...
@@ -199,8 +203,6 @@ public class JetStandardClasses {
}
}
private
static
final
JetType
DEFAULT_BOUND
=
getNullableAnyType
();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@NotNull
...
...
idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
浏览文件 @
7f6440c4
...
...
@@ -73,9 +73,7 @@ public class JetStandardLibrary {
JetSemanticServices
bootstrappingSemanticServices
=
JetSemanticServices
.
createSemanticServices
(
this
);
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
TopDownAnalyzer
bootstrappingTDA
=
new
TopDownAnalyzer
(
bootstrappingSemanticServices
,
bindingTraceContext
);
bootstrappingTDA
.
process
(
JetStandardClasses
.
STANDARD_CLASSES
,
file
.
getRootNamespace
().
getDeclarations
());
this
.
libraryScope
=
bindingTraceContext
.
getTopLevelScope
();
this
.
libraryScope
=
bootstrappingTDA
.
process
(
JetStandardClasses
.
STANDARD_CLASSES
,
file
.
getRootNamespace
().
getDeclarations
());
this
.
byteClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Byte"
);
this
.
charClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Char"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录