Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
08c074c5
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,发现更多精彩内容 >>
提交
08c074c5
编写于
5月 03, 2012
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SubstitutionUtils extracted from TypeUtils
上级
d7cb2f24
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
162 addition
and
107 deletion
+162
-107
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
...tbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+2
-6
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
.../jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
+2
-2
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
...g/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
+2
-1
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java
...ains/jet/lang/descriptors/MutableClassDescriptorLite.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
...org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
+3
-5
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java
...tend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java
...d/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java
+138
-0
compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java
...end/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java
+2
-2
compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
.../frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
+8
-86
compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
.../lang/types/expressions/BasicExpressionTypingVisitor.java
+3
-3
未找到文件。
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
浏览文件 @
08c074c5
...
...
@@ -92,11 +92,7 @@ import org.jetbrains.jet.lang.resolve.constants.NullValue;
import
org.jetbrains.jet.lang.resolve.constants.ShortValue
;
import
org.jetbrains.jet.lang.resolve.constants.StringValue
;
import
org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation
;
import
org.jetbrains.jet.lang.types.ErrorUtils
;
import
org.jetbrains.jet.lang.types.JetType
;
import
org.jetbrains.jet.lang.types.TypeSubstitutor
;
import
org.jetbrains.jet.lang.types.TypeUtils
;
import
org.jetbrains.jet.lang.types.Variance
;
import
org.jetbrains.jet.lang.types.*
;
import
org.jetbrains.jet.lang.types.lang.JetStandardClasses
;
import
org.jetbrains.jet.lang.types.lang.JetStandardLibrary
;
import
org.jetbrains.jet.rt.signature.JetSignatureAdapter
;
...
...
@@ -1583,7 +1579,7 @@ public class JavaDescriptorResolver {
private
TypeSubstitutor
createSubstitutorForGenericSupertypes
(
@Nullable
ClassDescriptor
classDescriptor
)
{
TypeSubstitutor
typeSubstitutor
;
if
(
classDescriptor
!=
null
)
{
typeSubstitutor
=
Type
Utils
.
buildDeepSubstitutor
(
classDescriptor
.
getDefaultType
());
typeSubstitutor
=
Substitution
Utils
.
buildDeepSubstitutor
(
classDescriptor
.
getDefaultType
());
}
else
{
typeSubstitutor
=
TypeSubstitutor
.
EMPTY
;
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
浏览文件 @
08c074c5
...
...
@@ -79,7 +79,7 @@ public class JavaTypeTransformer {
@Override
public
TypeProjection
visitWildcardType
(
PsiWildcardType
wildcardType
)
{
if
(!
wildcardType
.
isBounded
())
{
return
Type
Utils
.
makeStarProjection
(
typeParameterDescriptor
);
return
Substitution
Utils
.
makeStarProjection
(
typeParameterDescriptor
);
}
Variance
variance
=
wildcardType
.
isExtends
()
?
Variance
.
OUT_VARIANCE
:
Variance
.
IN_VARIANCE
;
...
...
@@ -174,7 +174,7 @@ public class JavaTypeTransformer {
if
(
classType
.
isRaw
())
{
List
<
TypeParameterDescriptor
>
parameters
=
classData
.
getTypeConstructor
().
getParameters
();
for
(
TypeParameterDescriptor
parameter
:
parameters
)
{
arguments
.
add
(
Type
Utils
.
makeStarProjection
(
parameter
));
arguments
.
add
(
Substitution
Utils
.
makeStarProjection
(
parameter
));
}
}
else
{
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
浏览文件 @
08c074c5
...
...
@@ -97,7 +97,8 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
if
(
typeConstructor
.
getParameters
().
isEmpty
())
{
return
memberDeclarations
;
}
Map
<
TypeConstructor
,
TypeProjection
>
substitutionContext
=
TypeUtils
.
buildSubstitutionContext
(
typeConstructor
.
getParameters
(),
typeArguments
);
Map
<
TypeConstructor
,
TypeProjection
>
substitutionContext
=
SubstitutionUtils
.
buildSubstitutionContext
(
typeConstructor
.
getParameters
(),
typeArguments
);
return
new
SubstitutingScope
(
memberDeclarations
,
TypeSubstitutor
.
create
(
substitutionContext
));
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java
浏览文件 @
08c074c5
...
...
@@ -139,7 +139,7 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
if
(
typeArguments
.
isEmpty
())
return
scopeForMemberLookup
;
List
<
TypeParameterDescriptor
>
typeParameters
=
getTypeConstructor
().
getParameters
();
Map
<
TypeConstructor
,
TypeProjection
>
substitutionContext
=
Type
Utils
.
buildSubstitutionContext
(
typeParameters
,
typeArguments
);
Map
<
TypeConstructor
,
TypeProjection
>
substitutionContext
=
Substitution
Utils
.
buildSubstitutionContext
(
typeParameters
,
typeArguments
);
return
new
SubstitutingScope
(
scopeForMemberLookup
,
TypeSubstitutor
.
create
(
substitutionContext
));
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
浏览文件 @
08c074c5
...
...
@@ -29,10 +29,7 @@ import org.jetbrains.jet.lang.psi.*;
import
org.jetbrains.jet.lang.resolve.scopes.JetScope
;
import
org.jetbrains.jet.lang.resolve.scopes.WritableScope
;
import
org.jetbrains.jet.lang.resolve.scopes.WriteThroughScope
;
import
org.jetbrains.jet.lang.types.JetType
;
import
org.jetbrains.jet.lang.types.TypeConstructor
;
import
org.jetbrains.jet.lang.types.TypeProjection
;
import
org.jetbrains.jet.lang.types.TypeUtils
;
import
org.jetbrains.jet.lang.types.*
;
import
org.jetbrains.jet.lang.types.checker.JetTypeChecker
;
import
org.jetbrains.jet.lexer.JetTokens
;
...
...
@@ -379,7 +376,8 @@ public class TypeHierarchyResolver {
private
void
checkSupertypesForConsistency
()
{
for
(
MutableClassDescriptor
mutableClassDescriptor
:
topologicalOrder
)
{
Multimap
<
TypeConstructor
,
TypeProjection
>
multimap
=
TypeUtils
.
buildDeepSubstitutionMultimap
(
mutableClassDescriptor
.
getDefaultType
());
Multimap
<
TypeConstructor
,
TypeProjection
>
multimap
=
SubstitutionUtils
.
buildDeepSubstitutionMultimap
(
mutableClassDescriptor
.
getDefaultType
());
for
(
Map
.
Entry
<
TypeConstructor
,
Collection
<
TypeProjection
>>
entry
:
multimap
.
asMap
().
entrySet
())
{
Collection
<
TypeProjection
>
projections
=
entry
.
getValue
();
if
(
projections
.
size
()
>
1
)
{
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java
浏览文件 @
08c074c5
...
...
@@ -244,7 +244,7 @@ public class TypeResolver {
List
<
TypeParameterDescriptor
>
parameters
=
constructor
.
getParameters
();
if
(
parameters
.
size
()
>
i
)
{
TypeParameterDescriptor
parameterDescriptor
=
parameters
.
get
(
i
);
arguments
.
add
(
Type
Utils
.
makeStarProjection
(
parameterDescriptor
));
arguments
.
add
(
Substitution
Utils
.
makeStarProjection
(
parameterDescriptor
));
}
else
{
arguments
.
add
(
new
TypeProjection
(
Variance
.
OUT_VARIANCE
,
ErrorUtils
.
createErrorType
(
"*"
)));
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java
0 → 100644
浏览文件 @
08c074c5
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jetbrains.jet.lang.types
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Multimap
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
;
import
org.jetbrains.jet.lang.types.lang.JetStandardClasses
;
import
org.jetbrains.jet.util.CommonSuppliers
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author abreslav
*/
public
class
SubstitutionUtils
{
@NotNull
public
static
Map
<
TypeConstructor
,
TypeProjection
>
buildSubstitutionContext
(
@NotNull
JetType
context
)
{
return
buildSubstitutionContext
(
context
.
getConstructor
().
getParameters
(),
context
.
getArguments
());
}
/**
* Builds a context with all the supertypes' parameters substituted
*/
@NotNull
public
static
TypeSubstitutor
buildDeepSubstitutor
(
@NotNull
JetType
type
)
{
Map
<
TypeConstructor
,
TypeProjection
>
substitution
=
Maps
.
newHashMap
();
TypeSubstitutor
typeSubstitutor
=
TypeSubstitutor
.
create
(
substitution
);
// we use the mutability of the map here
fillInDeepSubstitutor
(
type
,
typeSubstitutor
,
substitution
,
null
);
return
typeSubstitutor
;
}
@NotNull
public
static
Multimap
<
TypeConstructor
,
TypeProjection
>
buildDeepSubstitutionMultimap
(
@NotNull
JetType
type
)
{
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
fillInDeepSubstitutor
(
type
,
typeSubstitutor
,
substitution
,
fullSubstitution
);
return
fullSubstitution
;
}
// we use the mutability of the substitution map here
private
static
void
fillInDeepSubstitutor
(
@NotNull
JetType
context
,
@NotNull
TypeSubstitutor
substitutor
,
@NotNull
Map
<
TypeConstructor
,
TypeProjection
>
substitution
,
@Nullable
Multimap
<
TypeConstructor
,
TypeProjection
>
fullSubstitution
)
{
List
<
TypeParameterDescriptor
>
parameters
=
context
.
getConstructor
().
getParameters
();
List
<
TypeProjection
>
arguments
=
context
.
getArguments
();
if
(
parameters
.
size
()
!=
arguments
.
size
())
{
throw
new
IllegalStateException
();
}
for
(
int
i
=
0
;
i
<
arguments
.
size
();
i
++)
{
TypeProjection
argument
=
arguments
.
get
(
i
);
TypeParameterDescriptor
typeParameterDescriptor
=
parameters
.
get
(
i
);
JetType
substitute
=
substitutor
.
substitute
(
argument
.
getType
(),
Variance
.
INVARIANT
);
assert
substitute
!=
null
;
TypeProjection
substitutedTypeProjection
=
new
TypeProjection
(
argument
.
getProjectionKind
(),
substitute
);
substitution
.
put
(
typeParameterDescriptor
.
getTypeConstructor
(),
substitutedTypeProjection
);
if
(
fullSubstitution
!=
null
)
{
fullSubstitution
.
put
(
typeParameterDescriptor
.
getTypeConstructor
(),
substitutedTypeProjection
);
}
}
if
(
JetStandardClasses
.
isNothingOrNullableNothing
(
context
))
return
;
for
(
JetType
supertype
:
context
.
getConstructor
().
getSupertypes
())
{
fillInDeepSubstitutor
(
supertype
,
substitutor
,
substitution
,
fullSubstitution
);
}
}
@NotNull
public
static
Map
<
TypeConstructor
,
TypeProjection
>
buildSubstitutionContext
(
@NotNull
List
<
TypeParameterDescriptor
>
parameters
,
@NotNull
List
<
TypeProjection
>
contextArguments
)
{
Map
<
TypeConstructor
,
TypeProjection
>
parameterValues
=
new
HashMap
<
TypeConstructor
,
TypeProjection
>();
fillInSubstitutionContext
(
parameters
,
contextArguments
,
parameterValues
);
return
parameterValues
;
}
private
static
void
fillInSubstitutionContext
(
List
<
TypeParameterDescriptor
>
parameters
,
List
<
TypeProjection
>
contextArguments
,
Map
<
TypeConstructor
,
TypeProjection
>
parameterValues
)
{
for
(
int
i
=
0
,
parametersSize
=
parameters
.
size
();
i
<
parametersSize
;
i
++)
{
TypeParameterDescriptor
parameter
=
parameters
.
get
(
i
);
TypeProjection
value
=
contextArguments
.
get
(
i
);
parameterValues
.
put
(
parameter
.
getTypeConstructor
(),
value
);
}
}
@NotNull
public
static
TypeProjection
makeStarProjection
(
@NotNull
TypeParameterDescriptor
parameterDescriptor
)
{
return
new
TypeProjection
(
Variance
.
OUT_VARIANCE
,
parameterDescriptor
.
getUpperBoundsAsType
());
}
public
static
boolean
hasUnsubstitutedTypeParameters
(
JetType
type
)
{
if
(
type
.
getConstructor
().
getDeclarationDescriptor
()
instanceof
TypeParameterDescriptor
)
{
return
true
;
}
for
(
TypeProjection
proj
:
type
.
getArguments
())
{
if
(
hasUnsubstitutedTypeParameters
(
proj
.
getType
()))
{
return
true
;
}
}
return
false
;
}
public
static
void
assertNotImmediatelyRecursive
(
Map
<
TypeConstructor
,
TypeProjection
>
context
)
{
// Make sure we never replace a T with "Foo<T>" or something similar,
// because the substitution will not terminate in this case
// This check is not complete. It does not find cases like
// T -> Foo<T1>
// T -> Bar<T>
for
(
Map
.
Entry
<
TypeConstructor
,
TypeProjection
>
entry
:
context
.
entrySet
())
{
TypeConstructor
key
=
entry
.
getKey
();
TypeProjection
value
=
entry
.
getValue
();
if
(
TypeUtils
.
typeConstructorUsedInType
(
key
,
value
.
getType
()))
{
throw
new
IllegalStateException
(
"Immediately recursive substitution: "
+
context
+
"\nProblematic parameter: "
+
key
+
" -> "
+
value
);
}
}
}
}
compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java
浏览文件 @
08c074c5
...
...
@@ -127,7 +127,7 @@ public class TypeSubstitutor {
}
public
static
TypeSubstitutor
create
(
@NotNull
JetType
context
)
{
return
create
(
Type
Utils
.
buildSubstitutionContext
(
context
));
return
create
(
Substitution
Utils
.
buildSubstitutionContext
(
context
));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -254,7 +254,7 @@ public class TypeSubstitutor {
assert
typeToSubstituteIn
.
getConstructor
().
getDeclarationDescriptor
()
instanceof
TypeParameterDescriptor
;
if
(!
allows
(
parameterVariance
,
passedProjectionKind
))
{
return
Type
Utils
.
makeStarProjection
(
correspondingTypeParameter
);
return
Substitution
Utils
.
makeStarProjection
(
correspondingTypeParameter
);
}
return
substitutionResult
(
correspondingTypeParameter
,
effectiveContextVariance
,
passedProjectionKind
,
projectionValue
,
recursionDepth
+
1
);
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
浏览文件 @
08c074c5
...
...
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.types;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
import
com.intellij.util.Processor
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -36,7 +35,6 @@ import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
import
org.jetbrains.jet.lang.resolve.scopes.JetScope
;
import
org.jetbrains.jet.lang.types.checker.JetTypeChecker
;
import
org.jetbrains.jet.lang.types.lang.JetStandardClasses
;
import
org.jetbrains.jet.util.CommonSuppliers
;
import
java.util.*
;
...
...
@@ -401,80 +399,6 @@ public class TypeUtils {
return
result
;
}
@NotNull
public
static
Map
<
TypeConstructor
,
TypeProjection
>
buildSubstitutionContext
(
@NotNull
JetType
context
)
{
return
buildSubstitutionContext
(
context
.
getConstructor
().
getParameters
(),
context
.
getArguments
());
}
/**
* Builds a context with all the supertypes' parameters substituted
*/
@NotNull
public
static
TypeSubstitutor
buildDeepSubstitutor
(
@NotNull
JetType
type
)
{
Map
<
TypeConstructor
,
TypeProjection
>
substitution
=
Maps
.
newHashMap
();
TypeSubstitutor
typeSubstitutor
=
TypeSubstitutor
.
create
(
substitution
);
// we use the mutability of the map here
fillInDeepSubstitutor
(
type
,
typeSubstitutor
,
substitution
,
null
);
return
typeSubstitutor
;
}
@NotNull
public
static
Multimap
<
TypeConstructor
,
TypeProjection
>
buildDeepSubstitutionMultimap
(
@NotNull
JetType
type
)
{
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
fillInDeepSubstitutor
(
type
,
typeSubstitutor
,
substitution
,
fullSubstitution
);
return
fullSubstitution
;
}
// we use the mutability of the substitution map here
private
static
void
fillInDeepSubstitutor
(
@NotNull
JetType
context
,
@NotNull
TypeSubstitutor
substitutor
,
@NotNull
Map
<
TypeConstructor
,
TypeProjection
>
substitution
,
@Nullable
Multimap
<
TypeConstructor
,
TypeProjection
>
fullSubstitution
)
{
List
<
TypeParameterDescriptor
>
parameters
=
context
.
getConstructor
().
getParameters
();
List
<
TypeProjection
>
arguments
=
context
.
getArguments
();
if
(
parameters
.
size
()
!=
arguments
.
size
())
{
throw
new
IllegalStateException
();
}
for
(
int
i
=
0
;
i
<
arguments
.
size
();
i
++)
{
TypeProjection
argument
=
arguments
.
get
(
i
);
TypeParameterDescriptor
typeParameterDescriptor
=
parameters
.
get
(
i
);
JetType
substitute
=
substitutor
.
substitute
(
argument
.
getType
(),
Variance
.
INVARIANT
);
assert
substitute
!=
null
;
TypeProjection
substitutedTypeProjection
=
new
TypeProjection
(
argument
.
getProjectionKind
(),
substitute
);
substitution
.
put
(
typeParameterDescriptor
.
getTypeConstructor
(),
substitutedTypeProjection
);
if
(
fullSubstitution
!=
null
)
{
fullSubstitution
.
put
(
typeParameterDescriptor
.
getTypeConstructor
(),
substitutedTypeProjection
);
}
}
if
(
JetStandardClasses
.
isNothingOrNullableNothing
(
context
))
return
;
for
(
JetType
supertype
:
context
.
getConstructor
().
getSupertypes
())
{
fillInDeepSubstitutor
(
supertype
,
substitutor
,
substitution
,
fullSubstitution
);
}
}
@NotNull
public
static
Map
<
TypeConstructor
,
TypeProjection
>
buildSubstitutionContext
(
@NotNull
List
<
TypeParameterDescriptor
>
parameters
,
@NotNull
List
<
TypeProjection
>
contextArguments
)
{
Map
<
TypeConstructor
,
TypeProjection
>
parameterValues
=
new
HashMap
<
TypeConstructor
,
TypeProjection
>();
fillInSubstitutionContext
(
parameters
,
contextArguments
,
parameterValues
);
return
parameterValues
;
}
private
static
void
fillInSubstitutionContext
(
List
<
TypeParameterDescriptor
>
parameters
,
List
<
TypeProjection
>
contextArguments
,
Map
<
TypeConstructor
,
TypeProjection
>
parameterValues
)
{
for
(
int
i
=
0
,
parametersSize
=
parameters
.
size
();
i
<
parametersSize
;
i
++)
{
TypeParameterDescriptor
parameter
=
parameters
.
get
(
i
);
TypeProjection
value
=
contextArguments
.
get
(
i
);
parameterValues
.
put
(
parameter
.
getTypeConstructor
(),
value
);
}
}
@NotNull
public
static
TypeProjection
makeStarProjection
(
@NotNull
TypeParameterDescriptor
parameterDescriptor
)
{
return
new
TypeProjection
(
Variance
.
OUT_VARIANCE
,
parameterDescriptor
.
getUpperBoundsAsType
());
}
private
static
void
collectImmediateSupertypes
(
@NotNull
JetType
type
,
@NotNull
Collection
<
JetType
>
result
)
{
TypeSubstitutor
substitutor
=
TypeSubstitutor
.
create
(
type
);
for
(
JetType
supertype
:
type
.
getConstructor
().
getSupertypes
())
{
...
...
@@ -548,21 +472,19 @@ public class TypeUtils {
return
new
ArrayList
<
ClassDescriptor
>(
classDescriptors
);
}
public
static
boolean
hasUnsubstitutedTypeParameters
(
JetType
type
)
{
if
(
type
.
getConstructor
().
getDeclarationDescriptor
()
instanceof
TypeParameterDescriptor
)
{
return
true
;
}
public
static
boolean
equalTypes
(
@NotNull
JetType
a
,
@NotNull
JetType
b
)
{
return
JetTypeChecker
.
INSTANCE
.
isSubtypeOf
(
a
,
b
)
&&
JetTypeChecker
.
INSTANCE
.
isSubtypeOf
(
b
,
a
);
}
for
(
TypeProjection
proj
:
type
.
getArguments
())
{
if
(
hasUnsubstitutedTypeParameters
(
proj
.
getType
()))
{
public
static
boolean
typeConstructorUsedInType
(
@NotNull
TypeConstructor
key
,
@NotNull
JetType
value
)
{
if
(
value
.
getConstructor
()
==
key
)
return
true
;
for
(
TypeProjection
projection
:
value
.
getArguments
())
{
if
(
typeConstructorUsedInType
(
key
,
projection
.
getType
()))
{
return
true
;
}
}
return
false
;
}
public
static
boolean
equalTypes
(
@NotNull
JetType
a
,
@NotNull
JetType
b
)
{
return
JetTypeChecker
.
INSTANCE
.
isSubtypeOf
(
a
,
b
)
&&
JetTypeChecker
.
INSTANCE
.
isSubtypeOf
(
b
,
a
);
}
}
compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
浏览文件 @
08c074c5
...
...
@@ -285,7 +285,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
{
Multimap
<
TypeConstructor
,
TypeProjection
>
typeSubstitutionMap
=
Type
Utils
.
buildDeepSubstitutionMultimap
(
targetType
);
Substitution
Utils
.
buildDeepSubstitutionMultimap
(
targetType
);
for
(
int
i
=
0
;
i
<
actualType
.
getConstructor
().
getParameters
().
size
();
++
i
)
{
TypeProjection
actualTypeParameter
=
actualType
.
getArguments
().
get
(
i
);
...
...
@@ -310,7 +310,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
(
ClassDescriptor
)
targetType
.
getConstructor
().
getDeclarationDescriptor
(),
null
);
Multimap
<
TypeConstructor
,
TypeProjection
>
clearTypeSubstitutionMap
=
Type
Utils
.
buildDeepSubstitutionMultimap
(
targetTypeClerared
);
Substitution
Utils
.
buildDeepSubstitutionMultimap
(
targetTypeClerared
);
Set
<
JetType
>
clearSubstituted
=
new
HashSet
<
JetType
>();
...
...
@@ -332,7 +332,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
// "is List<*>"
if
(
typeProjection
.
equals
(
Type
Utils
.
makeStarProjection
(
typeParameter
)))
{
if
(
typeProjection
.
equals
(
Substitution
Utils
.
makeStarProjection
(
typeParameter
)))
{
continue
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录