Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
4c2e58dd
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,发现更多精彩内容 >>
提交
4c2e58dd
编写于
9月 23, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FunctionGroups eliminated
上级
d1fb0c33
变更
33
隐藏空白更改
内联
并排
Showing
33 changed file
with
236 addition
and
403 deletion
+236
-403
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java
...rg/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java
+4
-4
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaClassDescriptor.java
.../jetbrains/jet/lang/resolve/java/JavaClassDescriptor.java
+5
-6
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaClassMembersScope.java
...etbrains/jet/lang/resolve/java/JavaClassMembersScope.java
+4
-3
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
...tbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+4
-3
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java
...org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java
+5
-7
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableMemberDescriptor.java
...brains/jet/lang/descriptors/CallableMemberDescriptor.java
+7
-0
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java
...c/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java
+2
-1
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
...g/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
+6
-11
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
...etbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionGroup.java
...src/org/jetbrains/jet/lang/descriptors/FunctionGroup.java
+0
-45
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/LazySubstitutingClassDescriptor.java
...jet/lang/descriptors/LazySubstitutingClassDescriptor.java
+2
-1
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/LazySubstitutingFunctionGroup.java
...s/jet/lang/descriptors/LazySubstitutingFunctionGroup.java
+0
-54
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
...etbrains/jet/lang/descriptors/MutableClassDescriptor.java
+4
-12
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java
...rg/jetbrains/jet/lang/descriptors/PropertyDescriptor.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/WritableFunctionGroup.java
...jetbrains/jet/lang/descriptors/WritableFunctionGroup.java
+0
-63
compiler/frontend/src/org/jetbrains/jet/lang/resolve/AbstractScopeAdapter.java
.../org/jetbrains/jet/lang/resolve/AbstractScopeAdapter.java
+3
-2
compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
.../src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
+58
-17
compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java
...nd/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java
+7
-7
compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
...rc/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
+9
-9
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java
...c/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java
+5
-5
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/JetScope.java
...d/src/org/jetbrains/jet/lang/resolve/scopes/JetScope.java
+2
-1
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/JetScopeImpl.java
...c/org/jetbrains/jet/lang/resolve/scopes/JetScopeImpl.java
+3
-2
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/SubstitutingScope.java
.../jetbrains/jet/lang/resolve/scopes/SubstitutingScope.java
+45
-45
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java
.../jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java
+10
-36
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeWithImports.java
...ins/jet/lang/resolve/scopes/WritableScopeWithImports.java
+11
-8
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java
.../jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java
+7
-5
compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java
...frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java
+5
-21
compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
.../src/org/jetbrains/jet/lang/types/JetStandardClasses.java
+5
-6
compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
.../src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
+6
-11
compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
.../frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/util/CommonSuppliers.java
.../frontend/src/org/jetbrains/jet/util/CommonSuppliers.java
+6
-2
idea/tests/org/jetbrains/jet/types/JetOverridingTest.java
idea/tests/org/jetbrains/jet/types/JetOverridingTest.java
+2
-2
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
+6
-11
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java
浏览文件 @
4c2e58dd
...
...
@@ -51,7 +51,7 @@ public class IntrinsicMethods {
declareIntrinsicFunction
(
type
,
"dec"
,
0
,
DEC
);
}
final
FunctionGroup
typeInfoFunctionGroup
=
stdlib
.
getTypeInfoFunctionGroup
();
final
Set
<
FunctionDescriptor
>
typeInfoFunctionGroup
=
stdlib
.
getTypeInfoFunctions
();
declareOverload
(
typeInfoFunctionGroup
,
0
,
TYPEINFO
);
declareOverload
(
typeInfoFunctionGroup
,
1
,
VALUE_TYPEINFO
);
...
...
@@ -108,12 +108,12 @@ public class IntrinsicMethods {
private
void
declareIntrinsicFunction
(
String
className
,
String
functionName
,
int
arity
,
IntrinsicMethod
implementation
)
{
JetScope
memberScope
=
getClassMemberScope
(
className
);
final
FunctionGroup
group
=
memberScope
.
getFunctionGroup
(
functionName
);
final
Set
<
FunctionDescriptor
>
group
=
memberScope
.
getFunctions
(
functionName
);
declareOverload
(
group
,
arity
,
implementation
);
}
private
void
declareOverload
(
FunctionGroup
group
,
int
arity
,
IntrinsicMethod
implementation
)
{
for
(
FunctionDescriptor
descriptor
:
group
.
getFunctionDescriptors
()
)
{
private
void
declareOverload
(
Set
<
FunctionDescriptor
>
group
,
int
arity
,
IntrinsicMethod
implementation
)
{
for
(
FunctionDescriptor
descriptor
:
group
)
{
if
(
descriptor
.
getValueParameters
().
size
()
==
arity
)
{
myMethods
.
put
(
descriptor
.
getOriginal
(),
implementation
);
}
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaClassDescriptor.java
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.lang.resolve.java
;
import
com.google.common.collect.Sets
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor
;
...
...
@@ -12,6 +13,7 @@ import org.jetbrains.jet.lang.types.*;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -21,7 +23,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
private
TypeConstructor
typeConstructor
;
private
JavaClassMembersScope
unsubstitutedMemberScope
;
private
JetType
classObjectType
;
private
final
WritableFunctionGroup
constructors
=
new
WritableFunctionGroup
(
"<init>"
);
private
final
Set
<
FunctionDescriptor
>
constructors
=
Sets
.
newLinkedHashSet
(
);
private
Modality
modality
;
private
JetType
superclassType
;
private
final
ClassKind
kind
;
...
...
@@ -60,7 +62,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
}
public
void
addConstructor
(
ConstructorDescriptor
constructorDescriptor
)
{
this
.
constructors
.
add
Function
(
constructorDescriptor
);
this
.
constructors
.
add
(
constructorDescriptor
);
}
private
TypeSubstitutor
createTypeSubstitutor
(
List
<
TypeProjection
>
typeArguments
)
{
...
...
@@ -92,10 +94,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
@NotNull
@Override
public
FunctionGroup
getConstructors
()
{
// assert typeArguments.size() == typeConstructor.getParameters().size();
// if (typeArguments.isEmpty()) return constructors;
// return new LazySubstitutingFunctionGroup(createTypeSubstitutor(typeArguments), constructors);
public
Set
<
FunctionDescriptor
>
getConstructors
()
{
return
constructors
;
}
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaClassMembersScope.java
浏览文件 @
4c2e58dd
...
...
@@ -12,6 +12,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -21,7 +22,7 @@ public class JavaClassMembersScope implements JetScope {
private
final
JavaSemanticServices
semanticServices
;
private
final
boolean
staticMembers
;
private
final
DeclarationDescriptor
containingDeclaration
;
private
final
Map
<
String
,
FunctionGroup
>
functionGroups
=
Maps
.
newHashMap
();
private
final
Map
<
String
,
Set
<
FunctionDescriptor
>
>
functionGroups
=
Maps
.
newHashMap
();
private
final
Map
<
String
,
VariableDescriptor
>
variables
=
Maps
.
newHashMap
();
private
final
Map
<
String
,
ClassifierDescriptor
>
classifiers
=
Maps
.
newHashMap
();
private
Collection
<
DeclarationDescriptor
>
allDescriptors
;
...
...
@@ -130,8 +131,8 @@ public class JavaClassMembersScope implements JetScope {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
FunctionGroup
functionGroup
=
functionGroups
.
get
(
name
);
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
Set
<
FunctionDescriptor
>
functionGroup
=
functionGroups
.
get
(
name
);
if
(
functionGroup
==
null
)
{
functionGroup
=
semanticServices
.
getDescriptorResolver
().
resolveFunctionGroup
(
containingDeclaration
,
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
浏览文件 @
4c2e58dd
...
...
@@ -2,6 +2,7 @@ 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
;
...
...
@@ -302,8 +303,8 @@ public class JavaDescriptorResolver {
}
@NotNull
public
FunctionGroup
resolveFunctionGroup
(
@NotNull
DeclarationDescriptor
owner
,
@NotNull
PsiClass
psiClass
,
@Nullable
ClassDescriptor
classDescriptor
,
@NotNull
String
methodName
,
boolean
staticMembers
)
{
WritableFunctionGroup
writableFunctionGroup
=
new
WritableFunctionGroup
(
methodName
);
public
Set
<
FunctionDescriptor
>
resolveFunctionGroup
(
@NotNull
DeclarationDescriptor
owner
,
@NotNull
PsiClass
psiClass
,
@Nullable
ClassDescriptor
classDescriptor
,
@NotNull
String
methodName
,
boolean
staticMembers
)
{
Set
<
FunctionDescriptor
>
writableFunctionGroup
=
Sets
.
newLinkedHashSet
(
);
final
Collection
<
HierarchicalMethodSignature
>
signatures
=
psiClass
.
getVisibleSignatures
();
TypeSubstitutor
typeSubstitutor
=
createSubstitutorForGenericSupertypes
(
classDescriptor
);
for
(
HierarchicalMethodSignature
signature:
signatures
)
{
...
...
@@ -317,7 +318,7 @@ public class JavaDescriptorResolver {
FunctionDescriptor
substitutedFunctionDescriptor
=
resolveMethodToFunctionDescriptor
(
owner
,
psiClass
,
typeSubstitutor
,
method
);
if
(
substitutedFunctionDescriptor
!=
null
)
{
writableFunctionGroup
.
add
Function
(
substitutedFunctionDescriptor
);
writableFunctionGroup
.
add
(
substitutedFunctionDescriptor
);
}
}
return
writableFunctionGroup
;
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java
浏览文件 @
4c2e58dd
...
...
@@ -4,6 +4,9 @@ import org.jetbrains.annotations.NotNull;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl
;
import
java.util.Collections
;
import
java.util.Set
;
/**
* @author abreslav
*/
...
...
@@ -31,13 +34,8 @@ public class JavaPackageScope extends JetScopeImpl {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
// ClassifierDescriptor classifier = getClassifier(name);
// if (classifier instanceof ClassDescriptor) {
// ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
// return classDescriptor.getConstructors();
// }
return
FunctionGroup
.
EMPTY
;
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
return
Collections
.
emptySet
();
}
@NotNull
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableMemberDescriptor.java
0 → 100644
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.lang.descriptors
;
/**
* @author abreslav
*/
public
interface
CallableMemberDescriptor
extends
CallableDescriptor
,
MemberDescriptor
{
}
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java
浏览文件 @
4c2e58dd
...
...
@@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.types.TypeProjection;
import
org.jetbrains.jet.lang.types.TypeSubstitutor
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -25,7 +26,7 @@ public interface ClassDescriptor extends ClassifierDescriptor {
JetType
getSuperclassType
();
@NotNull
FunctionGroup
getConstructors
();
Set
<
FunctionDescriptor
>
getConstructors
();
@Nullable
ConstructorDescriptor
getUnsubstitutedPrimaryConstructor
();
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
浏览文件 @
4c2e58dd
...
...
@@ -12,6 +12,7 @@ import org.jetbrains.jet.lang.types.*;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -20,7 +21,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
private
TypeConstructor
typeConstructor
;
private
JetScope
memberDeclarations
;
private
FunctionGroup
constructors
;
private
Set
<
FunctionDescriptor
>
constructors
;
private
ConstructorDescriptor
primaryConstructor
;
private
JetType
superclassType
;
private
ReceiverDescriptor
implicitReceiver
;
...
...
@@ -36,7 +37,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
Collection
<
JetType
>
supertypes
,
@NotNull
JetScope
memberDeclarations
,
@NotNull
FunctionGroup
constructors
,
@NotNull
Set
<
FunctionDescriptor
>
constructors
,
@Nullable
ConstructorDescriptor
primaryConstructor
)
{
return
initialize
(
sealed
,
typeParameters
,
supertypes
,
memberDeclarations
,
constructors
,
primaryConstructor
,
getClassType
(
supertypes
));
}
...
...
@@ -45,7 +46,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
Collection
<
JetType
>
supertypes
,
@NotNull
JetScope
memberDeclarations
,
@NotNull
FunctionGroup
constructors
,
@NotNull
Set
<
FunctionDescriptor
>
constructors
,
@Nullable
ConstructorDescriptor
primaryConstructor
,
@Nullable
JetType
superclassType
)
{
this
.
typeConstructor
=
new
TypeConstructorImpl
(
this
,
getAnnotations
(),
sealed
,
getName
(),
typeParameters
,
supertypes
);
...
...
@@ -53,7 +54,6 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
this
.
constructors
=
constructors
;
this
.
primaryConstructor
=
primaryConstructor
;
this
.
superclassType
=
superclassType
;
// assert !constructors.isEmpty() || primaryConstructor == null;
return
this
;
}
...
...
@@ -103,13 +103,8 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
@NotNull
@Override
public
FunctionGroup
getConstructors
()
{
// assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Argument list length mismatch for " + getName();
// if (typeArguments.size() == 0) {
// return constructors;
// }
// Map<TypeConstructor, TypeProjection> substitutionContext = TypeUtils.buildSubstitutionContext(getTypeConstructor().getParameters(), typeArguments);
return
constructors
;
// LazySubstitutingFunctionGroup(TypeSubstitutor.create(substitutionContext), constructors);
public
Set
<
FunctionDescriptor
>
getConstructors
()
{
return
constructors
;
}
@NotNull
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
浏览文件 @
4c2e58dd
...
...
@@ -20,7 +20,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
/**
* @author abreslav
*/
public
class
FunctionDescriptorImpl
extends
DeclarationDescriptorImpl
implements
FunctionDescriptor
{
public
class
FunctionDescriptorImpl
extends
DeclarationDescriptorImpl
implements
FunctionDescriptor
,
CallableMemberDescriptor
{
private
List
<
TypeParameterDescriptor
>
typeParameters
;
private
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
;
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionGroup.java
已删除
100644 → 0
浏览文件 @
d1fb0c33
package
org.jetbrains.jet.lang.descriptors
;
import
org.jetbrains.annotations.NotNull
;
import
java.util.Collections
;
import
java.util.Set
;
/**
* @author abreslav
*/
public
interface
FunctionGroup
extends
Named
{
FunctionGroup
EMPTY
=
new
FunctionGroup
()
{
@NotNull
@Override
public
String
getName
()
{
return
"<empty>"
;
}
@Override
public
boolean
isEmpty
()
{
return
true
;
}
@NotNull
@Override
public
Set
<
FunctionDescriptor
>
getFunctionDescriptors
()
{
return
Collections
.
emptySet
();
}
@Override
public
String
toString
()
{
return
"EMPTY"
;
}
};
@NotNull
@Override
String
getName
();
boolean
isEmpty
();
@NotNull
Set
<
FunctionDescriptor
>
getFunctionDescriptors
();
}
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/LazySubstitutingClassDescriptor.java
浏览文件 @
4c2e58dd
...
...
@@ -10,6 +10,7 @@ import org.jetbrains.jet.lang.types.*;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -103,7 +104,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
@NotNull
@Override
public
FunctionGroup
getConstructors
()
{
public
Set
<
FunctionDescriptor
>
getConstructors
()
{
throw
new
UnsupportedOperationException
();
// TODO
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/LazySubstitutingFunctionGroup.java
已删除
100644 → 0
浏览文件 @
d1fb0c33
package
org.jetbrains.jet.lang.descriptors
;
import
com.google.common.collect.Sets
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.types.TypeSubstitutor
;
import
java.util.Collections
;
import
java.util.Set
;
/**
* @author abreslav
*/
public
class
LazySubstitutingFunctionGroup
implements
FunctionGroup
{
private
final
TypeSubstitutor
substitutor
;
private
final
FunctionGroup
functionGroup
;
private
Set
<
FunctionDescriptor
>
functionDescriptors
;
public
LazySubstitutingFunctionGroup
(
TypeSubstitutor
substitutor
,
FunctionGroup
functionGroup
)
{
this
.
substitutor
=
substitutor
;
this
.
functionGroup
=
functionGroup
;
}
@NotNull
@Override
public
String
getName
()
{
return
functionGroup
.
getName
();
}
@Override
public
boolean
isEmpty
()
{
return
functionGroup
.
isEmpty
();
}
@NotNull
@Override
public
Set
<
FunctionDescriptor
>
getFunctionDescriptors
()
{
if
(
functionDescriptors
==
null
)
{
if
(
substitutor
.
isEmpty
())
{
functionDescriptors
=
functionGroup
.
getFunctionDescriptors
();
}
else
{
Set
<
FunctionDescriptor
>
functionDescriptorSet
=
Sets
.
newLinkedHashSet
();
for
(
FunctionDescriptor
descriptor
:
functionGroup
.
getFunctionDescriptors
())
{
FunctionDescriptor
substitute
=
descriptor
.
substitute
(
substitutor
);
if
(
substitute
!=
null
)
{
functionDescriptorSet
.
add
(
substitute
);
}
}
functionDescriptors
=
Collections
.
unmodifiableSet
(
functionDescriptorSet
);
}
}
return
functionDescriptors
;
}
}
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
浏览文件 @
4c2e58dd
...
...
@@ -22,7 +22,7 @@ import java.util.*;
*/
public
class
MutableClassDescriptor
extends
MutableDeclarationDescriptor
implements
ClassDescriptor
,
NamespaceLike
{
private
ConstructorDescriptor
primaryConstructor
;
private
final
WritableFunctionGroup
constructors
=
new
WritableFunctionGroup
(
"<init>"
);
private
final
Set
<
FunctionDescriptor
>
constructors
=
Sets
.
newLinkedHashSet
(
);
private
final
Set
<
FunctionDescriptor
>
functions
=
Sets
.
newHashSet
();
private
final
Set
<
PropertyDescriptor
>
properties
=
Sets
.
newHashSet
();
private
List
<
TypeParameterDescriptor
>
typeParameters
=
Lists
.
newArrayList
();
...
...
@@ -84,7 +84,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
public
void
addConstructor
(
@NotNull
ConstructorDescriptor
constructorDescriptor
)
{
assert
constructorDescriptor
.
getContainingDeclaration
()
==
this
;
// assert constructorDescriptor.getTypeParameters().size() == getTypeConstructor().getParameters().size();
constructors
.
add
Function
(
constructorDescriptor
);
constructors
.
add
(
constructorDescriptor
);
if
(
defaultType
!=
null
)
{
// constructorDescriptor.getTypeParameters().addAll(typeParameters);
((
ConstructorDescriptorImpl
)
constructorDescriptor
).
setReturnType
(
getDefaultType
());
...
...
@@ -168,7 +168,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
typeParameters
,
supertypes
);
scopeForMemberResolution
.
setImplicitReceiver
(
new
ClassReceiver
(
this
));
for
(
FunctionDescriptor
functionDescriptor
:
constructors
.
getFunctionDescriptors
()
)
{
for
(
FunctionDescriptor
functionDescriptor
:
constructors
)
{
((
ConstructorDescriptorImpl
)
functionDescriptor
).
setReturnType
(
getDefaultType
());
}
}
...
...
@@ -201,15 +201,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
@NotNull
@Override
public
FunctionGroup
getConstructors
()
{
// TODO : Duplicates ClassDescriptorImpl
// assert typeArguments.size() == getTypeConstructor().getParameters().size();
// if (typeArguments.size() == 0) {
// return constructors;
// }
// Map<TypeConstructor, TypeProjection> substitutionContext = TypeUtils.buildSubstitutionContext(getTypeConstructor().getParameters(), typeArguments);
// return new LazySubstitutingFunctionGroup(TypeSubstitutor.create(substitutionContext), constructors);
public
Set
<
FunctionDescriptor
>
getConstructors
()
{
return
constructors
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java
浏览文件 @
4c2e58dd
...
...
@@ -17,7 +17,7 @@ import java.util.Set;
/**
* @author abreslav
*/
public
class
PropertyDescriptor
extends
VariableDescriptorImpl
implements
MemberDescriptor
{
public
class
PropertyDescriptor
extends
VariableDescriptorImpl
implements
Callable
MemberDescriptor
{
private
final
Modality
modality
;
private
final
boolean
isVar
;
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/WritableFunctionGroup.java
已删除
100644 → 0
浏览文件 @
d1fb0c33
package
org.jetbrains.jet.lang.descriptors
;
import
com.google.common.collect.Sets
;
import
org.jetbrains.annotations.NotNull
;
import
java.util.Collections
;
import
java.util.Set
;
/**
* @author abreslav
*/
public
class
WritableFunctionGroup
implements
FunctionGroup
{
private
final
String
name
;
private
Set
<
FunctionDescriptor
>
functionDescriptors
;
private
Set
<
FunctionDescriptor
>
unmodifiableFunctionDescriptors
;
public
WritableFunctionGroup
(
String
name
)
{
this
.
name
=
name
;
}
@NotNull
@Override
public
String
getName
()
{
return
name
;
}
@Override
public
String
toString
()
{
return
"FunctionGroup{"
+
"name='"
+
name
+
'\''
+
'}'
;
}
public
void
addFunction
(
@NotNull
FunctionDescriptor
functionDescriptor
)
{
getWritableFunctionDescriptors
().
add
(
functionDescriptor
);
}
@Override
@NotNull
public
Set
<
FunctionDescriptor
>
getFunctionDescriptors
()
{
if
(
unmodifiableFunctionDescriptors
==
null
)
{
unmodifiableFunctionDescriptors
=
Collections
.
unmodifiableSet
(
getWritableFunctionDescriptors
());
}
return
unmodifiableFunctionDescriptors
;
}
private
Set
<
FunctionDescriptor
>
getWritableFunctionDescriptors
()
{
if
(
functionDescriptors
==
null
)
{
functionDescriptors
=
Sets
.
newLinkedHashSet
();
}
return
functionDescriptors
;
}
@Override
public
boolean
isEmpty
()
{
return
functionDescriptors
==
null
||
functionDescriptors
.
isEmpty
();
}
public
void
addAllFunctions
(
@NotNull
FunctionGroup
functionGroup
)
{
if
(
functionGroup
.
isEmpty
())
return
;
getWritableFunctionDescriptors
().
addAll
(
functionGroup
.
getFunctionDescriptors
());
}
}
compiler/frontend/src/org/jetbrains/jet/lang/resolve/AbstractScopeAdapter.java
浏览文件 @
4c2e58dd
...
...
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -28,8 +29,8 @@ public abstract class AbstractScopeAdapter implements JetScope {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
return
getWorkerScope
().
getFunction
Group
(
name
);
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
return
getWorkerScope
().
getFunction
s
(
name
);
}
@Override
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.lang.resolve
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.psi.PsiElement
;
...
...
@@ -8,7 +9,9 @@ import org.jetbrains.annotations.Nullable;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.lang.types.JetType
;
import
org.jetbrains.jet.lang.types.JetTypeChecker
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
org.jetbrains.jet.util.CommonSuppliers
;
import
java.util.Collection
;
import
java.util.Map
;
...
...
@@ -63,8 +66,8 @@ public class OverrideResolver {
@Nullable
private
FunctionDescriptor
findFunctionOverridableBy
(
@NotNull
FunctionDescriptor
declaredFunction
,
@NotNull
JetType
supertype
)
{
FunctionGroup
functionGroup
=
supertype
.
getMemberScope
().
getFunctionGroup
(
declaredFunction
.
getName
());
for
(
FunctionDescriptor
functionDescriptor
:
functionGroup
.
getFunctionDescriptors
()
)
{
Set
<
FunctionDescriptor
>
functionGroup
=
supertype
.
getMemberScope
().
getFunctions
(
declaredFunction
.
getName
());
for
(
FunctionDescriptor
functionDescriptor
:
functionGroup
)
{
if
(
OverridingUtil
.
isOverridableBy
(
context
.
getSemanticServices
().
getTypeChecker
(),
functionDescriptor
,
declaredFunction
).
isSuccess
())
{
return
functionDescriptor
;
}
...
...
@@ -94,29 +97,67 @@ public class OverrideResolver {
}
protected
void
checkOverridesInAClass
(
MutableClassDescriptor
classDescriptor
,
JetClassOrObject
klass
)
{
Set
<
FunctionDescriptor
>
inheritedFunctions
=
Sets
.
newLinkedHashSet
();
Set
<
PropertyDescriptor
>
inheritedProperties
=
Sets
.
newLinkedHashSet
();
Set
<
CallableMemberDescriptor
>
inheritedFunctions
=
Sets
.
newLinkedHashSet
();
for
(
JetType
supertype
:
classDescriptor
.
getSupertypes
())
{
for
(
DeclarationDescriptor
descriptor
:
supertype
.
getMemberScope
().
getAllDescriptors
())
{
if
(
descriptor
instanceof
FunctionDescriptor
)
{
FunctionDescriptor
functionDescriptor
=
(
FunctionDescriptor
)
descriptor
;
inheritedFunctions
.
add
(
functionDescriptor
);
if
(
descriptor
instanceof
CallableMemberDescriptor
)
{
CallableMemberDescriptor
memberDescriptor
=
(
CallableMemberDescriptor
)
descriptor
;
inheritedFunctions
.
add
(
memberDescriptor
);
}
}
}
Set
<
CallableMemberDescriptor
>
filteredMembers
=
OverridingUtil
.
filterOverrides
(
inheritedFunctions
);
Multimap
<
CallableMemberDescriptor
,
CallableMemberDescriptor
>
factoredMembers
=
CommonSuppliers
.
newLinkedHashSetHashSetMultimap
();
JetTypeChecker
typeChecker
=
context
.
getSemanticServices
().
getTypeChecker
();
for
(
CallableMemberDescriptor
one
:
filteredMembers
)
{
if
(
factoredMembers
.
values
().
contains
(
one
))
continue
;
for
(
CallableMemberDescriptor
another
:
filteredMembers
)
{
if
(
one
==
another
)
continue
;
factoredMembers
.
put
(
one
,
one
);
if
(
OverridingUtil
.
isOverridableBy
(
typeChecker
,
one
,
another
).
isSuccess
()
||
OverridingUtil
.
isOverridableBy
(
typeChecker
,
another
,
one
).
isSuccess
())
{
factoredMembers
.
put
(
one
,
another
);
}
else
if
(
descriptor
instanceof
PropertyDescriptor
)
{
PropertyDescriptor
propertyDescriptor
=
(
PropertyDescriptor
)
descriptor
;
inheritedProperties
.
add
(
propertyDescriptor
);
}
}
Set
<
CallableMemberDescriptor
>
mustBeOverridden
=
Sets
.
newLinkedHashSet
();
for
(
CallableMemberDescriptor
key
:
factoredMembers
.
keySet
())
{
Collection
<
CallableMemberDescriptor
>
mutuallyOverridable
=
factoredMembers
.
get
(
key
);
// System.out.println(key);
// println(mutuallyOverridable);
int
implementationCount
=
0
;
for
(
CallableMemberDescriptor
member
:
mutuallyOverridable
)
{
if
(
member
.
getModality
()
!=
Modality
.
ABSTRACT
)
{
implementationCount
++;
}
}
if
(
implementationCount
!=
1
)
{
mustBeOverridden
.
addAll
(
mutuallyOverridable
);
}
}
Set
<
CallableDescriptor
>
actuallyOverridden
=
Sets
.
newHashSet
();
for
(
FunctionDescriptor
declaredFunction
:
classDescriptor
.
getFunctions
())
{
actuallyOverridden
.
addAll
(
declaredFunction
.
getOverriddenDescriptors
());
}
OverridingUtil
.
filterOverrides
(
inheritedFunctions
);
OverridingUtil
.
filterOverrides
(
inheritedProperties
);
for
(
PropertyDescriptor
declaredProperty
:
classDescriptor
.
getProperties
())
{
actuallyOverridden
.
addAll
(
declaredProperty
.
getOverriddenDescriptors
());
}
// System.out.println(classDescriptor);
// println(inheritedFunctions);
// println(inheritedProperties);
mustBeOverridden
.
removeAll
(
actuallyOverridden
);
System
.
out
.
println
(
classDescriptor
);
println
(
mustBeOverridden
);
System
.
out
.
println
(
"Actually overridden:"
);
println
(
actuallyOverridden
);
for
(
FunctionDescriptor
declaredFunction
:
classDescriptor
.
getFunctions
())
{
checkOverrideForFunction
(
declaredFunction
);
...
...
@@ -160,7 +201,7 @@ public class OverrideResolver {
}
}
private
void
println
(
Set
<?
extends
CallableDescriptor
>
inheritedProperties
)
{
private
void
println
(
Collection
<?
extends
CallableDescriptor
>
inheritedProperties
)
{
for
(
CallableDescriptor
inheritedProperty
:
inheritedProperties
)
{
System
.
out
.
println
(
" "
+
inheritedProperty
);
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java
浏览文件 @
4c2e58dd
...
...
@@ -114,7 +114,6 @@ public class OverridingUtil {
TypeParameterDescriptor
superTypeParameter
=
superTypeParameters
.
get
(
i
);
TypeParameterDescriptor
subTypeParameter
=
subTypeParameters
.
get
(
i
);
if
(!
JetTypeImpl
.
equalTypes
(
superTypeParameter
.
getBoundsAsType
(),
subTypeParameter
.
getBoundsAsType
(),
axioms
))
{
return
OverrideCompatibilityInfo
.
boundsMismatch
(
superTypeParameter
,
subTypeParameter
);
}
...
...
@@ -133,12 +132,13 @@ public class OverridingUtil {
// TODO : Default values, varargs etc
TypeSubstitutor
typeSubstitutor
=
TypeSubstitutor
.
create
(
substitutionContext
);
JetType
substitutedSuperReturnType
=
typeSubstitutor
.
substitute
(
superDescriptor
.
getReturnType
(),
Variance
.
OUT_VARIANCE
);
assert
substitutedSuperReturnType
!=
null
;
if
(!
typeChecker
.
isSubtypeOf
(
subDescriptor
.
getReturnType
(),
substitutedSuperReturnType
))
{
return
OverrideCompatibilityInfo
.
returnTypeMismatch
(
substitutedSuperReturnType
,
subDescriptor
.
getReturnType
());
}
// This code compares return types, but they are not a part of the signature, so this code does not belong here
// TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(substitutionContext);
// JetType substitutedSuperReturnType = typeSubstitutor.substitute(superDescriptor.getReturnType(), Variance.OUT_VARIANCE);
// assert substitutedSuperReturnType != null;
// if (!typeChecker.isSubtypeOf(subDescriptor.getReturnType(), substitutedSuperReturnType)) {
// return OverrideCompatibilityInfo.returnTypeMismatch(substitutedSuperReturnType, subDescriptor.getReturnType());
// }
return
OverrideCompatibilityInfo
.
success
();
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
浏览文件 @
4c2e58dd
...
...
@@ -138,7 +138,7 @@ public class CallResolver {
DeclarationDescriptor
declarationDescriptor
=
constructedType
.
getConstructor
().
getDeclarationDescriptor
();
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
declarationDescriptor
;
Set
<
FunctionDescriptor
>
constructors
=
classDescriptor
.
getConstructors
()
.
getFunctionDescriptors
()
;
Set
<
FunctionDescriptor
>
constructors
=
classDescriptor
.
getConstructors
();
if
(
constructors
.
isEmpty
())
{
// trace.getErrorHandler().genericError(reportAbsenceOn, "This class does not have a constructor");
trace
.
report
(
NO_CONSTRUCTOR
.
on
(
reportAbsenceOn
));
...
...
@@ -159,7 +159,7 @@ public class CallResolver {
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
containingDeclaration
;
Set
<
FunctionDescriptor
>
constructors
=
classDescriptor
.
getConstructors
()
.
getFunctionDescriptors
()
;
Set
<
FunctionDescriptor
>
constructors
=
classDescriptor
.
getConstructors
();
if
(
constructors
.
isEmpty
())
{
// trace.getErrorHandler().genericError(reportAbsenceOn, "This class does not have a constructor");
trace
.
report
(
NO_CONSTRUCTOR
.
on
(
reportAbsenceOn
));
...
...
@@ -630,7 +630,7 @@ public class CallResolver {
private
List
<
FunctionDescriptor
>
findCandidatesByExactSignature
(
JetScope
scope
,
ReceiverDescriptor
receiver
,
String
name
,
List
<
JetType
>
parameterTypes
)
{
List
<
FunctionDescriptor
>
result
=
Lists
.
newArrayList
();
if
(
receiver
!=
NO_RECEIVER
)
{
Set
<
FunctionDescriptor
>
extensionFunctionDescriptors
=
scope
.
getFunction
Group
(
name
).
getFunctionDescriptors
(
);
Set
<
FunctionDescriptor
>
extensionFunctionDescriptors
=
scope
.
getFunction
s
(
name
);
List
<
FunctionDescriptor
>
nonlocal
=
Lists
.
newArrayList
();
List
<
FunctionDescriptor
>
local
=
Lists
.
newArrayList
();
TaskPrioritizer
.
splitLexicallyLocalDescriptors
(
extensionFunctionDescriptors
,
scope
.
getContainingDeclaration
(),
local
,
nonlocal
);
...
...
@@ -640,7 +640,7 @@ public class CallResolver {
return
result
;
}
Set
<
FunctionDescriptor
>
functionDescriptors
=
receiver
.
getType
().
getMemberScope
().
getFunction
Group
(
name
).
getFunctionDescriptors
(
);
Set
<
FunctionDescriptor
>
functionDescriptors
=
receiver
.
getType
().
getMemberScope
().
getFunction
s
(
name
);
if
(
lookupExactSignature
(
functionDescriptors
,
parameterTypes
,
result
))
{
return
result
;
...
...
@@ -649,7 +649,7 @@ public class CallResolver {
return
result
;
}
else
{
lookupExactSignature
(
scope
.
getFunction
Group
(
name
).
getFunctionDescriptors
(
),
parameterTypes
,
result
);
lookupExactSignature
(
scope
.
getFunction
s
(
name
),
parameterTypes
,
result
);
return
result
;
}
}
...
...
@@ -696,7 +696,7 @@ public class CallResolver {
@NotNull
@Override
protected
Collection
<
FunctionDescriptor
>
getNonExtensionsByName
(
JetScope
scope
,
String
name
)
{
Set
<
FunctionDescriptor
>
functions
=
Sets
.
newLinkedHashSet
(
scope
.
getFunction
Group
(
name
).
getFunctionDescriptors
(
));
Set
<
FunctionDescriptor
>
functions
=
Sets
.
newLinkedHashSet
(
scope
.
getFunction
s
(
name
));
for
(
Iterator
<
FunctionDescriptor
>
iterator
=
functions
.
iterator
();
iterator
.
hasNext
();
)
{
FunctionDescriptor
functionDescriptor
=
iterator
.
next
();
if
(
functionDescriptor
.
getReceiver
()
!=
NO_RECEIVER
)
{
...
...
@@ -713,7 +713,7 @@ public class CallResolver {
@Override
protected
Collection
<
FunctionDescriptor
>
getMembersByName
(
@NotNull
ReceiverDescriptor
receiver
,
String
name
)
{
JetScope
receiverScope
=
receiver
.
getType
().
getMemberScope
();
Set
<
FunctionDescriptor
>
members
=
Sets
.
newHashSet
(
receiverScope
.
getFunction
Group
(
name
).
getFunctionDescriptors
(
));
Set
<
FunctionDescriptor
>
members
=
Sets
.
newHashSet
(
receiverScope
.
getFunction
s
(
name
));
addConstructors
(
receiverScope
,
name
,
members
);
addVariableAsFunction
(
receiverScope
,
name
,
members
,
false
);
return
members
;
...
...
@@ -722,7 +722,7 @@ public class CallResolver {
@NotNull
@Override
protected
Collection
<
FunctionDescriptor
>
getExtensionsByName
(
JetScope
scope
,
String
name
)
{
Set
<
FunctionDescriptor
>
extensionFunctions
=
Sets
.
newHashSet
(
scope
.
getFunction
Group
(
name
).
getFunctionDescriptors
(
));
Set
<
FunctionDescriptor
>
extensionFunctions
=
Sets
.
newHashSet
(
scope
.
getFunction
s
(
name
));
for
(
Iterator
<
FunctionDescriptor
>
iterator
=
extensionFunctions
.
iterator
();
iterator
.
hasNext
();
)
{
FunctionDescriptor
descriptor
=
iterator
.
next
();
if
(
descriptor
.
getReceiver
()
==
NO_RECEIVER
)
{
...
...
@@ -743,7 +743,7 @@ public class CallResolver {
ClassifierDescriptor
classifier
=
scope
.
getClassifier
(
name
);
if
(
classifier
instanceof
ClassDescriptor
&&
!
ErrorUtils
.
isError
(
classifier
.
getTypeConstructor
()))
{
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
classifier
;
functions
.
addAll
(
classDescriptor
.
getConstructors
()
.
getFunctionDescriptors
()
);
functions
.
addAll
(
classDescriptor
.
getConstructors
());
}
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.java
浏览文件 @
4c2e58dd
...
...
@@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -56,16 +57,15 @@ public class ChainedScope implements JetScope {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
if
(
scopeChain
.
length
==
0
)
{
return
FunctionGroup
.
EMPTY
;
return
Collections
.
emptySet
()
;
}
WritableFunctionGroup
result
=
new
WritableFunctionGroup
(
name
);
Set
<
FunctionDescriptor
>
result
=
Sets
.
newLinkedHashSet
(
);
for
(
JetScope
jetScope
:
scopeChain
)
{
result
.
addAll
Functions
(
jetScope
.
getFunctionGroup
(
name
));
result
.
addAll
(
jetScope
.
getFunctions
(
name
));
}
return
result
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/JetScope.java
浏览文件 @
4c2e58dd
...
...
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -35,7 +36,7 @@ public interface JetScope {
VariableDescriptor
getVariable
(
@NotNull
String
name
);
@NotNull
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
);
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
);
@NotNull
DeclarationDescriptor
getContainingDeclaration
();
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/JetScopeImpl.java
浏览文件 @
4c2e58dd
...
...
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -35,8 +36,8 @@ public abstract class JetScopeImpl implements JetScope {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
return
FunctionGroup
.
EMPTY
;
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
return
Collections
.
emptySet
()
;
}
@NotNull
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/SubstitutingScope.java
浏览文件 @
4c2e58dd
...
...
@@ -8,9 +8,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import
org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
;
import
org.jetbrains.jet.lang.types.TypeSubstitutor
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
/**
* @author abreslav
...
...
@@ -20,7 +18,7 @@ public class SubstitutingScope implements JetScope {
private
final
JetScope
workerScope
;
private
final
TypeSubstitutor
substitutor
;
private
Map
<
String
,
FunctionGroup
>
functionGroup
s
=
null
;
private
Map
<
DeclarationDescriptor
,
DeclarationDescriptor
>
substitutedDescriptor
s
=
null
;
private
Collection
<
DeclarationDescriptor
>
allDescriptors
=
null
;
public
SubstitutingScope
(
JetScope
workerScope
,
@NotNull
TypeSubstitutor
substitutor
)
{
...
...
@@ -28,26 +26,54 @@ public class SubstitutingScope implements JetScope {
this
.
substitutor
=
substitutor
;
}
@Override
public
VariableDescriptor
getVariable
(
@NotNull
String
name
)
{
VariableDescriptor
variable
=
workerScope
.
getVariable
(
name
);
if
(
variable
==
null
||
substitutor
.
isEmpty
())
{
return
variable
;
@Nullable
private
<
D
extends
DeclarationDescriptor
>
D
substitute
(
@Nullable
D
descriptor
)
{
if
(
descriptor
==
null
)
return
null
;
if
(
substitutor
.
isEmpty
())
return
descriptor
;
if
(
substitutedDescriptors
==
null
)
{
substitutedDescriptors
=
Maps
.
newHashMap
();
}
return
variable
.
substitute
(
substitutor
);
DeclarationDescriptor
substituted
=
substitutedDescriptors
.
get
(
descriptor
);
if
(
substituted
==
null
)
{
substituted
=
descriptor
.
substitute
(
substitutor
);
substitutedDescriptors
.
put
(
descriptor
,
substituted
);
}
//noinspection unchecked
return
(
D
)
substituted
;
}
@NotNull
private
<
D
extends
DeclarationDescriptor
>
Set
<
D
>
substitute
(
@NotNull
Set
<
D
>
descriptors
)
{
if
(
substitutor
.
isEmpty
())
return
descriptors
;
if
(
descriptors
.
isEmpty
())
return
descriptors
;
Set
<
D
>
result
=
Sets
.
newHashSet
();
for
(
D
descriptor
:
descriptors
)
{
D
substitute
=
substitute
(
descriptor
);
if
(
substitute
!=
null
)
{
result
.
add
(
substitute
);
}
}
return
result
;
}
@Override
public
VariableDescriptor
getVariable
(
@NotNull
String
name
)
{
return
substitute
(
workerScope
.
getVariable
(
name
));
}
@Override
public
ClassifierDescriptor
getClassifier
(
@NotNull
String
name
)
{
ClassifierDescriptor
descriptor
=
workerScope
.
getClassifier
(
name
);
if
(
descriptor
==
null
)
{
return
null
;
}
if
(
descriptor
instanceof
ClassDescriptor
)
{
return
new
LazySubstitutingClassDescriptor
((
ClassDescriptor
)
descriptor
,
substitutor
);
}
throw
new
UnsupportedOperationException
();
// TODO
return
substitute
(
workerScope
.
getClassifier
(
name
));
}
@NotNull
@Override
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
return
substitute
(
workerScope
.
getFunctions
(
name
));
}
@Override
...
...
@@ -66,32 +92,6 @@ public class SubstitutingScope implements JetScope {
throw
new
UnsupportedOperationException
();
// TODO
}
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
if
(
substitutor
.
isEmpty
())
{
return
workerScope
.
getFunctionGroup
(
name
);
}
if
(
functionGroups
==
null
)
{
functionGroups
=
Maps
.
newHashMap
();
}
FunctionGroup
cachedGroup
=
functionGroups
.
get
(
name
);
if
(
cachedGroup
!=
null
)
{
return
cachedGroup
;
}
FunctionGroup
functionGroup
=
workerScope
.
getFunctionGroup
(
name
);
FunctionGroup
result
;
if
(
functionGroup
.
isEmpty
())
{
result
=
FunctionGroup
.
EMPTY
;
}
else
{
result
=
new
LazySubstitutingFunctionGroup
(
substitutor
,
functionGroup
);
}
functionGroups
.
put
(
name
,
result
);
return
result
;
}
@NotNull
@Override
public
DeclarationDescriptor
getContainingDeclaration
()
{
...
...
@@ -121,7 +121,7 @@ public class SubstitutingScope implements JetScope {
if
(
allDescriptors
==
null
)
{
allDescriptors
=
Sets
.
newHashSet
();
for
(
DeclarationDescriptor
descriptor
:
workerScope
.
getAllDescriptors
())
{
DeclarationDescriptor
substitute
=
descriptor
.
substitute
(
substitu
tor
);
DeclarationDescriptor
substitute
=
substitute
(
descrip
tor
);
assert
substitute
!=
null
;
allDescriptors
.
add
(
substitute
);
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.lang.resolve.scopes
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.*
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.resolve.DescriptorUtils
;
import
org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
;
import
org.jetbrains.jet.util.CommonSuppliers
;
import
java.util.*
;
...
...
@@ -27,7 +26,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
private
Map
<
String
,
PropertyDescriptor
>
propertyDescriptorsByFieldNames
;
@Nullable
private
Map
<
String
,
WritableFunctionGroup
>
functionGroups
;
private
SetMultimap
<
String
,
FunctionDescriptor
>
functionGroups
;
@Nullable
private
Map
<
String
,
DeclarationDescriptor
>
variableClassOrNamespaceDescriptors
;
...
...
@@ -144,13 +143,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
return
(
VariableDescriptor
)
descriptor
;
}
// if (implicitReceiver != null) {
// VariableDescriptor variable = getImplicitReceiver().getMemberScope().getVariable(name);
// if (variable != null) {
// return variable;
// }
// }
VariableDescriptor
variableDescriptor
=
getWorkerScope
().
getVariable
(
name
);
if
(
variableDescriptor
!=
null
)
{
return
variableDescriptor
;
...
...
@@ -159,45 +151,27 @@ public class WritableScopeImpl extends WritableScopeWithImports {
}
@NotNull
private
Map
<
String
,
WritableFunctionGroup
>
getFunctionGroups
()
{
private
SetMultimap
<
String
,
FunctionDescriptor
>
getFunctionGroups
()
{
if
(
functionGroups
==
null
)
{
functionGroups
=
new
HashMap
<
String
,
WritableFunctionGroup
>
();
functionGroups
=
CommonSuppliers
.
newLinkedHashSetHashSetMultimap
();
}
return
functionGroups
;
}
@Override
public
void
addFunctionDescriptor
(
@NotNull
FunctionDescriptor
functionDescriptor
)
{
String
name
=
functionDescriptor
.
getName
();
Map
<
String
,
WritableFunctionGroup
>
functionGroups
=
getFunctionGroups
();
@Nullable
WritableFunctionGroup
functionGroup
=
functionGroups
.
get
(
name
);
if
(
functionGroup
==
null
)
{
functionGroup
=
new
WritableFunctionGroup
(
name
);
functionGroups
.
put
(
name
,
functionGroup
);
}
functionGroup
.
addFunction
(
functionDescriptor
);
getFunctionGroups
().
put
(
functionDescriptor
.
getName
(),
functionDescriptor
);
allDescriptors
.
add
(
functionDescriptor
);
}
@Override
@NotNull
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
WritableFunctionGroup
result
=
new
WritableFunctionGroup
(
name
);
FunctionGroup
functionGroup
=
getFunctionGroups
().
get
(
name
);
if
(
functionGroup
!=
null
)
{
result
.
addAllFunctions
(
functionGroup
);
}
// if (implicitReceiver != null) {
// result.addAllFunctions(getImplicitReceiver().getMemberScope().getFunctionGroup(name));
// }
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
Set
<
FunctionDescriptor
>
result
=
Sets
.
newLinkedHashSet
(
getFunctionGroups
().
get
(
name
));
result
.
addAll
Functions
(
getWorkerScope
().
getFunctionGroup
(
name
));
result
.
addAll
(
getWorkerScope
().
getFunctions
(
name
));
result
.
addAll
Functions
(
super
.
getFunctionGroup
(
name
));
result
.
addAll
(
super
.
getFunctions
(
name
));
return
result
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeWithImports.java
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.lang.resolve.scopes
;
import
com.google.common.collect.Sets
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
;
import
org.jetbrains.jet.lang.descriptors.FunctionDescriptor
;
import
org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
;
import
org.jetbrains.jet.lang.descriptors.VariableDescriptor
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -58,16 +64,13 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
if
(
getImports
().
isEmpty
())
{
return
FunctionGroup
.
EMPTY
;
return
Collections
.
emptySet
()
;
}
WritableFunctionGroup
result
=
new
WritableFunctionGroup
(
name
);
Set
<
FunctionDescriptor
>
result
=
Sets
.
newLinkedHashSet
(
);
for
(
JetScope
imported
:
getImports
())
{
FunctionGroup
importedFunctions
=
imported
.
getFunctionGroup
(
name
);
if
(!
importedFunctions
.
isEmpty
())
{
result
.
addAllFunctions
(
importedFunctions
);
}
result
.
addAll
(
imported
.
getFunctions
(
name
));
}
return
result
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.lang.resolve.scopes
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
;
import
java.util.Collection
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -46,14 +48,14 @@ public class WriteThroughScope extends WritableScopeWithImports {
@Override
@NotNull
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
WritableFunctionGroup
result
=
new
WritableFunctionGroup
(
name
);
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
Set
<
FunctionDescriptor
>
result
=
Sets
.
newLinkedHashSet
(
);
result
.
addAll
Functions
(
writableWorker
.
getFunctionGroup
(
name
));
result
.
addAll
(
writableWorker
.
getFunctions
(
name
));
result
.
addAll
Functions
(
getWorkerScope
().
getFunctionGroup
(
name
));
result
.
addAll
(
getWorkerScope
().
getFunctions
(
name
));
result
.
addAll
Functions
(
super
.
getFunctionGroup
(
name
));
// Imports
result
.
addAll
(
super
.
getFunctions
(
name
));
// Imports
return
result
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java
浏览文件 @
4c2e58dd
...
...
@@ -43,7 +43,7 @@ public class ErrorUtils {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
return
ERROR_FUNCTION_GROUP
;
}
...
...
@@ -77,33 +77,17 @@ public class ErrorUtils {
};
private
static
final
FunctionGroup
ERROR_FUNCTION_GROUP
=
new
FunctionGroup
()
{
@NotNull
@Override
public
String
getName
()
{
return
"<ERROR FUNCTION>"
;
}
@Override
public
boolean
isEmpty
()
{
return
false
;
}
@NotNull
@Override
public
Set
<
FunctionDescriptor
>
getFunctionDescriptors
()
{
return
Collections
.
singleton
(
createErrorFunction
(
0
,
Collections
.<
JetType
>
emptyList
()));
}
};
private
static
final
ClassDescriptorImpl
ERROR_CLASS
=
new
ClassDescriptorImpl
(
ERROR_MODULE
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
"<ERROR CLASS>"
)
{
@NotNull
@Override
public
FunctionGroup
getConstructors
()
{
public
Set
<
FunctionDescriptor
>
getConstructors
()
{
return
ERROR_FUNCTION_GROUP
;
}
};
private
static
final
Set
<
FunctionDescriptor
>
ERROR_FUNCTION_GROUP
=
Collections
.
singleton
(
createErrorFunction
(
0
,
Collections
.<
JetType
>
emptyList
()));
private
static
final
ConstructorDescriptor
ERROR_CONSTRUCTOR
=
new
ConstructorDescriptorImpl
(
ERROR_CLASS
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
true
);
static
{
ERROR_CLASS
.
initialize
(
true
,
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
Collections
.<
JetType
>
emptyList
(),
getErrorScope
(),
ERROR_FUNCTION_GROUP
,
ERROR_CONSTRUCTOR
);
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
浏览文件 @
4c2e58dd
...
...
@@ -48,7 +48,7 @@ public class JetStandardClasses {
}
},
JetScope
.
EMPTY
,
FunctionGroup
.
EMPTY
,
Collections
.<
FunctionDescriptor
>
emptySet
()
,
null
,
null
);
...
...
@@ -71,7 +71,7 @@ public class JetStandardClasses {
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
Collections
.<
JetType
>
emptySet
(),
JetScope
.
EMPTY
,
FunctionGroup
.
EMPTY
,
Collections
.<
FunctionDescriptor
>
emptySet
()
,
null
,
null
);
...
...
@@ -97,7 +97,6 @@ public class JetStandardClasses {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public
static
final
JetScope
STUB
=
JetScope
.
EMPTY
;
public
static
final
FunctionGroup
STUB_FG
=
FunctionGroup
.
EMPTY
;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -124,7 +123,7 @@ public class JetStandardClasses {
parameters
,
Collections
.
singleton
(
getAnyType
()),
STUB
,
STUB_FG
,
Collections
.<
FunctionDescriptor
>
emptySet
(),
// TODO
null
);
// TODO : constructor
TUPLE_CONSTRUCTORS
.
add
(
TUPLE
[
i
].
getTypeConstructor
());
}
...
...
@@ -149,7 +148,7 @@ public class JetStandardClasses {
FUNCTION
[
i
]
=
function
.
initialize
(
false
,
createTypeParameters
(
i
,
function
),
Collections
.
singleton
(
getAnyType
()),
STUB
,
FunctionGroup
.
EMPTY
,
null
);
Collections
.
singleton
(
getAnyType
()),
STUB
,
Collections
.<
FunctionDescriptor
>
emptySet
()
,
null
);
FUNCTION_TYPE_CONSTRUCTORS
.
add
(
FUNCTION
[
i
].
getTypeConstructor
());
ClassDescriptorImpl
receiverFunction
=
new
ClassDescriptorImpl
(
...
...
@@ -164,7 +163,7 @@ public class JetStandardClasses {
RECEIVER_FUNCTION
[
i
]
=
receiverFunction
.
initialize
(
false
,
parameters
,
Collections
.
singleton
(
getAnyType
()),
STUB
,
FunctionGroup
.
EMPTY
,
null
);
Collections
.
singleton
(
getAnyType
()),
STUB
,
Collections
.<
FunctionDescriptor
>
emptySet
()
,
null
);
RECEIVER_FUNCTION_TYPE_CONSTRUCTORS
.
add
(
RECEIVER_FUNCTION
[
i
].
getTypeConstructor
());
}
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
浏览文件 @
4c2e58dd
...
...
@@ -6,7 +6,7 @@ import com.intellij.psi.PsiFileFactory;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.JetSemanticServices
;
import
org.jetbrains.jet.lang.descriptors.ClassDescriptor
;
import
org.jetbrains.jet.lang.descriptors.Function
Group
;
import
org.jetbrains.jet.lang.descriptors.Function
Descriptor
;
import
org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
;
import
org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor
;
import
org.jetbrains.jet.lang.psi.JetFile
;
...
...
@@ -21,6 +21,7 @@ import java.io.InputStream;
import
java.io.InputStreamReader
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author abreslav
...
...
@@ -60,7 +61,6 @@ public class JetStandardLibrary {
private
final
ClassDescriptor
arrayClass
;
private
final
ClassDescriptor
iterableClass
;
private
final
ClassDescriptor
typeInfoClass
;
private
final
ClassDescriptor
tuple0Class
;
private
final
JetType
byteType
;
private
final
JetType
nullableByteType
;
...
...
@@ -89,7 +89,7 @@ public class JetStandardLibrary {
private
final
JetType
nullableStringType
;
private
final
NamespaceDescriptor
typeInfoNamespace
;
private
final
FunctionGroup
typeInfoFunction
;
private
final
Set
<
FunctionDescriptor
>
typeInfoFunction
;
private
JetStandardLibrary
(
@NotNull
Project
project
)
{
// TODO : review
...
...
@@ -120,10 +120,9 @@ public class JetStandardLibrary {
this
.
stringClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"String"
);
this
.
arrayClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Array"
);
this
.
iterableClass
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Iterable"
);
this
.
tuple0Class
=
(
ClassDescriptor
)
libraryScope
.
getClassifier
(
"Tuple0"
);
typeInfoNamespace
=
libraryScope
.
getNamespace
(
"typeinfo"
);
this
.
typeInfoClass
=
(
ClassDescriptor
)
typeInfoNamespace
.
getMemberScope
().
getClassifier
(
"TypeInfo"
);
typeInfoFunction
=
typeInfoNamespace
.
getMemberScope
().
getFunction
Group
(
"typeinfo"
);
typeInfoFunction
=
typeInfoNamespace
.
getMemberScope
().
getFunction
s
(
"typeinfo"
);
this
.
byteType
=
new
JetTypeImpl
(
getByte
());
this
.
charType
=
new
JetTypeImpl
(
getChar
());
...
...
@@ -134,7 +133,7 @@ public class JetStandardLibrary {
this
.
doubleType
=
new
JetTypeImpl
(
getDouble
());
this
.
booleanType
=
new
JetTypeImpl
(
getBoolean
());
this
.
stringType
=
new
JetTypeImpl
(
getString
());
this
.
tuple0Type
=
new
JetTypeImpl
(
getTuple0
(
));
this
.
tuple0Type
=
new
JetTypeImpl
(
JetStandardClasses
.
getTuple
(
0
));
this
.
nullableByteType
=
TypeUtils
.
makeNullable
(
byteType
);
this
.
nullableCharType
=
TypeUtils
.
makeNullable
(
charType
);
...
...
@@ -210,10 +209,6 @@ public class JetStandardLibrary {
return
iterableClass
;
}
public
ClassDescriptor
getTuple0
()
{
return
tuple0Class
;
}
public
NamespaceDescriptor
getTypeInfoNamespace
()
{
return
typeInfoNamespace
;
}
...
...
@@ -222,7 +217,7 @@ public class JetStandardLibrary {
return
typeInfoClass
;
}
public
FunctionGroup
getTypeInfoFunctionGroup
()
{
public
Set
<
FunctionDescriptor
>
getTypeInfoFunctions
()
{
return
typeInfoFunction
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
浏览文件 @
4c2e58dd
...
...
@@ -237,7 +237,7 @@ public class TypeUtils {
@NotNull
public
static
Multimap
<
TypeConstructor
,
TypeProjection
>
buildDeepSubstitutionMultimap
(
@NotNull
JetType
type
)
{
Multimap
<
TypeConstructor
,
TypeProjection
>
fullSubstitution
=
Multimaps
.
newSetMultimap
(
Maps
.<
TypeConstructor
,
Collection
<
TypeProjection
>>
newHashMap
(),
CommonSuppliers
.<
TypeProjection
>
getLinkedHashSetSupplier
()
);
Multimap
<
TypeConstructor
,
TypeProjection
>
fullSubstitution
=
CommonSuppliers
.
newLinkedHashSetHashSetMultimap
(
);
Map
<
TypeConstructor
,
TypeProjection
>
substitution
=
Maps
.
newHashMap
();
TypeSubstitutor
typeSubstitutor
=
TypeSubstitutor
.
create
(
substitution
);
// we use the mutability of the map here
...
...
compiler/frontend/src/org/jetbrains/jet/util/CommonSuppliers.java
浏览文件 @
4c2e58dd
package
org.jetbrains.jet.util
;
import
com.google.common.base.Supplier
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.*
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -36,4 +36,8 @@ public class CommonSuppliers {
//noinspection unchecked
return
(
Supplier
<
Set
<
T
>>)
LINKED_HASH_SET_SUPPLIER
;
}
public
static
<
K
,
V
>
SetMultimap
<
K
,
V
>
newLinkedHashSetHashSetMultimap
()
{
return
Multimaps
.
newSetMultimap
(
Maps
.<
K
,
Collection
<
V
>>
newHashMap
(),
CommonSuppliers
.<
V
>
getLinkedHashSetSupplier
());
}
}
idea/tests/org/jetbrains/jet/types/JetOverridingTest.java
浏览文件 @
4c2e58dd
...
...
@@ -70,7 +70,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
"fun ab() : Int"
,
"fun a() : Int"
);
assert
Not
Overridable
(
assertOverridable
(
"fun a() : Int"
,
"fun a() : Any"
);
...
...
@@ -98,7 +98,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
"fun a<T1, X : T1>(a : T1) : T1"
,
"fun a<T, Y : T>(a : Y) : T"
);
assert
Not
Overridable
(
assertOverridable
(
"fun a<T1, X : T1>(a : T1) : X"
,
"fun a<T, Y : T>(a : T) : T"
);
...
...
idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
浏览文件 @
4c2e58dd
...
...
@@ -610,18 +610,13 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
@NotNull
@Override
public
FunctionGroup
getFunctionGroup
(
@NotNull
String
name
)
{
WritableFunctionGroup
writableFunctionGroup
=
new
WritableFunctionGroup
(
name
);
// ClassifierDescriptor classifier = getClassifier(name);
// if (classifier instanceof ClassDescriptor) {
// ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
// writableFunctionGroup.addAllFunctions(classDescriptor.getConstructors());
// }
public
Set
<
FunctionDescriptor
>
getFunctions
(
@NotNull
String
name
)
{
Set
<
FunctionDescriptor
>
writableFunctionGroup
=
Sets
.
newLinkedHashSet
();
ModuleDescriptor
module
=
new
ModuleDescriptor
(
"TypeCheckerTest"
);
for
(
String
funDecl
:
FUNCTION_DECLARATIONS
)
{
FunctionDescriptor
functionDescriptor
=
classDescriptorResolver
.
resolveFunctionDescriptor
(
module
,
this
,
JetPsiFactory
.
createFunction
(
getProject
(),
funDecl
));
if
(
name
.
equals
(
functionDescriptor
.
getName
()))
{
writableFunctionGroup
.
add
Function
(
functionDescriptor
);
writableFunctionGroup
.
add
(
functionDescriptor
);
}
}
return
writableFunctionGroup
;
...
...
@@ -690,7 +685,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
});
}
WritableFunctionGroup
constructors
=
new
WritableFunctionGroup
(
"<init>"
);
Set
<
FunctionDescriptor
>
constructors
=
Sets
.
newLinkedHashSet
(
);
classDescriptor
.
initialize
(
!
open
,
typeParameters
,
...
...
@@ -702,12 +697,12 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
for
(
JetConstructor
constructor
:
classElement
.
getSecondaryConstructors
())
{
ConstructorDescriptorImpl
functionDescriptor
=
classDescriptorResolver
.
resolveSecondaryConstructorDescriptor
(
memberDeclarations
,
classDescriptor
,
constructor
);
functionDescriptor
.
setReturnType
(
classDescriptor
.
getDefaultType
());
constructors
.
add
Function
(
functionDescriptor
);
constructors
.
add
(
functionDescriptor
);
}
ConstructorDescriptorImpl
primaryConstructorDescriptor
=
classDescriptorResolver
.
resolvePrimaryConstructorDescriptor
(
scope
,
classDescriptor
,
classElement
);
if
(
primaryConstructorDescriptor
!=
null
)
{
primaryConstructorDescriptor
.
setReturnType
(
classDescriptor
.
getDefaultType
());
constructors
.
add
Function
(
primaryConstructorDescriptor
);
constructors
.
add
(
primaryConstructorDescriptor
);
classDescriptor
.
setPrimaryConstructor
(
primaryConstructorDescriptor
);
}
return
classDescriptor
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录