Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
87b22e81
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,发现更多精彩内容 >>
提交
87b22e81
编写于
9月 26, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JAVA_ROOT eliminated. Proper parents for everything except generic parameters of functions
上级
292fe08b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
147 addition
and
44 deletion
+147
-44
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaClassMembersScope.java
...etbrains/jet/lang/resolve/java/JavaClassMembersScope.java
+12
-7
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
...tbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+83
-22
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
.../jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java
...rains/jet/lang/descriptors/DeclarationDescriptorImpl.java
+1
-1
idea/testData/checkerWithErrorTypes/quick/Override.jet
idea/testData/checkerWithErrorTypes/quick/Override.jet
+50
-13
未找到文件。
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaClassMembersScope.java
浏览文件 @
87b22e81
...
...
@@ -71,13 +71,7 @@ public class JavaClassMembersScope implements JetScope {
public
Collection
<
DeclarationDescriptor
>
getAllDescriptors
()
{
if
(
allDescriptors
==
null
)
{
allDescriptors
=
Sets
.
newHashSet
();
TypeSubstitutor
substitutorForGenericSupertypes
;
if
(
containingDeclaration
instanceof
ClassDescriptor
)
{
substitutorForGenericSupertypes
=
semanticServices
.
getDescriptorResolver
().
createSubstitutorForGenericSupertypes
((
ClassDescriptor
)
containingDeclaration
);
}
else
{
substitutorForGenericSupertypes
=
TypeSubstitutor
.
EMPTY
;
}
TypeSubstitutor
substitutorForGenericSupertypes
=
getTypeSubstitutorForSupertypes
();
for
(
HierarchicalMethodSignature
signature
:
psiClass
.
getVisibleSignatures
())
{
PsiMethod
method
=
signature
.
getMethod
();
...
...
@@ -98,6 +92,17 @@ public class JavaClassMembersScope implements JetScope {
return
allDescriptors
;
}
private
TypeSubstitutor
getTypeSubstitutorForSupertypes
()
{
TypeSubstitutor
substitutorForGenericSupertypes
;
if
(
containingDeclaration
instanceof
ClassDescriptor
)
{
substitutorForGenericSupertypes
=
semanticServices
.
getDescriptorResolver
().
createSubstitutorForGenericSupertypes
((
ClassDescriptor
)
containingDeclaration
);
}
else
{
substitutorForGenericSupertypes
=
TypeSubstitutor
.
EMPTY
;
}
return
substitutorForGenericSupertypes
;
}
private
ClassifierDescriptor
doGetClassifierDescriptor
(
String
name
)
{
// TODO : suboptimal, walk the list only once
for
(
PsiClass
innerClass
:
psiClass
.
getAllInnerClasses
())
{
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
浏览文件 @
87b22e81
...
...
@@ -21,11 +21,11 @@ import java.util.*;
*/
public
class
JavaDescriptorResolver
{
/*package*/
static
final
DeclarationDescriptor
JAVA_
ROOT
=
new
DeclarationDescriptorImpl
(
null
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
"<java_root
>"
)
{
@NotNull
/*package*/
static
final
DeclarationDescriptor
JAVA_
METHOD_TYPE_PARAMETER_PARENT
=
new
DeclarationDescriptorImpl
(
null
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
"<java_generic_method
>"
)
{
@Override
public
DeclarationDescriptor
substitute
(
TypeSubstitutor
substitutor
)
{
throw
new
UnsupportedOperationException
();
// TODO
throw
new
UnsupportedOperationException
();
}
@Override
...
...
@@ -38,7 +38,7 @@ public class JavaDescriptorResolver {
@NotNull
@Override
public
DeclarationDescriptor
substitute
(
TypeSubstitutor
substitutor
)
{
throw
new
UnsupportedOperationException
();
// TODO
throw
new
UnsupportedOperationException
();
}
@Override
...
...
@@ -51,7 +51,7 @@ public class JavaDescriptorResolver {
protected
final
Map
<
PsiTypeParameter
,
TypeParameterDescriptor
>
typeParameterDescriptorCache
=
Maps
.
newHashMap
();
protected
final
Map
<
PsiMethod
,
FunctionDescriptor
>
methodDescriptorCache
=
Maps
.
newHashMap
();
protected
final
Map
<
PsiField
,
VariableDescriptor
>
fieldDescriptorCache
=
Maps
.
newHashMap
();
protected
final
Map
<
String
,
NamespaceDescriptor
>
namespaceDescriptorCache
=
new
HashMap
<
String
,
NamespaceDescriptor
>
();
protected
final
Map
<
PsiPackage
,
NamespaceDescriptor
>
namespaceDescriptorCache
=
Maps
.
newHashMap
();
protected
final
JavaPsiFacade
javaFacade
;
protected
final
GlobalSearchScope
javaSearchScope
;
protected
final
JavaSemanticServices
semanticServices
;
...
...
@@ -92,7 +92,7 @@ public class JavaDescriptorResolver {
String
name
=
psiClass
.
getName
();
JavaClassDescriptor
classDescriptor
=
new
JavaClassDescriptor
(
JAVA_ROOT
,
psiClass
.
isInterface
()
?
ClassKind
.
TRAIT
:
ClassKind
.
CLASS
resolveParentDescriptor
(
psiClass
)
,
psiClass
.
isInterface
()
?
ClassKind
.
TRAIT
:
ClassKind
.
CLASS
);
classDescriptor
.
setName
(
name
);
...
...
@@ -163,6 +163,17 @@ public class JavaDescriptorResolver {
return
classDescriptor
;
}
private
DeclarationDescriptor
resolveParentDescriptor
(
PsiClass
psiClass
)
{
PsiClass
containingClass
=
psiClass
.
getContainingClass
();
if
(
containingClass
!=
null
)
{
return
resolveClass
(
psiClass
);
}
PsiJavaFile
containingFile
=
(
PsiJavaFile
)
psiClass
.
getContainingFile
();
String
packageName
=
containingFile
.
getPackageName
();
return
resolveNamespace
(
packageName
);
}
private
List
<
TypeParameterDescriptor
>
resolveTypeParameters
(
@NotNull
DeclarationDescriptor
containingDeclaration
,
@NotNull
PsiTypeParameter
[]
typeParameters
)
{
List
<
TypeParameterDescriptor
>
result
=
Lists
.
newArrayList
();
for
(
PsiTypeParameter
typeParameter
:
typeParameters
)
{
...
...
@@ -223,7 +234,15 @@ public class JavaDescriptorResolver {
}
public
NamespaceDescriptor
resolveNamespace
(
String
qualifiedName
)
{
NamespaceDescriptor
namespaceDescriptor
=
namespaceDescriptorCache
.
get
(
qualifiedName
);
PsiPackage
psiPackage
=
javaFacade
.
findPackage
(
qualifiedName
);
if
(
psiPackage
==
null
)
{
return
null
;
}
return
resolveNamespace
(
psiPackage
);
}
private
NamespaceDescriptor
resolveNamespace
(
@NotNull
PsiPackage
psiPackage
)
{
NamespaceDescriptor
namespaceDescriptor
=
namespaceDescriptorCache
.
get
(
psiPackage
);
if
(
namespaceDescriptor
==
null
)
{
// TODO : packages
...
...
@@ -232,31 +251,37 @@ public class JavaDescriptorResolver {
// namespaceDescriptor = createJavaNamespaceDescriptor(psiClass);
// }
// else {
PsiPackage
psiPackage
=
javaFacade
.
findPackage
(
qualifiedName
);
if
(
psiPackage
==
null
)
{
return
null
;
}
namespaceDescriptor
=
createJavaNamespaceDescriptor
(
psiPackage
);
// }
namespaceDescriptorCache
.
put
(
qualifiedNam
e
,
namespaceDescriptor
);
namespaceDescriptorCache
.
put
(
psiPackag
e
,
namespaceDescriptor
);
}
return
namespaceDescriptor
;
}
private
NamespaceDescriptor
createJavaNamespaceDescriptor
(
PsiPackage
psiPackage
)
{
private
NamespaceDescriptor
createJavaNamespaceDescriptor
(
@NotNull
PsiPackage
psiPackage
)
{
String
name
=
psiPackage
.
getName
();
JavaNamespaceDescriptor
namespaceDescriptor
=
new
JavaNamespaceDescriptor
(
JAVA_ROOT
,
resolveParentDescriptor
(
psiPackage
)
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
// TODO
psiPackage
.
getName
()
name
==
null
?
"<java_root>"
:
name
);
namespaceDescriptor
.
setMemberScope
(
new
JavaPackageScope
(
psiPackage
.
getQualifiedName
(),
namespaceDescriptor
,
semanticServices
));
semanticServices
.
getTrace
().
record
(
BindingContext
.
NAMESPACE
,
psiPackage
,
namespaceDescriptor
);
return
namespaceDescriptor
;
}
private
DeclarationDescriptor
resolveParentDescriptor
(
@NotNull
PsiPackage
psiPackage
)
{
PsiPackage
parentPackage
=
psiPackage
.
getParentPackage
();
if
(
parentPackage
==
null
)
{
return
null
;
}
return
resolveNamespace
(
parentPackage
);
}
private
NamespaceDescriptor
createJavaNamespaceDescriptor
(
@NotNull
final
PsiClass
psiClass
)
{
JavaNamespaceDescriptor
namespaceDescriptor
=
new
JavaNamespaceDescriptor
(
JAVA_ROOT
,
resolveParentDescriptor
(
psiClass
)
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
// TODO
psiClass
.
getName
()
);
...
...
@@ -312,15 +337,11 @@ public class JavaDescriptorResolver {
final
Collection
<
HierarchicalMethodSignature
>
signatures
=
psiClass
.
getVisibleSignatures
();
TypeSubstitutor
typeSubstitutor
=
createSubstitutorForGenericSupertypes
(
classDescriptor
);
for
(
HierarchicalMethodSignature
signature:
signatures
)
{
PsiMethod
method
=
signature
.
getMethod
();
if
(
method
.
hasModifierProperty
(
PsiModifier
.
STATIC
)
!=
staticMembers
)
{
continue
;
}
if
(!
methodName
.
equals
(
method
.
getName
()))
{
if
(!
methodName
.
equals
(
signature
.
getName
()))
{
continue
;
}
FunctionDescriptor
substitutedFunctionDescriptor
=
resolve
MethodToFunctionDescriptor
(
owner
,
psiClass
,
typeSubstitutor
,
method
);
FunctionDescriptor
substitutedFunctionDescriptor
=
resolve
HierarchicalSignatureToFunction
(
owner
,
psiClass
,
staticMembers
,
typeSubstitutor
,
signature
);
if
(
substitutedFunctionDescriptor
!=
null
)
{
writableFunctionGroup
.
add
(
substitutedFunctionDescriptor
);
}
...
...
@@ -328,6 +349,21 @@ public class JavaDescriptorResolver {
return
writableFunctionGroup
;
}
@Nullable
private
FunctionDescriptor
resolveHierarchicalSignatureToFunction
(
DeclarationDescriptor
owner
,
PsiClass
psiClass
,
boolean
staticMembers
,
TypeSubstitutor
typeSubstitutor
,
HierarchicalMethodSignature
signature
)
{
PsiMethod
method
=
signature
.
getMethod
();
if
(
method
.
hasModifierProperty
(
PsiModifier
.
STATIC
)
!=
staticMembers
)
{
return
null
;
}
FunctionDescriptor
functionDescriptor
=
resolveMethodToFunctionDescriptor
(
owner
,
psiClass
,
typeSubstitutor
,
method
);
// if (functionDescriptor != null && !staticMembers) {
// for (HierarchicalMethodSignature superSignature : signature.getSuperSignatures()) {
// ((FunctionDescriptorImpl) functionDescriptor).addOverriddenFunction(resolveHierarchicalSignatureToFunction(owner, superSignature.getMethod().getContainingClass(), false, typeSubstitutor, superSignature));
// }
// }
return
functionDescriptor
;
}
public
TypeSubstitutor
createSubstitutorForGenericSupertypes
(
ClassDescriptor
classDescriptor
)
{
TypeSubstitutor
typeSubstitutor
;
if
(
classDescriptor
!=
null
)
{
...
...
@@ -382,4 +418,29 @@ public class JavaDescriptorResolver {
(
modifierListOwner
.
hasModifierProperty
(
PsiModifier
.
PROTECTED
)
?
Visibility
.
PROTECTED
:
Visibility
.
INTERNAL
));
}
public
TypeParameterDescriptor
resolveTypeParameter
(
PsiTypeParameter
typeParameter
)
{
PsiTypeParameterListOwner
owner
=
typeParameter
.
getOwner
();
if
(
owner
instanceof
PsiClass
)
{
PsiClass
psiClass
=
(
PsiClass
)
owner
;
return
resolveTypeParameter
(
resolveClass
(
psiClass
),
typeParameter
);
}
if
(
owner
instanceof
PsiMethod
)
{
PsiMethod
psiMethod
=
(
PsiMethod
)
owner
;
PsiClass
containingClass
=
psiMethod
.
getContainingClass
();
DeclarationDescriptor
ownerOwner
;
TypeSubstitutor
substitutorForGenericSupertypes
;
if
(
psiMethod
.
hasModifierProperty
(
PsiModifier
.
STATIC
))
{
substitutorForGenericSupertypes
=
TypeSubstitutor
.
EMPTY
;
return
resolveTypeParameter
(
JAVA_METHOD_TYPE_PARAMETER_PARENT
,
typeParameter
);
}
else
{
ClassDescriptor
classDescriptor
=
resolveClass
(
containingClass
);
ownerOwner
=
classDescriptor
;
substitutorForGenericSupertypes
=
semanticServices
.
getDescriptorResolver
().
createSubstitutorForGenericSupertypes
(
classDescriptor
);
}
FunctionDescriptor
functionDescriptor
=
resolveMethodToFunctionDescriptor
(
ownerOwner
,
containingClass
,
substitutorForGenericSupertypes
,
psiMethod
);
return
resolveTypeParameter
(
functionDescriptor
,
typeParameter
);
}
throw
new
IllegalStateException
(
"Unknown parent type: "
+
owner
);
}
}
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
浏览文件 @
87b22e81
...
...
@@ -70,7 +70,7 @@ public class JavaTypeTransformer {
if
(
psiClass
instanceof
PsiTypeParameter
)
{
PsiTypeParameter
typeParameter
=
(
PsiTypeParameter
)
psiClass
;
TypeParameterDescriptor
typeParameterDescriptor
=
resolver
.
resolveTypeParameter
(
JavaDescriptorResolver
.
JAVA_ROOT
,
typeParameter
);
TypeParameterDescriptor
typeParameterDescriptor
=
resolver
.
resolveTypeParameter
(
typeParameter
);
return
typeParameterDescriptor
.
getDefaultType
();
}
else
{
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java
浏览文件 @
87b22e81
...
...
@@ -16,7 +16,7 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
private
final
String
name
;
private
final
DeclarationDescriptor
containingDeclaration
;
public
DeclarationDescriptorImpl
(
@Nullable
DeclarationDescriptor
containingDeclaration
,
List
<
AnnotationDescriptor
>
annotations
,
String
name
)
{
public
DeclarationDescriptorImpl
(
@Nullable
DeclarationDescriptor
containingDeclaration
,
@NotNull
List
<
AnnotationDescriptor
>
annotations
,
@NotNull
String
name
)
{
super
(
annotations
);
this
.
name
=
name
;
this
.
containingDeclaration
=
containingDeclaration
;
...
...
idea/testData/checkerWithErrorTypes/quick/Override.jet
浏览文件 @
87b22e81
...
...
@@ -3,37 +3,51 @@ namespace override
namespace normal {
trait MyTrait {
fun foo()
val pr : Unit
}
abstract class MyAbstractClass {
abstract fun bar()
abstract val prr : Unit
}
open class MyClass : MyTrait, MyAbstractClass {
open class MyClass
()
: MyTrait, MyAbstractClass {
override fun foo() {}
override fun bar() {}
override val pr : Unit = ()
override val prr : Unit = ()
}
class MyChildClass
: MyClass
{}
class MyChildClass
() : MyClass()
{}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!> : MyTrait, MyAbstractClass {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!>
()
: MyTrait, MyAbstractClass {
override fun foo() {}
override val pr : Unit = ()
override val prr : Unit = ()
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass3<!> : MyTrait, MyAbstractClass {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass3<!>
()
: MyTrait, MyAbstractClass {
override fun bar() {}
override val pr : Unit = ()
override val prr : Unit = ()
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass4<!> : MyTrait, MyAbstractClass {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass4<!>
()
: MyTrait, MyAbstractClass {
fun <!VIRTUAL_MEMBER_HIDDEN!>foo<!>() {}
val <!VIRTUAL_MEMBER_HIDDEN, MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>pr<!> : Unit
<!NOTHING_TO_OVERRIDE!>override<!> fun other() {}
<!NOTHING_TO_OVERRIDE!>override<!> val otherPr : Int = 1
}
class MyChildClass1
: MyClass
{
class MyChildClass1
() : MyClass()
{
fun <!VIRTUAL_MEMBER_HIDDEN!>foo<!>() {}
val <!VIRTUAL_MEMBER_HIDDEN!>pr<!> : Unit = ()
override fun bar() {}
override val prr : Unit = ()
}
}
...
...
@@ -44,33 +58,56 @@ namespace generics {
abstract class MyAbstractClass<T> {
abstract fun bar(t: T) : T
abstract val pr : T
}
trait MyProps<T> {
val p : T
}
open class MyGenericClass<T>
: MyTrait<T>, MyAbstractClas
s<T> {
open class MyGenericClass<T>
(t : T) : MyTrait<T>, MyAbstractClass<T>, MyProp
s<T> {
override fun foo(t: T) = t
override fun bar(t: T) = t
override val p : T = t
override val pr : T = t
}
class MyChildClass
: MyGenericClass<Int>
{}
class MyChildClass1<T>
: MyGenericClass<T>
{}
class MyChildClass2<T>
: MyGenericClass<T>
{
class MyChildClass
() : MyGenericClass<Int>(1)
{}
class MyChildClass1<T>
(t : T) : MyGenericClass<T>(t)
{}
class MyChildClass2<T>
(t : T) : MyGenericClass<T>(t)
{
fun <!VIRTUAL_MEMBER_HIDDEN!>foo<!>(t: T) = t
val <!VIRTUAL_MEMBER_HIDDEN!>pr<!> : T = t
override fun bar(t: T) = t
override val p : T = t
}
open class MyClass : MyTrait<Int>, MyAbstractClass<String> {
open class MyClass() : MyTrait<Int>, MyAbstractClass<String> {
override fun foo(i: Int) = i
override fun bar(s: String) = s
override val pr : String = "1"
}
abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String> {
override fun foo(i: Int) = i
override fun bar(s: String) = s
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T> {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R> : MyTrait<T>, MyAbstractClass<R> {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>
(r : R)
: MyTrait<T>, MyAbstractClass<R> {
<!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r
<!NOTHING_TO_OVERRIDE!>override<!> val <T> pr : R = r
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String> {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String> {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T> : MyTrait<Int>, MyAbstractClass<Int> {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int> {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
}
abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int> {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录