Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
dd0b3c8f
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,发现更多精彩内容 >>
提交
dd0b3c8f
编写于
9月 08, 2011
作者:
S
svtk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added more 'abstract' modifier checks; added 'ClassModifiers'
上级
73b4fa2e
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
258 addition
and
161 deletion
+258
-161
idea/src/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java
...c/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java
+2
-5
idea/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
...g/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
+3
-12
idea/src/org/jetbrains/jet/lang/descriptors/ClassModifiers.java
...rc/org/jetbrains/jet/lang/descriptors/ClassModifiers.java
+40
-0
idea/src/org/jetbrains/jet/lang/descriptors/ConstructorDescriptorImpl.java
...rains/jet/lang/descriptors/ConstructorDescriptorImpl.java
+4
-9
idea/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
...etbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
+6
-7
idea/src/org/jetbrains/jet/lang/descriptors/LazySubstitutingClassDescriptor.java
...jet/lang/descriptors/LazySubstitutingClassDescriptor.java
+3
-12
idea/src/org/jetbrains/jet/lang/descriptors/MemberModifiers.java
...c/org/jetbrains/jet/lang/descriptors/MemberModifiers.java
+23
-6
idea/src/org/jetbrains/jet/lang/descriptors/Modifiers.java
idea/src/org/jetbrains/jet/lang/descriptors/Modifiers.java
+16
-0
idea/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
...etbrains/jet/lang/descriptors/MutableClassDescriptor.java
+12
-30
idea/src/org/jetbrains/jet/lang/descriptors/VariableAsFunctionDescriptor.java
...ns/jet/lang/descriptors/VariableAsFunctionDescriptor.java
+1
-1
idea/src/org/jetbrains/jet/lang/psi/JetModifierList.java
idea/src/org/jetbrains/jet/lang/psi/JetModifierList.java
+12
-0
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
...g/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
+14
-23
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+15
-12
idea/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
...rc/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
+17
-0
idea/src/org/jetbrains/jet/lang/resolve/calls/ResolutionTask.java
.../org/jetbrains/jet/lang/resolve/calls/ResolutionTask.java
+17
-0
idea/src/org/jetbrains/jet/lang/resolve/java/JavaClassDescriptor.java
.../jetbrains/jet/lang/resolve/java/JavaClassDescriptor.java
+26
-18
idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
...tbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+4
-3
idea/src/org/jetbrains/jet/lang/types/ErrorUtils.java
idea/src/org/jetbrains/jet/lang/types/ErrorUtils.java
+4
-2
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
+1
-1
idea/src/org/jetbrains/jet/resolve/DescriptorRenderer.java
idea/src/org/jetbrains/jet/resolve/DescriptorRenderer.java
+1
-1
idea/testData/checker/Abstract.jet
idea/testData/checker/Abstract.jet
+19
-1
idea/testData/checker/BinaryCallsOnNullableValues.jet
idea/testData/checker/BinaryCallsOnNullableValues.jet
+6
-6
idea/testData/checker/ExtensionFunctions.jet
idea/testData/checker/ExtensionFunctions.jet
+2
-2
idea/testData/checker/ForRangeConventions.jet
idea/testData/checker/ForRangeConventions.jet
+10
-10
未找到文件。
idea/src/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java
浏览文件 @
dd0b3c8f
...
@@ -44,9 +44,6 @@ public interface ClassDescriptor extends ClassifierDescriptor {
...
@@ -44,9 +44,6 @@ public interface ClassDescriptor extends ClassifierDescriptor {
boolean
isObject
();
boolean
isObject
();
boolean
isAbstract
();
@NotNull
ClassModifiers
getClassModifiers
();
boolean
isOpen
();
boolean
isTrait
();
}
}
idea/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
浏览文件 @
dd0b3c8f
...
@@ -117,17 +117,8 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
...
@@ -117,17 +117,8 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
}
}
@Override
@Override
public
boolean
isAbstract
()
{
@NotNull
return
false
;
public
ClassModifiers
getClassModifiers
()
{
}
return
ClassModifiers
.
DEFAULT_MODIFIERS
;
@Override
public
boolean
isOpen
()
{
return
false
;
}
@Override
public
boolean
isTrait
()
{
return
false
;
}
}
}
}
idea/src/org/jetbrains/jet/lang/descriptors/ClassModifiers.java
0 → 100644
浏览文件 @
dd0b3c8f
package
org.jetbrains.jet.lang.descriptors
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.psi.JetModifierList
;
import
org.jetbrains.jet.lexer.JetTokens
;
/**
* @author svtk
*/
public
class
ClassModifiers
extends
Modifiers
{
public
static
final
ClassModifiers
DEFAULT_MODIFIERS
=
new
ClassModifiers
(
false
,
false
,
false
);
private
boolean
open
;
private
boolean
trait
;
public
ClassModifiers
(
boolean
anAbstract
,
boolean
open
,
boolean
trait
)
{
super
(
anAbstract
);
this
.
open
=
open
;
this
.
trait
=
trait
;
}
public
boolean
isOpen
()
{
return
open
;
}
public
boolean
isTrait
()
{
return
trait
;
}
public
static
ClassModifiers
resolveModifiers
(
@Nullable
JetModifierList
modifierList
)
{
if
(
modifierList
==
null
)
return
DEFAULT_MODIFIERS
;
return
new
ClassModifiers
(
modifierList
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
),
modifierList
.
hasModifier
(
JetTokens
.
OPEN_KEYWORD
)
||
modifierList
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
),
modifierList
.
hasModifier
(
JetTokens
.
TRAIT_KEYWORD
)
);
}
}
idea/src/org/jetbrains/jet/lang/descriptors/ConstructorDescriptorImpl.java
浏览文件 @
dd0b3c8f
...
@@ -28,13 +28,13 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
...
@@ -28,13 +28,13 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
@Override
@Override
@Deprecated
@Deprecated
public
FunctionDescriptorImpl
initialize
(
@Nullable
JetType
receiverType
,
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
,
@Nullable
JetType
unsubstitutedReturnType
)
{
public
FunctionDescriptorImpl
initialize
(
@Nullable
JetType
receiverType
,
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
,
@Nullable
JetType
unsubstitutedReturnType
,
MemberModifiers
modifiers
)
{
assert
receiverType
==
null
;
assert
receiverType
==
null
;
return
super
.
initialize
(
null
,
typeParameters
,
unsubstitutedValueParameters
,
unsubstitutedReturnType
);
return
super
.
initialize
(
null
,
typeParameters
,
unsubstitutedValueParameters
,
unsubstitutedReturnType
,
modifiers
);
}
}
public
ConstructorDescriptorImpl
initialize
(
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
)
{
public
ConstructorDescriptorImpl
initialize
(
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
,
MemberModifiers
modifiers
)
{
super
.
initialize
(
null
,
typeParameters
,
unsubstitutedValueParameters
,
null
);
super
.
initialize
(
null
,
typeParameters
,
unsubstitutedValueParameters
,
null
,
modifiers
);
return
this
;
return
this
;
}
}
...
@@ -66,11 +66,6 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
...
@@ -66,11 +66,6 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
return
Collections
.
emptySet
();
return
Collections
.
emptySet
();
}
}
@Nullable
public
MemberModifiers
getModifiers
()
{
return
null
;
}
@Override
@Override
public
void
addOverriddenFunction
(
@NotNull
FunctionDescriptor
overriddenFunction
)
{
public
void
addOverriddenFunction
(
@NotNull
FunctionDescriptor
overriddenFunction
)
{
throw
new
UnsupportedOperationException
(
"Constructors cannot override anything"
);
throw
new
UnsupportedOperationException
(
"Constructors cannot override anything"
);
...
...
idea/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
浏览文件 @
dd0b3c8f
...
@@ -47,11 +47,13 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
...
@@ -47,11 +47,13 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
@Nullable
JetType
receiverType
,
@Nullable
JetType
receiverType
,
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
List
<
TypeParameterDescriptor
>
typeParameters
,
@NotNull
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
,
@NotNull
List
<
ValueParameterDescriptor
>
unsubstitutedValueParameters
,
@Nullable
JetType
unsubstitutedReturnType
)
{
@Nullable
JetType
unsubstitutedReturnType
,
@Nullable
MemberModifiers
modifiers
)
{
this
.
receiverType
=
receiverType
;
this
.
receiverType
=
receiverType
;
this
.
typeParameters
=
typeParameters
;
this
.
typeParameters
=
typeParameters
;
this
.
unsubstitutedValueParameters
=
unsubstitutedValueParameters
;
this
.
unsubstitutedValueParameters
=
unsubstitutedValueParameters
;
this
.
unsubstitutedReturnType
=
unsubstitutedReturnType
;
this
.
unsubstitutedReturnType
=
unsubstitutedReturnType
;
this
.
modifiers
=
modifiers
;
return
this
;
return
this
;
}
}
...
@@ -70,11 +72,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
...
@@ -70,11 +72,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
return
overriddenFunctions
;
return
overriddenFunctions
;
}
}
public
void
setModifiers
(
MemberModifiers
modifiers
)
{
@NotNull
this
.
modifiers
=
modifiers
;
}
@Nullable
@Override
@Override
public
MemberModifiers
getModifiers
()
{
public
MemberModifiers
getModifiers
()
{
return
modifiers
;
return
modifiers
;
...
@@ -141,7 +139,8 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
...
@@ -141,7 +139,8 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
substitutedReceiverType
,
substitutedReceiverType
,
substitutedTypeParameters
,
substitutedTypeParameters
,
substitutedValueParameters
,
substitutedValueParameters
,
substitutedReturnType
substitutedReturnType
,
modifiers
);
);
return
substitutedDescriptor
;
return
substitutedDescriptor
;
}
}
...
...
idea/src/org/jetbrains/jet/lang/descriptors/LazySubstitutingClassDescriptor.java
浏览文件 @
dd0b3c8f
...
@@ -140,18 +140,9 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
...
@@ -140,18 +140,9 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
}
}
@Override
@Override
public
boolean
isAbstract
()
{
@NotNull
return
original
.
isAbstract
();
public
ClassModifiers
getClassModifiers
()
{
}
return
original
.
getClassModifiers
();
@Override
public
boolean
isOpen
()
{
return
original
.
isOpen
();
}
@Override
public
boolean
isTrait
()
{
return
original
.
isTrait
();
}
}
@Override
@Override
...
...
idea/src/org/jetbrains/jet/lang/descriptors/MemberModifiers.java
浏览文件 @
dd0b3c8f
package
org.jetbrains.jet.lang.descriptors
;
package
org.jetbrains.jet.lang.descriptors
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.psi.JetModifierList
;
import
org.jetbrains.jet.lexer.JetTokens
;
/**
/**
* @author abreslav
* @author abreslav
*/
*/
public
class
MemberModifiers
{
public
class
MemberModifiers
extends
Modifiers
{
public
static
final
MemberModifiers
DEFAULT_MODIFIERS
=
new
MemberModifiers
(
false
,
false
,
false
);
private
final
boolean
isAbstract
;
private
final
boolean
isVirtual
;
private
final
boolean
isVirtual
;
private
final
boolean
isOverride
;
private
final
boolean
isOverride
;
public
MemberModifiers
(
boolean
isAbstract
,
boolean
isVirtual
,
boolean
isOverride
)
{
public
MemberModifiers
(
boolean
isAbstract
,
boolean
isVirtual
,
boolean
isOverride
)
{
this
.
isAbstract
=
isAbstract
;
super
(
isAbstract
)
;
this
.
isVirtual
=
isVirtual
;
this
.
isVirtual
=
isVirtual
;
this
.
isOverride
=
isOverride
;
this
.
isOverride
=
isOverride
;
}
}
public
boolean
isAbstract
()
{
return
isAbstract
;
}
public
boolean
isVirtual
()
{
public
boolean
isVirtual
()
{
return
isVirtual
;
return
isVirtual
;
...
@@ -30,4 +32,19 @@ public class MemberModifiers {
...
@@ -30,4 +32,19 @@ public class MemberModifiers {
public
boolean
isOverridable
()
{
public
boolean
isOverridable
()
{
return
isAbstract
()
||
isVirtual
()
||
isOverride
();
return
isAbstract
()
||
isVirtual
()
||
isOverride
();
}
}
@NotNull
public
static
MemberModifiers
resolveModifiers
(
@Nullable
JetModifierList
modifierList
)
{
return
resolveModifiers
(
modifierList
,
DEFAULT_MODIFIERS
);
}
@NotNull
public
static
MemberModifiers
resolveModifiers
(
@Nullable
JetModifierList
modifierList
,
@NotNull
MemberModifiers
defaultModifiers
)
{
if
(
modifierList
==
null
)
return
defaultModifiers
;
return
new
MemberModifiers
(
modifierList
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
),
modifierList
.
hasModifier
(
JetTokens
.
VIRTUAL_KEYWORD
),
modifierList
.
hasModifier
(
JetTokens
.
OVERRIDE_KEYWORD
)
);
}
}
}
idea/src/org/jetbrains/jet/lang/descriptors/Modifiers.java
0 → 100644
浏览文件 @
dd0b3c8f
package
org.jetbrains.jet.lang.descriptors
;
/**
* @author svtk
*/
public
class
Modifiers
{
private
final
boolean
isAbstract
;
public
Modifiers
(
boolean
anAbstract
)
{
isAbstract
=
anAbstract
;
}
public
boolean
isAbstract
()
{
return
isAbstract
;
}
}
idea/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
浏览文件 @
dd0b3c8f
...
@@ -22,9 +22,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
...
@@ -22,9 +22,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
private
List
<
TypeParameterDescriptor
>
typeParameters
=
Lists
.
newArrayList
();
private
List
<
TypeParameterDescriptor
>
typeParameters
=
Lists
.
newArrayList
();
private
Collection
<
JetType
>
supertypes
=
Lists
.
newArrayList
();
private
Collection
<
JetType
>
supertypes
=
Lists
.
newArrayList
();
private
boolean
open
;
private
ClassModifiers
classModifiers
;
private
boolean
isAbstract
;
private
boolean
trait
;
private
TypeConstructor
typeConstructor
;
private
TypeConstructor
typeConstructor
;
private
final
WritableScope
scopeForMemberResolution
;
private
final
WritableScope
scopeForMemberResolution
;
private
final
WritableScope
scopeForMemberLookup
;
private
final
WritableScope
scopeForMemberLookup
;
...
@@ -143,32 +141,6 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
...
@@ -143,32 +141,6 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
scopeForMemberResolution
.
addLabeledDeclaration
(
this
);
scopeForMemberResolution
.
addLabeledDeclaration
(
this
);
}
}
@Override
public
boolean
isAbstract
()
{
return
isAbstract
||
trait
;
}
public
void
setAbstract
(
boolean
isAbstract
)
{
this
.
isAbstract
=
isAbstract
;
}
@Override
public
boolean
isTrait
()
{
return
trait
;
}
public
void
setTrait
(
boolean
trait
)
{
this
.
trait
=
trait
;
}
public
boolean
isOpen
()
{
return
open
;
}
public
void
setOpen
(
boolean
open
)
{
this
.
open
=
open
;
}
@NotNull
@NotNull
@Override
@Override
public
TypeConstructor
getTypeConstructor
()
{
public
TypeConstructor
getTypeConstructor
()
{
...
@@ -180,7 +152,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
...
@@ -180,7 +152,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
this
.
typeConstructor
=
new
TypeConstructorImpl
(
this
.
typeConstructor
=
new
TypeConstructorImpl
(
this
,
this
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
// TODO : pass annotations from the class?
Collections
.<
AnnotationDescriptor
>
emptyList
(),
// TODO : pass annotations from the class?
!
open
,
!
classModifiers
.
isOpen
()
,
getName
(),
getName
(),
typeParameters
,
typeParameters
,
supertypes
);
supertypes
);
...
@@ -276,6 +248,16 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
...
@@ -276,6 +248,16 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
return
isObject
;
return
isObject
;
}
}
public
void
setClassModifiers
(
ClassModifiers
classModifiers
)
{
this
.
classModifiers
=
classModifiers
;
}
@Override
@NotNull
public
ClassModifiers
getClassModifiers
()
{
return
classModifiers
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
DescriptorRenderer
.
TEXT
.
render
(
this
)
+
"["
+
getClass
().
getCanonicalName
()
+
"@"
+
System
.
identityHashCode
(
this
)
+
"]"
;
return
DescriptorRenderer
.
TEXT
.
render
(
this
)
+
"["
+
getClass
().
getCanonicalName
()
+
"@"
+
System
.
identityHashCode
(
this
)
+
"]"
;
...
...
idea/src/org/jetbrains/jet/lang/descriptors/VariableAsFunctionDescriptor.java
浏览文件 @
dd0b3c8f
...
@@ -16,7 +16,7 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
...
@@ -16,7 +16,7 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
assert
outType
!=
null
;
assert
outType
!=
null
;
assert
JetStandardClasses
.
isFunctionType
(
outType
);
assert
JetStandardClasses
.
isFunctionType
(
outType
);
VariableAsFunctionDescriptor
result
=
new
VariableAsFunctionDescriptor
(
variableDescriptor
);
VariableAsFunctionDescriptor
result
=
new
VariableAsFunctionDescriptor
(
variableDescriptor
);
result
.
initialize
(
JetStandardClasses
.
getReceiverType
(
outType
),
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
JetStandardClasses
.
getValueParameters
(
result
,
outType
),
JetStandardClasses
.
getReturnType
(
outType
));
result
.
initialize
(
JetStandardClasses
.
getReceiverType
(
outType
),
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
JetStandardClasses
.
getValueParameters
(
result
,
outType
),
JetStandardClasses
.
getReturnType
(
outType
)
,
MemberModifiers
.
DEFAULT_MODIFIERS
);
return
result
;
return
result
;
}
}
...
...
idea/src/org/jetbrains/jet/lang/psi/JetModifierList.java
浏览文件 @
dd0b3c8f
...
@@ -5,6 +5,8 @@ import com.intellij.lang.ASTNode;
...
@@ -5,6 +5,8 @@ import com.intellij.lang.ASTNode;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.JetNodeTypes
;
import
org.jetbrains.jet.JetNodeTypes
;
import
org.jetbrains.jet.lang.resolve.BindingTrace
;
import
org.jetbrains.jet.lexer.JetKeywordToken
;
import
org.jetbrains.jet.lexer.JetToken
;
import
org.jetbrains.jet.lexer.JetToken
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -57,4 +59,14 @@ public class JetModifierList extends JetElement {
...
@@ -57,4 +59,14 @@ public class JetModifierList extends JetElement {
}
}
return
null
;
return
null
;
}
}
public
boolean
checkNotContains
(
BindingTrace
trace
,
JetToken
...
tokens
)
{
for
(
JetToken
token
:
tokens
)
{
if
(
hasModifier
(
token
))
{
trace
.
getErrorHandler
().
genericError
(
getModifierNode
(
token
),
"Annotation "
+
((
JetKeywordToken
)
token
).
getValue
()
+
" is not allowed here"
);
return
false
;
}
}
return
true
;
}
}
}
idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
浏览文件 @
dd0b3c8f
...
@@ -26,7 +26,7 @@ import java.util.*;
...
@@ -26,7 +26,7 @@ import java.util.*;
*/
*/
public
class
ClassDescriptorResolver
{
public
class
ClassDescriptorResolver
{
private
static
final
MemberModifiers
DEFAULT_MODIFIERS
=
new
MemberModifiers
(
false
,
false
,
false
);
//
private static final MemberModifiers DEFAULT_MODIFIERS = new MemberModifiers(false, false, false);
private
final
JetSemanticServices
semanticServices
;
private
final
JetSemanticServices
semanticServices
;
private
final
TypeResolver
typeResolver
;
private
final
TypeResolver
typeResolver
;
...
@@ -144,10 +144,7 @@ public class ClassDescriptorResolver {
...
@@ -144,10 +144,7 @@ public class ClassDescriptorResolver {
index
++;
index
++;
}
}
descriptor
.
setTypeParameterDescriptors
(
typeParameters
);
descriptor
.
setTypeParameterDescriptors
(
typeParameters
);
descriptor
.
setClassModifiers
(
ClassModifiers
.
resolveModifiers
(
classElement
.
getModifierList
()));
descriptor
.
setOpen
(
classElement
.
hasModifier
(
JetTokens
.
OPEN_KEYWORD
)
||
classElement
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
));
descriptor
.
setAbstract
(
classElement
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
));
descriptor
.
setTrait
(
classElement
.
hasModifier
(
JetTokens
.
TRAIT_KEYWORD
));
trace
.
record
(
BindingContext
.
CLASS
,
classElement
,
descriptor
);
trace
.
record
(
BindingContext
.
CLASS
,
classElement
,
descriptor
);
}
}
...
@@ -227,13 +224,13 @@ public class ClassDescriptorResolver {
...
@@ -227,13 +224,13 @@ public class ClassDescriptorResolver {
returnType
=
ErrorUtils
.
createErrorType
(
"No type, no body"
);
returnType
=
ErrorUtils
.
createErrorType
(
"No type, no body"
);
}
}
}
}
functionDescriptor
.
setModifiers
(
resolveModifiers
(
function
.
getModifierList
(),
DEFAULT_MODIFIERS
));
functionDescriptor
.
initialize
(
functionDescriptor
.
initialize
(
receiverType
,
receiverType
,
typeParameterDescriptors
,
typeParameterDescriptors
,
valueParameterDescriptors
,
valueParameterDescriptors
,
returnType
);
returnType
,
MemberModifiers
.
resolveModifiers
(
function
.
getModifierList
()));
trace
.
record
(
BindingContext
.
FUNCTION
,
function
,
functionDescriptor
);
trace
.
record
(
BindingContext
.
FUNCTION
,
function
,
functionDescriptor
);
return
functionDescriptor
;
return
functionDescriptor
;
...
@@ -466,7 +463,7 @@ public class ClassDescriptorResolver {
...
@@ -466,7 +463,7 @@ public class ClassDescriptorResolver {
PropertyDescriptor
propertyDescriptor
=
new
PropertyDescriptor
(
PropertyDescriptor
propertyDescriptor
=
new
PropertyDescriptor
(
containingDeclaration
,
containingDeclaration
,
annotationResolver
.
createAnnotationStubs
(
modifierList
),
annotationResolver
.
createAnnotationStubs
(
modifierList
),
resolveModifiers
(
modifierList
,
DEFAULT_MODIFIERS
),
// TODO : default modifiers differ in different contexts
MemberModifiers
.
resolveModifiers
(
modifierList
),
// TODO : default modifiers differ in different contexts
false
,
false
,
null
,
null
,
JetPsiUtil
.
safeName
(
objectDeclaration
.
getName
()),
JetPsiUtil
.
safeName
(
objectDeclaration
.
getName
()),
...
@@ -516,7 +513,7 @@ public class ClassDescriptorResolver {
...
@@ -516,7 +513,7 @@ public class ClassDescriptorResolver {
PropertyDescriptor
propertyDescriptor
=
new
PropertyDescriptor
(
PropertyDescriptor
propertyDescriptor
=
new
PropertyDescriptor
(
containingDeclaration
,
containingDeclaration
,
annotationResolver
.
resolveAnnotations
(
scope
,
modifierList
),
annotationResolver
.
resolveAnnotations
(
scope
,
modifierList
),
resolveModifiers
(
modifierList
,
DEFAULT_MODIFIERS
),
// TODO : default modifiers differ in different contexts
MemberModifiers
.
resolveModifiers
(
modifierList
),
// TODO : default modifiers differ in different contexts
isVar
,
isVar
,
receiverType
,
receiverType
,
JetPsiUtil
.
safeName
(
property
.
getName
()),
JetPsiUtil
.
safeName
(
property
.
getName
()),
...
@@ -563,16 +560,6 @@ public class ClassDescriptorResolver {
...
@@ -563,16 +560,6 @@ public class ClassDescriptorResolver {
}
}
}
}
@NotNull
private
MemberModifiers
resolveModifiers
(
@Nullable
JetModifierList
modifierList
,
@NotNull
MemberModifiers
defaultModifiers
)
{
if
(
modifierList
==
null
)
return
defaultModifiers
;
return
new
MemberModifiers
(
modifierList
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
),
modifierList
.
hasModifier
(
JetTokens
.
VIRTUAL_KEYWORD
),
modifierList
.
hasModifier
(
JetTokens
.
OVERRIDE_KEYWORD
)
);
}
@Nullable
@Nullable
private
PropertySetterDescriptor
resolvePropertySetterDescriptor
(
@NotNull
JetScope
scope
,
@NotNull
JetProperty
property
,
@NotNull
PropertyDescriptor
propertyDescriptor
)
{
private
PropertySetterDescriptor
resolvePropertySetterDescriptor
(
@NotNull
JetScope
scope
,
@NotNull
JetProperty
property
,
@NotNull
PropertyDescriptor
propertyDescriptor
)
{
JetPropertyAccessor
setter
=
property
.
getSetter
();
JetPropertyAccessor
setter
=
property
.
getSetter
();
...
@@ -582,7 +569,7 @@ public class ClassDescriptorResolver {
...
@@ -582,7 +569,7 @@ public class ClassDescriptorResolver {
JetParameter
parameter
=
setter
.
getParameter
();
JetParameter
parameter
=
setter
.
getParameter
();
setterDescriptor
=
new
PropertySetterDescriptor
(
setterDescriptor
=
new
PropertySetterDescriptor
(
resolveModifiers
(
setter
.
getModifierList
(),
DEFAULT_MODIFIERS
),
// TODO : default modifiers differ in different contexts
MemberModifiers
.
resolveModifiers
(
setter
.
getModifierList
()
),
// TODO : default modifiers differ in different contexts
propertyDescriptor
,
annotations
,
setter
.
getBodyExpression
()
!=
null
,
false
);
propertyDescriptor
,
annotations
,
setter
.
getBodyExpression
()
!=
null
,
false
);
if
(
parameter
!=
null
)
{
if
(
parameter
!=
null
)
{
if
(
parameter
.
isRef
())
{
if
(
parameter
.
isRef
())
{
...
@@ -646,7 +633,7 @@ public class ClassDescriptorResolver {
...
@@ -646,7 +633,7 @@ public class ClassDescriptorResolver {
}
}
getterDescriptor
=
new
PropertyGetterDescriptor
(
getterDescriptor
=
new
PropertyGetterDescriptor
(
resolveModifiers
(
getter
.
getModifierList
(),
DEFAULT_MODIFIERS
),
// TODO : default modifiers differ in different contexts
MemberModifiers
.
resolveModifiers
(
getter
.
getModifierList
()
),
// TODO : default modifiers differ in different contexts
propertyDescriptor
,
annotations
,
returnType
,
getter
.
getBodyExpression
()
!=
null
,
false
);
propertyDescriptor
,
annotations
,
returnType
,
getter
.
getBodyExpression
()
!=
null
,
false
);
trace
.
record
(
BindingContext
.
PROPERTY_ACCESSOR
,
getter
,
getterDescriptor
);
trace
.
record
(
BindingContext
.
PROPERTY_ACCESSOR
,
getter
,
getterDescriptor
);
}
}
...
@@ -677,12 +664,16 @@ public class ClassDescriptorResolver {
...
@@ -677,12 +664,16 @@ public class ClassDescriptorResolver {
isPrimary
isPrimary
);
);
trace
.
record
(
BindingContext
.
CONSTRUCTOR
,
declarationToTrace
,
constructorDescriptor
);
trace
.
record
(
BindingContext
.
CONSTRUCTOR
,
declarationToTrace
,
constructorDescriptor
);
if
(
modifierList
!=
null
)
{
modifierList
.
checkNotContains
(
trace
,
JetTokens
.
ABSTRACT_KEYWORD
,
JetTokens
.
VIRTUAL_KEYWORD
,
JetTokens
.
OVERRIDE_KEYWORD
);
}
return
constructorDescriptor
.
initialize
(
return
constructorDescriptor
.
initialize
(
typeParameters
,
typeParameters
,
resolveValueParameters
(
resolveValueParameters
(
constructorDescriptor
,
constructorDescriptor
,
new
WritableScopeImpl
(
scope
,
classDescriptor
,
trace
.
getErrorHandler
()).
setDebugName
(
"Scope with value parameters of a constructor"
),
new
WritableScopeImpl
(
scope
,
classDescriptor
,
trace
.
getErrorHandler
()).
setDebugName
(
"Scope with value parameters of a constructor"
),
valueParameters
));
valueParameters
),
MemberModifiers
.
DEFAULT_MODIFIERS
);
}
}
@Nullable
@Nullable
...
@@ -717,7 +708,7 @@ public class ClassDescriptorResolver {
...
@@ -717,7 +708,7 @@ public class ClassDescriptorResolver {
PropertyDescriptor
propertyDescriptor
=
new
PropertyDescriptor
(
PropertyDescriptor
propertyDescriptor
=
new
PropertyDescriptor
(
classDescriptor
,
classDescriptor
,
annotationResolver
.
resolveAnnotations
(
scope
,
modifierList
),
annotationResolver
.
resolveAnnotations
(
scope
,
modifierList
),
resolveModifiers
(
modifierList
,
DEFAULT_MODIFIERS
),
MemberModifiers
.
resolveModifiers
(
modifierList
),
isMutable
,
isMutable
,
null
,
null
,
name
==
null
?
"<no name>"
:
name
,
name
==
null
?
"<no name>"
:
name
,
...
...
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
浏览文件 @
dd0b3c8f
...
@@ -172,6 +172,7 @@ public class TopDownAnalyzer {
...
@@ -172,6 +172,7 @@ public class TopDownAnalyzer {
if
(
klass
.
hasModifier
(
JetTokens
.
ENUM_KEYWORD
))
{
if
(
klass
.
hasModifier
(
JetTokens
.
ENUM_KEYWORD
))
{
MutableClassDescriptor
classObjectDescriptor
=
new
MutableClassDescriptor
(
trace
,
mutableClassDescriptor
,
outerScope
,
true
);
MutableClassDescriptor
classObjectDescriptor
=
new
MutableClassDescriptor
(
trace
,
mutableClassDescriptor
,
outerScope
,
true
);
classObjectDescriptor
.
setName
(
"class-object-for-"
+
klass
.
getName
());
classObjectDescriptor
.
setName
(
"class-object-for-"
+
klass
.
getName
());
classObjectDescriptor
.
setClassModifiers
(
ClassModifiers
.
DEFAULT_MODIFIERS
);
classObjectDescriptor
.
createTypeConstructor
();
classObjectDescriptor
.
createTypeConstructor
();
createPrimaryConstructor
(
classObjectDescriptor
);
createPrimaryConstructor
(
classObjectDescriptor
);
mutableClassDescriptor
.
setClassObjectDescriptor
(
classObjectDescriptor
);
mutableClassDescriptor
.
setClassObjectDescriptor
(
classObjectDescriptor
);
...
@@ -226,7 +227,8 @@ public class TopDownAnalyzer {
...
@@ -226,7 +227,8 @@ public class TopDownAnalyzer {
private
void
createPrimaryConstructor
(
MutableClassDescriptor
mutableClassDescriptor
)
{
private
void
createPrimaryConstructor
(
MutableClassDescriptor
mutableClassDescriptor
)
{
ConstructorDescriptorImpl
constructorDescriptor
=
new
ConstructorDescriptorImpl
(
mutableClassDescriptor
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
true
);
ConstructorDescriptorImpl
constructorDescriptor
=
new
ConstructorDescriptorImpl
(
mutableClassDescriptor
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
true
);
constructorDescriptor
.
initialize
(
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
Collections
.<
ValueParameterDescriptor
>
emptyList
());
constructorDescriptor
.
initialize
(
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
Collections
.<
ValueParameterDescriptor
>
emptyList
(),
MemberModifiers
.
DEFAULT_MODIFIERS
);
// TODO : make the constructor private?
// TODO : make the constructor private?
mutableClassDescriptor
.
setPrimaryConstructor
(
constructorDescriptor
);
mutableClassDescriptor
.
setPrimaryConstructor
(
constructorDescriptor
);
}
}
...
@@ -329,6 +331,7 @@ public class TopDownAnalyzer {
...
@@ -329,6 +331,7 @@ public class TopDownAnalyzer {
}
}
for
(
Map
.
Entry
<
JetObjectDeclaration
,
MutableClassDescriptor
>
entry
:
objects
.
entrySet
())
{
for
(
Map
.
Entry
<
JetObjectDeclaration
,
MutableClassDescriptor
>
entry
:
objects
.
entrySet
())
{
MutableClassDescriptor
descriptor
=
entry
.
getValue
();
MutableClassDescriptor
descriptor
=
entry
.
getValue
();
descriptor
.
setClassModifiers
(
ClassModifiers
.
DEFAULT_MODIFIERS
);
descriptor
.
createTypeConstructor
();
descriptor
.
createTypeConstructor
();
}
}
}
}
...
@@ -484,7 +487,7 @@ public class TopDownAnalyzer {
...
@@ -484,7 +487,7 @@ public class TopDownAnalyzer {
private
void
processPrimaryConstructor
(
MutableClassDescriptor
classDescriptor
,
JetClass
klass
)
{
private
void
processPrimaryConstructor
(
MutableClassDescriptor
classDescriptor
,
JetClass
klass
)
{
if
(!
klass
.
hasPrimaryConstructor
())
return
;
if
(!
klass
.
hasPrimaryConstructor
())
return
;
if
(
classDescriptor
.
isTrait
())
{
if
(
classDescriptor
.
getClassModifiers
().
isTrait
())
{
trace
.
getErrorHandler
().
genericError
(
klass
.
getPrimaryConstructorParameterList
().
getNode
(),
"A trait may not have a constructor"
);
trace
.
getErrorHandler
().
genericError
(
klass
.
getPrimaryConstructorParameterList
().
getNode
(),
"A trait may not have a constructor"
);
}
}
...
@@ -506,7 +509,7 @@ public class TopDownAnalyzer {
...
@@ -506,7 +509,7 @@ public class TopDownAnalyzer {
}
}
private
void
processSecondaryConstructor
(
MutableClassDescriptor
classDescriptor
,
JetConstructor
constructor
)
{
private
void
processSecondaryConstructor
(
MutableClassDescriptor
classDescriptor
,
JetConstructor
constructor
)
{
if
(
classDescriptor
.
isTrait
())
{
if
(
classDescriptor
.
getClassModifiers
().
isTrait
())
{
trace
.
getErrorHandler
().
genericError
(
constructor
.
getNameNode
(),
"A trait may not have a constructor"
);
trace
.
getErrorHandler
().
genericError
(
constructor
.
getNameNode
(),
"A trait may not have a constructor"
);
}
}
ConstructorDescriptor
constructorDescriptor
=
classDescriptorResolver
.
resolveSecondaryConstructorDescriptor
(
ConstructorDescriptor
constructorDescriptor
=
classDescriptorResolver
.
resolveSecondaryConstructorDescriptor
(
...
@@ -608,7 +611,7 @@ public class TopDownAnalyzer {
...
@@ -608,7 +611,7 @@ public class TopDownAnalyzer {
@Override
@Override
public
void
visitDelegationByExpressionSpecifier
(
JetDelegatorByExpressionSpecifier
specifier
)
{
public
void
visitDelegationByExpressionSpecifier
(
JetDelegatorByExpressionSpecifier
specifier
)
{
if
(
descriptor
.
isTrait
())
{
if
(
descriptor
.
getClassModifiers
().
isTrait
())
{
trace
.
getErrorHandler
().
genericError
(
specifier
.
getNode
(),
"Traits can not use delegation"
);
trace
.
getErrorHandler
().
genericError
(
specifier
.
getNode
(),
"Traits can not use delegation"
);
}
}
JetExpression
delegateExpression
=
specifier
.
getDelegateExpression
();
JetExpression
delegateExpression
=
specifier
.
getDelegateExpression
();
...
@@ -626,7 +629,7 @@ public class TopDownAnalyzer {
...
@@ -626,7 +629,7 @@ public class TopDownAnalyzer {
@Override
@Override
public
void
visitDelegationToSuperCallSpecifier
(
JetDelegatorToSuperCall
call
)
{
public
void
visitDelegationToSuperCallSpecifier
(
JetDelegatorToSuperCall
call
)
{
if
(
descriptor
.
isTrait
())
{
if
(
descriptor
.
getClassModifiers
().
isTrait
())
{
JetValueArgumentList
valueArgumentList
=
call
.
getValueArgumentList
();
JetValueArgumentList
valueArgumentList
=
call
.
getValueArgumentList
();
ASTNode
node
=
valueArgumentList
==
null
?
call
.
getNode
()
:
valueArgumentList
.
getNode
();
ASTNode
node
=
valueArgumentList
==
null
?
call
.
getNode
()
:
valueArgumentList
.
getNode
();
trace
.
getErrorHandler
().
genericError
(
node
,
"Traits can not initialize supertypes"
);
trace
.
getErrorHandler
().
genericError
(
node
,
"Traits can not initialize supertypes"
);
...
@@ -639,7 +642,7 @@ public class TopDownAnalyzer {
...
@@ -639,7 +642,7 @@ public class TopDownAnalyzer {
DeclarationDescriptor
declarationDescriptor
=
type
.
getConstructor
().
getDeclarationDescriptor
();
DeclarationDescriptor
declarationDescriptor
=
type
.
getConstructor
().
getDeclarationDescriptor
();
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
declarationDescriptor
;
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
declarationDescriptor
;
if
(
classDescriptor
.
isTrait
())
{
if
(
classDescriptor
.
getClassModifiers
().
isTrait
())
{
trace
.
getErrorHandler
().
genericError
(
call
.
getValueArgumentList
().
getNode
(),
"A trait may not have a constructor"
);
trace
.
getErrorHandler
().
genericError
(
call
.
getValueArgumentList
().
getNode
(),
"A trait may not have a constructor"
);
}
}
}
}
...
@@ -661,13 +664,13 @@ public class TopDownAnalyzer {
...
@@ -661,13 +664,13 @@ public class TopDownAnalyzer {
DeclarationDescriptor
declarationDescriptor
=
supertype
.
getConstructor
().
getDeclarationDescriptor
();
DeclarationDescriptor
declarationDescriptor
=
supertype
.
getConstructor
().
getDeclarationDescriptor
();
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
declarationDescriptor
;
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
declarationDescriptor
;
if
(!
descriptor
.
isTrait
())
{
if
(!
descriptor
.
getClassModifiers
().
isTrait
())
{
if
(
classDescriptor
.
hasConstructors
()
&&
!
ErrorUtils
.
isError
(
classDescriptor
.
getTypeConstructor
())
&&
!
classDescriptor
.
isTrait
())
{
if
(
classDescriptor
.
hasConstructors
()
&&
!
ErrorUtils
.
isError
(
classDescriptor
.
getTypeConstructor
())
&&
!
classDescriptor
.
getClassModifiers
().
isTrait
())
{
trace
.
getErrorHandler
().
genericError
(
specifier
.
getNode
(),
"This type has a constructor, and thus must be initialized here"
);
trace
.
getErrorHandler
().
genericError
(
specifier
.
getNode
(),
"This type has a constructor, and thus must be initialized here"
);
}
}
}
}
else
{
else
{
if
(!
classDescriptor
.
isTrait
())
{
if
(!
classDescriptor
.
getClassModifiers
().
isTrait
())
{
if
(
superclassAppeared
)
{
if
(
superclassAppeared
)
{
trace
.
getErrorHandler
().
genericError
(
specifier
.
getNode
(),
"A trait may extend only one class"
);
trace
.
getErrorHandler
().
genericError
(
specifier
.
getNode
(),
"A trait may extend only one class"
);
}
}
...
@@ -932,7 +935,7 @@ public class TopDownAnalyzer {
...
@@ -932,7 +935,7 @@ public class TopDownAnalyzer {
"Global property can not be abstract"
);
"Global property can not be abstract"
);
return
;
return
;
}
}
if
(!
classDescriptor
.
isAbstract
())
{
if
(!
classDescriptor
.
getClassModifiers
().
isAbstract
())
{
trace
.
getErrorHandler
().
genericError
(
property
.
getModifierList
().
getModifierNode
(
JetTokens
.
ABSTRACT_KEYWORD
),
trace
.
getErrorHandler
().
genericError
(
property
.
getModifierList
().
getModifierNode
(
JetTokens
.
ABSTRACT_KEYWORD
),
"Abstract property "
+
property
.
getName
()
+
" in non-abstract class "
+
classDescriptor
.
getName
());
"Abstract property "
+
property
.
getName
()
+
" in non-abstract class "
+
classDescriptor
.
getName
());
return
;
return
;
...
@@ -953,7 +956,7 @@ public class TopDownAnalyzer {
...
@@ -953,7 +956,7 @@ public class TopDownAnalyzer {
if
(
initializer
==
null
&&
!
trace
.
getBindingContext
().
get
(
BindingContext
.
IS_INITIALIZED
,
propertyDescriptor
))
{
if
(
initializer
==
null
&&
!
trace
.
getBindingContext
().
get
(
BindingContext
.
IS_INITIALIZED
,
propertyDescriptor
))
{
if
(
classDescriptor
==
null
||
(
getter
!=
null
&&
getter
.
getBodyExpression
()
!=
null
)
||
(
setter
!=
null
&&
setter
.
getBodyExpression
()
!=
null
))
{
if
(
classDescriptor
==
null
||
(
getter
!=
null
&&
getter
.
getBodyExpression
()
!=
null
)
||
(
setter
!=
null
&&
setter
.
getBodyExpression
()
!=
null
))
{
trace
.
getErrorHandler
().
genericError
(
nameNode
,
"Property must be initialized"
);
trace
.
getErrorHandler
().
genericError
(
nameNode
,
"Property must be initialized"
);
}
else
if
(!
classDescriptor
.
isTrait
())
{
}
else
if
(!
classDescriptor
.
getClassModifiers
().
isTrait
())
{
trace
.
getErrorHandler
().
genericError
(
nameNode
,
"Property must be initialized or be abstract"
);
trace
.
getErrorHandler
().
genericError
(
nameNode
,
"Property must be initialized or be abstract"
);
}
}
}
}
...
@@ -969,7 +972,7 @@ public class TopDownAnalyzer {
...
@@ -969,7 +972,7 @@ public class TopDownAnalyzer {
PsiElement
nameIdentifier
=
function
.
getNameIdentifier
();
PsiElement
nameIdentifier
=
function
.
getNameIdentifier
();
if
(
containingDescriptor
instanceof
ClassDescriptor
)
{
if
(
containingDescriptor
instanceof
ClassDescriptor
)
{
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
containingDescriptor
;
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
containingDescriptor
;
if
(
functionDescriptor
.
getModifiers
().
isAbstract
()
&&
!
classDescriptor
.
isAbstract
())
{
if
(
functionDescriptor
.
getModifiers
().
isAbstract
()
&&
!
classDescriptor
.
getClassModifiers
().
isAbstract
())
{
trace
.
getErrorHandler
().
genericError
(
function
.
getModifierList
().
getModifierNode
(
JetTokens
.
ABSTRACT_KEYWORD
),
trace
.
getErrorHandler
().
genericError
(
function
.
getModifierList
().
getModifierNode
(
JetTokens
.
ABSTRACT_KEYWORD
),
"Abstract method "
+
function
.
getName
()
+
" in non-abstract class "
+
classDescriptor
.
getName
());
"Abstract method "
+
function
.
getName
()
+
" in non-abstract class "
+
classDescriptor
.
getName
());
}
}
...
...
idea/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
浏览文件 @
dd0b3c8f
...
@@ -97,6 +97,22 @@ public class CallResolver {
...
@@ -97,6 +97,22 @@ public class CallResolver {
if
(
name
==
null
)
return
checkArgumentTypesAndFail
(
trace
,
scope
,
call
);
if
(
name
==
null
)
return
checkArgumentTypesAndFail
(
trace
,
scope
,
call
);
prioritizedTasks
=
FUNCTION_TASK_PRIORITIZER
.
computePrioritizedTasks
(
scope
,
receiverType
,
call
,
name
);
prioritizedTasks
=
FUNCTION_TASK_PRIORITIZER
.
computePrioritizedTasks
(
scope
,
receiverType
,
call
,
name
);
ResolutionTask
.
DescriptorCheckStrategy
abstractConstructorCheck
=
new
ResolutionTask
.
DescriptorCheckStrategy
()
{
@Override
public
<
D
extends
CallableDescriptor
>
boolean
performAdvancedChecks
(
D
descriptor
,
BindingTrace
trace
,
TracingStrategy
tracing
)
{
if
(
descriptor
instanceof
ConstructorDescriptor
)
{
ClassModifiers
modifiers
=
((
ConstructorDescriptor
)
descriptor
).
getContainingDeclaration
().
getClassModifiers
();
if
(
modifiers
.
isAbstract
())
{
tracing
.
reportOverallResolutionError
(
trace
,
"Can not create an instance of an abstract class"
);
return
false
;
}
}
return
true
;
}
};
for
(
ResolutionTask
task
:
prioritizedTasks
)
{
task
.
setCheckingStrategy
(
abstractConstructorCheck
);
}
}
}
else
{
else
{
JetValueArgumentList
valueArgumentList
=
call
.
getValueArgumentList
();
JetValueArgumentList
valueArgumentList
=
call
.
getValueArgumentList
();
...
@@ -384,6 +400,7 @@ public class CallResolver {
...
@@ -384,6 +400,7 @@ public class CallResolver {
if
(
dirty
.
getValue
())
{
if
(
dirty
.
getValue
())
{
dirtyCandidates
.
add
(
candidate
);
dirtyCandidates
.
add
(
candidate
);
}
}
task
.
performAdvancedChecks
(
candidate
,
temporaryTrace
,
tracing
);
}
}
OverloadResolutionResult
<
D
>
result
=
computeResultAndReportErrors
(
trace
,
tracing
,
successfulCandidates
,
failedCandidates
,
dirtyCandidates
,
traces
);
OverloadResolutionResult
<
D
>
result
=
computeResultAndReportErrors
(
trace
,
tracing
,
successfulCandidates
,
failedCandidates
,
dirtyCandidates
,
traces
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/calls/ResolutionTask.java
浏览文件 @
dd0b3c8f
...
@@ -7,8 +7,10 @@ import org.jetbrains.jet.lang.psi.Call;
...
@@ -7,8 +7,10 @@ import org.jetbrains.jet.lang.psi.Call;
import
org.jetbrains.jet.lang.psi.JetExpression
;
import
org.jetbrains.jet.lang.psi.JetExpression
;
import
org.jetbrains.jet.lang.psi.JetTypeProjection
;
import
org.jetbrains.jet.lang.psi.JetTypeProjection
;
import
org.jetbrains.jet.lang.psi.ValueArgument
;
import
org.jetbrains.jet.lang.psi.ValueArgument
;
import
org.jetbrains.jet.lang.resolve.BindingTrace
;
import
org.jetbrains.jet.lang.types.JetType
;
import
org.jetbrains.jet.lang.types.JetType
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
...
@@ -21,6 +23,7 @@ import java.util.List;
...
@@ -21,6 +23,7 @@ import java.util.List;
private
final
List
<
JetTypeProjection
>
typeArguments
;
private
final
List
<
JetTypeProjection
>
typeArguments
;
private
final
List
<?
extends
ValueArgument
>
valueArguments
;
private
final
List
<?
extends
ValueArgument
>
valueArguments
;
private
final
List
<
JetExpression
>
functionLiteralArguments
;
private
final
List
<
JetExpression
>
functionLiteralArguments
;
private
DescriptorCheckStrategy
checkingStrategy
;
public
ResolutionTask
(
public
ResolutionTask
(
@NotNull
Collection
<
Descriptor
>
candidates
,
@NotNull
Collection
<
Descriptor
>
candidates
,
...
@@ -67,5 +70,19 @@ import java.util.List;
...
@@ -67,5 +70,19 @@ import java.util.List;
public
List
<
JetExpression
>
getFunctionLiteralArguments
()
{
public
List
<
JetExpression
>
getFunctionLiteralArguments
()
{
return
functionLiteralArguments
;
return
functionLiteralArguments
;
}
}
public
void
setCheckingStrategy
(
DescriptorCheckStrategy
strategy
)
{
checkingStrategy
=
strategy
;
}
public
boolean
performAdvancedChecks
(
Descriptor
descriptor
,
BindingTrace
trace
,
TracingStrategy
tracing
)
{
if
(
checkingStrategy
!=
null
&&
!
checkingStrategy
.
performAdvancedChecks
(
descriptor
,
trace
,
tracing
))
{
return
false
;
}
return
true
;
}
public
interface
DescriptorCheckStrategy
{
<
D
extends
CallableDescriptor
>
boolean
performAdvancedChecks
(
D
descriptor
,
BindingTrace
trace
,
TracingStrategy
tracing
);
}
}
}
idea/src/org/jetbrains/jet/lang/resolve/java/JavaClassDescriptor.java
浏览文件 @
dd0b3c8f
...
@@ -20,9 +20,10 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
...
@@ -20,9 +20,10 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
private
JavaClassMembersScope
unsubstitutedMemberScope
;
private
JavaClassMembersScope
unsubstitutedMemberScope
;
private
JetType
classObjectType
;
private
JetType
classObjectType
;
private
final
WritableFunctionGroup
constructors
=
new
WritableFunctionGroup
(
"<init>"
);
private
final
WritableFunctionGroup
constructors
=
new
WritableFunctionGroup
(
"<init>"
);
private
boolean
isAbstract
;
private
ClassModifiers
modifiers
;
private
boolean
isOpen
;
// private boolean isAbstract;
private
boolean
isTrait
;
// private boolean isOpen;
// private boolean isTrait;
public
JavaClassDescriptor
(
DeclarationDescriptor
containingDeclaration
)
{
public
JavaClassDescriptor
(
DeclarationDescriptor
containingDeclaration
)
{
super
(
containingDeclaration
);
super
(
containingDeclaration
);
...
@@ -33,9 +34,10 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
...
@@ -33,9 +34,10 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
}
}
public
void
setModifiers
(
boolean
isAbstract
,
boolean
isOpen
,
boolean
isTrait
)
{
public
void
setModifiers
(
boolean
isAbstract
,
boolean
isOpen
,
boolean
isTrait
)
{
this
.
isAbstract
=
isAbstract
;
this
.
modifiers
=
new
ClassModifiers
(
isAbstract
,
isOpen
,
isTrait
);
this
.
isOpen
=
isOpen
;
// this.isAbstract = isAbstract;
this
.
isTrait
=
isTrait
;
// this.isOpen = isOpen;
// this.isTrait = isTrait;
}
}
public
void
setUnsubstitutedMemberScope
(
JavaClassMembersScope
memberScope
)
{
public
void
setUnsubstitutedMemberScope
(
JavaClassMembersScope
memberScope
)
{
...
@@ -129,19 +131,25 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
...
@@ -129,19 +131,25 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
return
false
;
return
false
;
}
}
// @Override
// public boolean isAbstract() {
// return isAbstract;
// }
//
// @Override
// public boolean isOpen() {
// return isOpen;
// }
//
// @Override
// public boolean isTrait() {
// return isTrait;
// }
@Override
@Override
public
boolean
isAbstract
()
{
@NotNull
return
isAbstract
;
public
ClassModifiers
getClassModifiers
()
{
}
return
modifiers
;
@Override
public
boolean
isOpen
()
{
return
isOpen
;
}
@Override
public
boolean
isTrait
()
{
return
isTrait
;
}
}
@Override
@Override
...
...
idea/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
浏览文件 @
dd0b3c8f
...
@@ -125,7 +125,7 @@ public class JavaDescriptorResolver {
...
@@ -125,7 +125,7 @@ public class JavaDescriptorResolver {
classDescriptor
,
classDescriptor
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
Collections
.<
AnnotationDescriptor
>
emptyList
(),
false
);
false
);
constructorDescriptor
.
initialize
(
typeParameters
,
Collections
.<
ValueParameterDescriptor
>
emptyList
());
constructorDescriptor
.
initialize
(
typeParameters
,
Collections
.<
ValueParameterDescriptor
>
emptyList
()
,
MemberModifiers
.
DEFAULT_MODIFIERS
);
constructorDescriptor
.
setReturnType
(
classDescriptor
.
getDefaultType
());
constructorDescriptor
.
setReturnType
(
classDescriptor
.
getDefaultType
());
classDescriptor
.
addConstructor
(
constructorDescriptor
);
classDescriptor
.
addConstructor
(
constructorDescriptor
);
semanticServices
.
getTrace
().
record
(
BindingContext
.
CONSTRUCTOR
,
psiClass
,
constructorDescriptor
);
semanticServices
.
getTrace
().
record
(
BindingContext
.
CONSTRUCTOR
,
psiClass
,
constructorDescriptor
);
...
@@ -137,7 +137,7 @@ public class JavaDescriptorResolver {
...
@@ -137,7 +137,7 @@ public class JavaDescriptorResolver {
classDescriptor
,
classDescriptor
,
Collections
.<
AnnotationDescriptor
>
emptyList
(),
// TODO
Collections
.<
AnnotationDescriptor
>
emptyList
(),
// TODO
false
);
false
);
constructorDescriptor
.
initialize
(
typeParameters
,
resolveParameterDescriptors
(
constructorDescriptor
,
constructor
.
getParameterList
().
getParameters
()));
constructorDescriptor
.
initialize
(
typeParameters
,
resolveParameterDescriptors
(
constructorDescriptor
,
constructor
.
getParameterList
().
getParameters
())
,
MemberModifiers
.
DEFAULT_MODIFIERS
);
constructorDescriptor
.
setReturnType
(
classDescriptor
.
getDefaultType
());
constructorDescriptor
.
setReturnType
(
classDescriptor
.
getDefaultType
());
classDescriptor
.
addConstructor
(
constructorDescriptor
);
classDescriptor
.
addConstructor
(
constructorDescriptor
);
semanticServices
.
getTrace
().
record
(
BindingContext
.
CONSTRUCTOR
,
constructor
,
constructorDescriptor
);
semanticServices
.
getTrace
().
record
(
BindingContext
.
CONSTRUCTOR
,
constructor
,
constructorDescriptor
);
...
@@ -348,7 +348,8 @@ public class JavaDescriptorResolver {
...
@@ -348,7 +348,8 @@ public class JavaDescriptorResolver {
null
,
null
,
resolveTypeParameters
(
functionDescriptorImpl
,
method
.
getTypeParameters
()),
resolveTypeParameters
(
functionDescriptorImpl
,
method
.
getTypeParameters
()),
semanticServices
.
getDescriptorResolver
().
resolveParameterDescriptors
(
functionDescriptorImpl
,
parameters
),
semanticServices
.
getDescriptorResolver
().
resolveParameterDescriptors
(
functionDescriptorImpl
,
parameters
),
semanticServices
.
getTypeTransformer
().
transformToType
(
returnType
)
semanticServices
.
getTypeTransformer
().
transformToType
(
returnType
),
MemberModifiers
.
DEFAULT_MODIFIERS
//TODO
);
);
semanticServices
.
getTrace
().
record
(
BindingContext
.
FUNCTION
,
method
,
functionDescriptorImpl
);
semanticServices
.
getTrace
().
record
(
BindingContext
.
FUNCTION
,
method
,
functionDescriptorImpl
);
FunctionDescriptor
substitutedFunctionDescriptor
=
functionDescriptorImpl
;
FunctionDescriptor
substitutedFunctionDescriptor
=
functionDescriptorImpl
;
...
...
idea/src/org/jetbrains/jet/lang/types/ErrorUtils.java
浏览文件 @
dd0b3c8f
...
@@ -123,7 +123,8 @@ public class ErrorUtils {
...
@@ -123,7 +123,8 @@ public class ErrorUtils {
null
,
null
,
typeParameters
,
typeParameters
,
getValueParameters
(
functionDescriptor
,
positionedValueArgumentTypes
),
getValueParameters
(
functionDescriptor
,
positionedValueArgumentTypes
),
createErrorType
(
"<ERROR FUNCTION RETURN>"
)
createErrorType
(
"<ERROR FUNCTION RETURN>"
),
MemberModifiers
.
DEFAULT_MODIFIERS
);
);
}
}
...
@@ -132,7 +133,8 @@ public class ErrorUtils {
...
@@ -132,7 +133,8 @@ public class ErrorUtils {
null
,
null
,
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
// TODO
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
// TODO
Collections
.<
ValueParameterDescriptor
>
emptyList
(),
// TODO
Collections
.<
ValueParameterDescriptor
>
emptyList
(),
// TODO
createErrorType
(
"<ERROR FUNCTION RETURN TYPE>"
)
createErrorType
(
"<ERROR FUNCTION RETURN TYPE>"
),
MemberModifiers
.
DEFAULT_MODIFIERS
);
);
}
}
...
...
idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
浏览文件 @
dd0b3c8f
...
@@ -932,7 +932,7 @@ public class JetTypeInferrer {
...
@@ -932,7 +932,7 @@ public class JetTypeInferrer {
else
{
else
{
effectiveReceiverType
=
receiverType
;
effectiveReceiverType
=
receiverType
;
}
}
functionDescriptor
.
initialize
(
effectiveReceiverType
,
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
valueParameterDescriptors
,
null
);
functionDescriptor
.
initialize
(
effectiveReceiverType
,
Collections
.<
TypeParameterDescriptor
>
emptyList
(),
valueParameterDescriptors
,
null
,
MemberModifiers
.
DEFAULT_MODIFIERS
);
context
.
trace
.
record
(
BindingContext
.
FUNCTION
,
expression
,
functionDescriptor
);
context
.
trace
.
record
(
BindingContext
.
FUNCTION
,
expression
,
functionDescriptor
);
JetType
returnType
=
NO_EXPECTED_TYPE
;
JetType
returnType
=
NO_EXPECTED_TYPE
;
...
...
idea/src/org/jetbrains/jet/resolve/DescriptorRenderer.java
浏览文件 @
dd0b3c8f
...
@@ -251,7 +251,7 @@ public class DescriptorRenderer {
...
@@ -251,7 +251,7 @@ public class DescriptorRenderer {
@Override
@Override
public
Void
visitClassDescriptor
(
ClassDescriptor
descriptor
,
StringBuilder
builder
)
{
public
Void
visitClassDescriptor
(
ClassDescriptor
descriptor
,
StringBuilder
builder
)
{
String
keyword
=
descriptor
.
isTrait
()
?
"trait class"
:
"class"
;
String
keyword
=
descriptor
.
getClassModifiers
().
isTrait
()
?
"trait class"
:
"class"
;
renderClassDescriptor
(
descriptor
,
builder
,
keyword
);
renderClassDescriptor
(
descriptor
,
builder
,
keyword
);
return
super
.
visitClassDescriptor
(
descriptor
,
builder
);
return
super
.
visitClassDescriptor
(
descriptor
,
builder
);
}
}
...
...
idea/testData/checker/Abstract.jet
浏览文件 @
dd0b3c8f
...
@@ -47,4 +47,22 @@ abstract class <error>A10</error> {
...
@@ -47,4 +47,22 @@ abstract class <error>A10</error> {
<error>abstract</error> val i: Int
<error>abstract</error> val i: Int
<error>abstract</error> fun foo(): fun(Int): Int
<error>abstract</error> fun foo(): fun(Int): Int
val <error>j</error>: Int
val <error>j</error>: Int
fun <error>foo1</error>(): fun(Int): Int
fun <error>foo1</error>(): fun(Int): Int
\ No newline at end of file
//creating an instance
abstract class B1(
val i: Int,
val s: String
) {
}
class B2() : B1(1, "r") {}
abstract class B3(i: Int) {
this(): this(1)
}
fun foo(a: B3) {
val a = <error>B3()</error>
val b = <error>B1(2, "s")</error>
}
idea/testData/checker/BinaryCallsOnNullableValues.jet
浏览文件 @
dd0b3c8f
abstract
class A() {
class A() {
abstract fun equals(a : Any?) : Boolean
fun equals(a : Any?) : Boolean = false
}
}
abstract
class B() {
class B() {
abstract fun equals(a : Any?) : Boolean?
fun equals(a : Any?) : Boolean? = false
}
}
abstract
class C() {
class C() {
abstract fun equals(a : Any?) : Int
fun equals(a : Any?) : Int = 0
}
}
fun f(): Unit {
fun f(): Unit {
...
...
idea/testData/checker/ExtensionFunctions.jet
浏览文件 @
dd0b3c8f
...
@@ -40,9 +40,9 @@ fun Int.foo() = this
...
@@ -40,9 +40,9 @@ fun Int.foo() = this
namespace null_safety {
namespace null_safety {
fun parse(cmd: String): Command? { return null }
fun parse(cmd: String): Command? { return null }
abstract
class Command() {
class Command() {
// fun equals(other : Any?) : Boolean
// fun equals(other : Any?) : Boolean
abstract val foo : Int
val foo : Int = 0
}
}
fun Any.equals(other : Any?) : Boolean = true
fun Any.equals(other : Any?) : Boolean = true
...
...
idea/testData/checker/ForRangeConventions.jet
浏览文件 @
dd0b3c8f
...
@@ -65,16 +65,16 @@ abstract class Range1() {
...
@@ -65,16 +65,16 @@ abstract class Range1() {
abstract fun iterator() : Iterator<Int>
abstract fun iterator() : Iterator<Int>
}
}
fun test() {
fun test(
notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRange4: NotRange4, notRange5: NotRange5, notRange6: NotRange6, notRange7: NotRange7, range0: Range0, range1: Range1
) {
for (i in <error>
NotRange1()
</error>);
for (i in <error>
notRange1
</error>);
for (i in <error>
NotRange2()
</error>);
for (i in <error>
notRange2
</error>);
for (i in <error>
NotRange3()
</error>);
for (i in <error>
notRange3
</error>);
for (i in <error>
NotRange4()
</error>);
for (i in <error>
notRange4
</error>);
for (i in <error>
NotRange5()
</error>);
for (i in <error>
notRange5
</error>);
for (i in <error>
NotRange6()
</error>);
for (i in <error>
notRange6
</error>);
for (i in <error>
NotRange7()
</error>);
for (i in <error>
notRange7
</error>);
for (i in
Range0()
);
for (i in
range0
);
for (i in
Range1()
);
for (i in
range1
);
for (i in (ArrayList<Int>() : List<Int>));
for (i in (ArrayList<Int>() : List<Int>));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录