Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
e364fe42
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,发现更多精彩内容 >>
提交
e364fe42
编写于
4月 02, 2012
作者:
S
Svetlana Isakova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
public methods in private classes visibility check
上级
ffbce7fe
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
79 addition
and
50 deletion
+79
-50
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
...tbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+1
-0
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibilities.java
.../src/org/jetbrains/jet/lang/descriptors/Visibilities.java
+21
-6
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibility.java
...nd/src/org/jetbrains/jet/lang/descriptors/Visibility.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/resolve/QualifiedExpressionResolver.java
...tbrains/jet/lang/resolve/QualifiedExpressionResolver.java
+24
-41
compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/TaskPrioritizer.java
...org/jetbrains/jet/lang/resolve/calls/TaskPrioritizer.java
+1
-2
compiler/testData/diagnostics/tests/scopes/visibility2.jet
compiler/testData/diagnostics/tests/scopes/visibility2.jet
+31
-0
未找到文件。
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
浏览文件 @
e364fe42
...
...
@@ -446,6 +446,7 @@ public class JavaDescriptorResolver {
classData
.
classDescriptor
.
setSupertypes
(
getSupertypes
(
new
PsiClassWrapper
(
classObjectPsiClass
),
classData
.
classDescriptor
,
new
ArrayList
<
TypeParameterDescriptor
>(
0
)));
classData
.
classDescriptor
.
setName
(
JetPsiUtil
.
NO_NAME_PROVIDED
);
// TODO
classData
.
classDescriptor
.
setModality
(
Modality
.
FINAL
);
classData
.
classDescriptor
.
setVisibility
(
containing
.
getVisibility
());
classData
.
classDescriptor
.
setTypeParameterDescriptors
(
new
ArrayList
<
TypeParameterDescriptor
>(
0
));
classData
.
classDescriptor
.
createTypeConstructor
();
classData
.
classDescriptor
.
setScopeForMemberLookup
(
new
JavaClassMembersScope
(
classData
.
classDescriptor
,
classObjectPsiClass
,
semanticServices
,
false
));
...
...
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibilities.java
浏览文件 @
e364fe42
...
...
@@ -17,6 +17,7 @@
package
org.jetbrains.jet.lang.descriptors
;
import
com.google.common.collect.Sets
;
import
com.intellij.psi.util.PsiTreeUtil
;
import
org.jetbrains.jet.lang.resolve.DescriptorUtils
;
import
java.util.Set
;
...
...
@@ -27,7 +28,7 @@ import java.util.Set;
public
class
Visibilities
{
public
static
final
Visibility
PRIVATE
=
new
Visibility
(
false
)
{
@Override
p
ublic
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
p
rotected
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
DeclarationDescriptor
parent
=
what
;
while
(
parent
!=
null
)
{
parent
=
parent
.
getContainingDeclaration
();
...
...
@@ -41,6 +42,9 @@ public class Visibilities {
if
(
parent
==
fromParent
)
{
return
true
;
}
if
(
fromParent
instanceof
NamespaceDescriptor
)
{
break
;
//'private' package members are not visible for subpackages, so when we reach a package, we should stop
}
fromParent
=
fromParent
.
getContainingDeclaration
();
}
return
false
;
...
...
@@ -49,7 +53,7 @@ public class Visibilities {
public
static
final
Visibility
PROTECTED
=
new
Visibility
(
true
)
{
@Override
p
ublic
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
p
rotected
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
ClassDescriptor
classDescriptor
=
DescriptorUtils
.
getParentOfType
(
what
,
ClassDescriptor
.
class
);
if
(
classDescriptor
==
null
)
return
false
;
...
...
@@ -64,7 +68,7 @@ public class Visibilities {
public
static
final
Visibility
INTERNAL
=
new
Visibility
(
false
)
{
@Override
p
ublic
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
p
rotected
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
ModuleDescriptor
parentModule
=
DescriptorUtils
.
getParentOfType
(
what
,
ModuleDescriptor
.
class
,
false
);
ModuleDescriptor
fromModule
=
DescriptorUtils
.
getParentOfType
(
from
,
ModuleDescriptor
.
class
,
false
);
return
parentModule
==
fromModule
;
...
...
@@ -73,24 +77,35 @@ public class Visibilities {
public
static
final
Visibility
PUBLIC
=
new
Visibility
(
true
)
{
@Override
p
ublic
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
p
rotected
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
return
true
;
}
};
public
static
final
Visibility
INTERNAL_PROTECTED
=
new
Visibility
(
false
)
{
@Override
p
ublic
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
p
rotected
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
return
PROTECTED
.
isVisible
(
what
,
from
)
&&
INTERNAL
.
isVisible
(
what
,
from
);
}
};
public
static
final
Visibility
LOCAL
=
new
Visibility
(
false
)
{
@Override
p
ublic
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
p
rotected
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
return
true
;
}
};
public
static
final
Set
<
Visibility
>
INTERNAL_VISIBILITIES
=
Sets
.
newHashSet
(
PRIVATE
,
INTERNAL
,
INTERNAL_PROTECTED
,
LOCAL
);
public
static
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
)
{
DeclarationDescriptorWithVisibility
parent
=
what
;
while
(
parent
!=
null
)
{
if
(!
parent
.
getVisibility
().
isVisible
(
parent
,
from
))
{
return
false
;
}
parent
=
DescriptorUtils
.
getParentOfType
(
parent
,
DeclarationDescriptorWithVisibility
.
class
);
}
return
true
;
}
}
compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibility.java
浏览文件 @
e364fe42
...
...
@@ -30,5 +30,5 @@ public abstract class Visibility {
return
isPublicAPI
;
}
p
ublic
abstract
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
);
p
rotected
abstract
boolean
isVisible
(
DeclarationDescriptorWithVisibility
what
,
DeclarationDescriptor
from
);
}
compiler/frontend/src/org/jetbrains/jet/lang/resolve/QualifiedExpressionResolver.java
浏览文件 @
e364fe42
...
...
@@ -40,17 +40,15 @@ public class QualifiedExpressionResolver {
@NotNull
public
Collection
<?
extends
DeclarationDescriptor
>
analyseImportReference
(
@NotNull
JetImportDirective
importDirective
,
@NotNull
JetScope
scope
,
@NotNull
BindingTrace
trace
)
{
@NotNull
JetScope
scope
,
@NotNull
BindingTrace
trace
)
{
return
processImportReference
(
importDirective
,
scope
,
Importer
.
DO_NOTHING
,
trace
,
false
);
}
@NotNull
public
Collection
<?
extends
DeclarationDescriptor
>
processImportReference
(
@NotNull
JetImportDirective
importDirective
,
@NotNull
JetScope
scope
,
@NotNull
Importer
importer
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
)
{
@NotNull
JetScope
scope
,
@NotNull
Importer
importer
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
)
{
if
(
importDirective
.
isAbsoluteInRootNamespace
())
{
trace
.
report
(
UNSUPPORTED
.
on
(
importDirective
,
"TypeHierarchyResolver"
));
// TODO
return
Collections
.
emptyList
();
...
...
@@ -95,9 +93,8 @@ public class QualifiedExpressionResolver {
}
private
boolean
canImportMembersFrom
(
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
descriptors
,
@NotNull
JetSimpleNameExpression
reference
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
)
{
@NotNull
JetSimpleNameExpression
reference
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
)
{
if
(
onlyClasses
)
{
return
true
;
}
...
...
@@ -116,9 +113,8 @@ public class QualifiedExpressionResolver {
}
private
boolean
canImportMembersFrom
(
@NotNull
DeclarationDescriptor
descriptor
,
@NotNull
JetSimpleNameExpression
reference
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
)
{
@NotNull
JetSimpleNameExpression
reference
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
)
{
assert
!
onlyClasses
;
if
(
descriptor
instanceof
NamespaceDescriptor
)
{
return
true
;
...
...
@@ -132,8 +128,8 @@ public class QualifiedExpressionResolver {
@NotNull
public
Collection
<?
extends
DeclarationDescriptor
>
lookupDescriptorsForUserType
(
@NotNull
JetUserType
userType
,
@NotNull
JetScope
outerScope
,
@NotNull
BindingTrace
trace
)
{
@NotNull
JetScope
outerScope
,
@NotNull
BindingTrace
trace
)
{
if
(
userType
.
isAbsoluteInRootNamespace
())
{
trace
.
report
(
Errors
.
UNSUPPORTED
.
on
(
userType
,
"package"
));
return
Collections
.
emptyList
();
...
...
@@ -152,10 +148,8 @@ public class QualifiedExpressionResolver {
@NotNull
public
Collection
<?
extends
DeclarationDescriptor
>
lookupDescriptorsForQualifiedExpression
(
@NotNull
JetQualifiedExpression
importedReference
,
@NotNull
JetScope
outerScope
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
storeResult
)
{
@NotNull
JetScope
outerScope
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
storeResult
)
{
JetExpression
receiverExpression
=
importedReference
.
getReceiverExpression
();
Collection
<?
extends
DeclarationDescriptor
>
declarationDescriptors
;
if
(
receiverExpression
instanceof
JetQualifiedExpression
)
{
...
...
@@ -182,10 +176,8 @@ public class QualifiedExpressionResolver {
@NotNull
private
Collection
<?
extends
DeclarationDescriptor
>
lookupSelectorDescriptors
(
@NotNull
JetSimpleNameExpression
selector
,
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
declarationDescriptors
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
storeResult
)
{
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
declarationDescriptors
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
storeResult
)
{
Set
<
SuccessfulLookupResult
>
results
=
Sets
.
newHashSet
();
for
(
DeclarationDescriptor
declarationDescriptor
:
declarationDescriptors
)
{
if
(
declarationDescriptor
instanceof
NamespaceDescriptor
)
{
...
...
@@ -215,11 +207,8 @@ public class QualifiedExpressionResolver {
@NotNull
public
Collection
<?
extends
DeclarationDescriptor
>
lookupDescriptorsForSimpleNameReference
(
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
JetScope
outerScope
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
namespaceLevel
,
boolean
storeResult
)
{
@NotNull
JetScope
outerScope
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
namespaceLevel
,
boolean
storeResult
)
{
LookupResult
lookupResult
=
lookupSimpleNameReference
(
referenceExpression
,
outerScope
,
onlyClasses
,
namespaceLevel
);
if
(
lookupResult
==
LookupResult
.
EMPTY
)
return
Collections
.
emptyList
();
return
filterAndStoreResolutionResult
(
Collections
.
singletonList
((
SuccessfulLookupResult
)
lookupResult
),
referenceExpression
,
trace
,
...
...
@@ -228,9 +217,7 @@ public class QualifiedExpressionResolver {
@NotNull
private
LookupResult
lookupSimpleNameReference
(
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
JetScope
outerScope
,
boolean
onlyClasses
,
boolean
namespaceLevel
)
{
@NotNull
JetScope
outerScope
,
boolean
onlyClasses
,
boolean
namespaceLevel
)
{
String
referencedName
=
referenceExpression
.
getReferencedName
();
if
(
referencedName
==
null
)
{
...
...
@@ -269,10 +256,8 @@ public class QualifiedExpressionResolver {
@NotNull
private
Collection
<?
extends
DeclarationDescriptor
>
filterAndStoreResolutionResult
(
@NotNull
Collection
<
SuccessfulLookupResult
>
lookupResults
,
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
storeResult
)
{
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
BindingTrace
trace
,
boolean
onlyClasses
,
boolean
storeResult
)
{
if
(
lookupResults
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
...
...
@@ -328,10 +313,10 @@ public class QualifiedExpressionResolver {
}
private
void
storeResolutionResult
(
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
descriptors
,
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
canBeImportedDescriptors
,
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
Collection
<
JetScope
>
possibleResolutionScopes
,
@NotNull
BindingTrace
trace
)
{
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
canBeImportedDescriptors
,
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
Collection
<
JetScope
>
possibleResolutionScopes
,
@NotNull
BindingTrace
trace
)
{
assert
canBeImportedDescriptors
.
size
()
<=
descriptors
.
size
();
assert
!
possibleResolutionScopes
.
isEmpty
();
...
...
@@ -378,9 +363,7 @@ public class QualifiedExpressionResolver {
* @return <code>true</code> if method has successfully resolved ambiguity
*/
private
boolean
resolveClassNamespaceAmbiguity
(
@NotNull
Collection
<?
extends
DeclarationDescriptor
>
filteredDescriptors
,
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
JetScope
resolutionScope
,
@NotNull
BindingTrace
trace
)
{
@NotNull
JetSimpleNameExpression
referenceExpression
,
@NotNull
JetScope
resolutionScope
,
@NotNull
BindingTrace
trace
)
{
if
(
filteredDescriptors
.
size
()
==
2
)
{
NamespaceDescriptor
namespaceDescriptor
=
null
;
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/TaskPrioritizer.java
浏览文件 @
e364fe42
...
...
@@ -222,8 +222,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
if
(
call
==
null
)
return
false
;
D
candidateDescriptor
=
call
.
getCandidateDescriptor
();
if
(
ErrorUtils
.
isError
(
candidateDescriptor
))
return
true
;
Visibility
visibility
=
candidateDescriptor
.
getVisibility
();
return
visibility
.
isVisible
(
candidateDescriptor
,
context
.
scope
.
getContainingDeclaration
());
return
Visibilities
.
isVisible
(
candidateDescriptor
,
context
.
scope
.
getContainingDeclaration
());
}
});
if
(
visibleCandidates
.
isEmpty
())
return
;
...
...
compiler/testData/diagnostics/tests/scopes/visibility2.jet
0 → 100644
浏览文件 @
e364fe42
//
FILE
:
a
.
kt
package
a
private
class
A
{
fun
bar
()
{}
}
private
fun
foo
()
{}
fun
makeA
()
=
A
()
//
FILE
:
b
.
kt
package
a
.
b
import
a
.*
fun
test
()
{
val
y
=
makeA
()
y
.<
!UNRESOLVED_REFERENCE!>bar<!>()
<
!UNRESOLVED_REFERENCE!>foo<!>()
}
class
A
{
class
B
{
fun
foo
()
{
val
y
=
makeA
()
//
assure
that
'makeA'
is
visible
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录