Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
b8d2e62d
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,发现更多精彩内容 >>
提交
b8d2e62d
编写于
4月 16, 2012
作者:
S
Stepan Koltsov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sometimes descriptor has more than one declaration
上级
81568cdc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
7 deletion
+67
-7
compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java
...c/org/jetbrains/jet/lang/resolve/BindingContextUtils.java
+52
-0
idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java
.../org/jetbrains/jet/plugin/references/JetPsiReference.java
+15
-7
未找到文件。
compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java
浏览文件 @
b8d2e62d
...
...
@@ -16,6 +16,7 @@
package
org.jetbrains.jet.lang.resolve
;
import
com.google.common.collect.Lists
;
import
com.intellij.psi.PsiElement
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
...
...
@@ -31,6 +32,8 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import
org.jetbrains.jet.util.slicedmap.ReadOnlySlice
;
import
org.jetbrains.jet.util.slicedmap.Slices
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
/**
...
...
@@ -83,6 +86,27 @@ public class BindingContextUtils {
return
null
;
}
@NotNull
public
static
List
<
PsiElement
>
resolveToDeclarationPsiElements
(
@NotNull
BindingContext
bindingContext
,
@Nullable
JetReferenceExpression
referenceExpression
)
{
DeclarationDescriptor
declarationDescriptor
=
bindingContext
.
get
(
BindingContext
.
REFERENCE_TARGET
,
referenceExpression
);
if
(
declarationDescriptor
==
null
)
{
return
Lists
.
newArrayList
(
bindingContext
.
get
(
BindingContext
.
LABEL_TARGET
,
referenceExpression
));
}
List
<
PsiElement
>
elements
=
descriptorToDeclarations
(
bindingContext
,
declarationDescriptor
);
if
(
elements
.
size
()
>
0
)
{
return
elements
;
}
// TODO: Need to have a valid stubs for standard classes
if
(
referenceExpression
!=
null
&&
JetStandardClasses
.
getAllStandardClasses
().
contains
(
declarationDescriptor
))
{
return
Lists
.<
PsiElement
>
newArrayList
(
referenceExpression
.
getContainingFile
());
}
return
Lists
.
newArrayList
();
}
@Nullable
public
static
VariableDescriptor
extractVariableDescriptorIfAny
(
@NotNull
BindingContext
bindingContext
,
@Nullable
JetElement
element
,
boolean
onlyReference
)
{
DeclarationDescriptor
descriptor
=
null
;
...
...
@@ -131,6 +155,21 @@ public class BindingContextUtils {
}
}
@NotNull
public
static
List
<
PsiElement
>
descriptorToDeclarations
(
@NotNull
BindingContext
context
,
@NotNull
DeclarationDescriptor
descriptor
)
{
if
(
descriptor
instanceof
CallableMemberDescriptor
)
{
return
callableDescriptorToDeclarations
(
context
,
(
CallableMemberDescriptor
)
descriptor
);
}
else
{
PsiElement
psiElement
=
descriptorToDeclaration
(
context
,
descriptor
);
if
(
psiElement
!=
null
)
{
return
Lists
.
newArrayList
(
psiElement
);
}
else
{
return
Lists
.
newArrayList
();
}
}
}
@Nullable
public
static
PsiElement
callableDescriptorToDeclaration
(
@NotNull
BindingContext
context
,
@NotNull
CallableMemberDescriptor
callable
)
{
if
(
callable
.
getKind
()
!=
CallableMemberDescriptor
.
Kind
.
DECLARATION
)
{
...
...
@@ -148,6 +187,19 @@ public class BindingContextUtils {
return
doGetDescriptorToDeclaration
(
context
,
callable
.
getOriginal
());
}
private
static
List
<
PsiElement
>
callableDescriptorToDeclarations
(
@NotNull
BindingContext
context
,
@NotNull
CallableMemberDescriptor
callable
)
{
if
(
callable
.
getKind
()
!=
CallableMemberDescriptor
.
Kind
.
DECLARATION
)
{
List
<
PsiElement
>
r
=
new
ArrayList
<
PsiElement
>();
Set
<?
extends
CallableMemberDescriptor
>
overridenDescriptors
=
callable
.
getOverriddenDescriptors
();
for
(
CallableMemberDescriptor
overriden
:
overridenDescriptors
)
{
r
.
addAll
(
callableDescriptorToDeclarations
(
context
,
overriden
));
}
return
r
;
}
PsiElement
psiElement
=
doGetDescriptorToDeclaration
(
context
,
callable
);
return
psiElement
!=
null
?
Lists
.
newArrayList
(
psiElement
)
:
Lists
.<
PsiElement
>
newArrayList
();
}
@Nullable
public
static
PsiElement
classDescriptorToDeclaration
(
@NotNull
BindingContext
context
,
@NotNull
ClassDescriptor
clazz
)
{
return
doGetDescriptorToDeclaration
(
context
,
clazz
);
...
...
idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java
浏览文件 @
b8d2e62d
...
...
@@ -33,6 +33,7 @@ import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
static
org
.
jetbrains
.
jet
.
lang
.
resolve
.
BindingContext
.
AMBIGUOUS_REFERENCE_TARGET
;
...
...
@@ -102,9 +103,12 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
protected
PsiElement
doResolve
()
{
JetFile
file
=
(
JetFile
)
getElement
().
getContainingFile
();
BindingContext
bindingContext
=
WholeProjectAnalyzerFacade
.
analyzeProjectWithCacheOnAFile
(
file
).
getBindingContext
();
PsiElement
psiElement
=
BindingContextUtils
.
resolveToDeclarationPsiElement
(
bindingContext
,
myExpression
);
if
(
psiElement
!=
null
)
{
return
psiElement
;
List
<
PsiElement
>
psiElement
=
BindingContextUtils
.
resolveToDeclarationPsiElements
(
bindingContext
,
myExpression
);
if
(
psiElement
.
size
()
==
1
)
{
return
psiElement
.
iterator
().
next
();
}
if
(
psiElement
.
size
()
>
1
)
{
return
null
;
}
Collection
<?
extends
DeclarationDescriptor
>
declarationDescriptors
=
bindingContext
.
get
(
AMBIGUOUS_REFERENCE_TARGET
,
myExpression
);
if
(
declarationDescriptors
!=
null
)
return
null
;
...
...
@@ -123,13 +127,17 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
ArrayList
<
ResolveResult
>
results
=
new
ArrayList
<
ResolveResult
>(
declarationDescriptors
.
size
());
for
(
DeclarationDescriptor
descriptor
:
declarationDescriptors
)
{
PsiElement
element
=
BindingContextUtils
.
descriptorToDeclaration
(
bindingContext
,
descriptor
);
if
(
element
==
null
)
{
List
<
PsiElement
>
elements
=
BindingContextUtils
.
descriptorToDeclarations
(
bindingContext
,
descriptor
);
if
(
element
s
.
isEmpty
()
)
{
// TODO: Need a better resolution for Intrinsic function (KT-975)
element
=
file
;
results
.
add
(
new
PsiElementResolveResult
(
file
,
true
));
}
else
{
for
(
PsiElement
element
:
elements
)
{
results
.
add
(
new
PsiElementResolveResult
(
element
,
true
));
}
}
results
.
add
(
new
PsiElementResolveResult
(
element
,
true
));
}
return
results
.
toArray
(
new
ResolveResult
[
results
.
size
()]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录