Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
ae2a4afa
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,发现更多精彩内容 >>
提交
ae2a4afa
编写于
3月 14, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parents checked and fixed
上级
36cd2f3a
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
141 addition
and
25 deletion
+141
-25
idea/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java
idea/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java
+55
-0
idea/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java
idea/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java
+2
-1
idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java
idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java
+2
-0
idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java
...c/org/jetbrains/jet/lang/resolve/BindingTraceContext.java
+6
-0
idea/src/org/jetbrains/jet/lang/resolve/MutableClassDescriptor.java
...rg/jetbrains/jet/lang/resolve/MutableClassDescriptor.java
+2
-1
idea/src/org/jetbrains/jet/lang/resolve/MutableDeclarationDescriptor.java
...brains/jet/lang/resolve/MutableDeclarationDescriptor.java
+5
-7
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+2
-2
idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java
idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java
+8
-2
idea/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
.../jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
+0
-1
idea/src/org/jetbrains/jet/lang/types/DeclarationDescriptorImpl.java
...g/jetbrains/jet/lang/types/DeclarationDescriptorImpl.java
+0
-1
idea/src/org/jetbrains/jet/lang/types/DeclarationDescriptorVisitor.java
...etbrains/jet/lang/types/DeclarationDescriptorVisitor.java
+4
-2
idea/src/org/jetbrains/jet/lang/types/ModuleDescriptor.java
idea/src/org/jetbrains/jet/lang/types/ModuleDescriptor.java
+17
-0
idea/src/org/jetbrains/jet/plugin/JetQuickDocumentationProvider.java
...g/jetbrains/jet/plugin/JetQuickDocumentationProvider.java
+18
-3
idea/src/org/jetbrains/jet/resolve/DescriptorUtil.java
idea/src/org/jetbrains/jet/resolve/DescriptorUtil.java
+20
-5
未找到文件。
idea/src/org/jetbrains/jet/lang/psi/JetNamedDeclaration.java
浏览文件 @
ae2a4afa
package
org.jetbrains.jet.lang.psi
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiNameIdentifierOwner
;
import
com.intellij.psi.PsiReference
;
import
com.intellij.psi.util.PsiTreeUtil
;
import
com.intellij.util.IncorrectOperationException
;
import
org.jetbrains.annotations.NonNls
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -27,6 +30,58 @@ public abstract class JetNamedDeclaration extends JetDeclaration implements PsiN
return
findChildByType
(
JetTokens
.
IDENTIFIER
);
}
@Override
public
PsiReference
getReference
()
{
return
new
PsiReference
()
{
@Override
public
PsiElement
getElement
()
{
return
getNameIdentifier
();
}
@Override
public
TextRange
getRangeInElement
()
{
return
getElement
().
getTextRange
().
shiftRight
(
getElement
().
getTextOffset
());
}
@Override
public
PsiElement
resolve
()
{
return
PsiTreeUtil
.
getParentOfType
(
JetNamedDeclaration
.
this
,
JetFile
.
class
);
}
@NotNull
@Override
public
String
getCanonicalText
()
{
return
"<TBD>"
;
}
@Override
public
PsiElement
handleElementRename
(
String
newElementName
)
throws
IncorrectOperationException
{
throw
new
IncorrectOperationException
();
}
@Override
public
PsiElement
bindToElement
(
@NotNull
PsiElement
element
)
throws
IncorrectOperationException
{
throw
new
IncorrectOperationException
();
}
@Override
public
boolean
isReferenceTo
(
PsiElement
element
)
{
return
resolve
()
==
element
;
}
@NotNull
@Override
public
Object
[]
getVariants
()
{
return
EMPTY_ARRAY
;
}
@Override
public
boolean
isSoft
()
{
return
false
;
}
};
}
@Override
public
PsiElement
setName
(
@NonNls
@NotNull
String
name
)
throws
IncorrectOperationException
{
return
getNameIdentifier
().
replace
(
JetChangeUtil
.
createNameIdentifier
(
getProject
(),
name
));
...
...
idea/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java
浏览文件 @
ae2a4afa
...
...
@@ -8,6 +8,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
import
org.jetbrains.jet.lang.psi.JetNamespace
;
import
org.jetbrains.jet.lang.resolve.java.JavaPackageScope
;
import
org.jetbrains.jet.lang.resolve.java.JavaSemanticServices
;
import
org.jetbrains.jet.lang.types.ModuleDescriptor
;
/**
* @author abreslav
...
...
@@ -26,7 +27,7 @@ public class AnalyzingUtils {
JavaSemanticServices
javaSemanticServices
=
new
JavaSemanticServices
(
project
,
semanticServices
,
bindingTraceContext
);
JetScope
libraryScope
=
semanticServices
.
getStandardLibrary
().
getLibraryScope
();
WritableScope
scope
=
new
WritableScope
(
libraryScope
,
libraryScope
.
getContainingDeclaration
(
));
WritableScope
scope
=
new
WritableScope
(
libraryScope
,
new
ModuleDescriptor
(
"<module>"
));
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("").getMemberScope());
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("java.lang").getMemberScope());
scope
.
importScope
(
new
JavaPackageScope
(
""
,
null
,
javaSemanticServices
));
...
...
idea/src/org/jetbrains/jet/lang/resolve/BindingContext.java
浏览文件 @
ae2a4afa
...
...
@@ -14,6 +14,8 @@ public interface BindingContext {
FunctionDescriptor
getFunctionDescriptor
(
JetFunction
declaration
);
PropertyDescriptor
getPropertyDescriptor
(
JetProperty
declaration
);
DeclarationDescriptor
getDeclarationDescriptor
(
JetDeclaration
declaration
);
Type
getExpressionType
(
JetExpression
expression
);
JetScope
getTopLevelScope
();
...
...
idea/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java
浏览文件 @
ae2a4afa
...
...
@@ -48,6 +48,12 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public
DeclarationDescriptor
getDeclarationDescriptor
(
JetDeclaration
declaration
)
{
return
declarationsToDescriptors
.
get
(
declaration
);
}
public
NamespaceDescriptor
getNamespaceDescriptor
(
JetNamespace
declaration
)
{
return
(
NamespaceDescriptor
)
declarationsToDescriptors
.
get
(
declaration
);
}
...
...
idea/src/org/jetbrains/jet/lang/resolve/MutableClassDescriptor.java
浏览文件 @
ae2a4afa
...
...
@@ -13,7 +13,8 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
private
final
WritableScope
unsubstitutedMemberScope
;
private
TypeConstructor
typeConstructor
;
public
MutableClassDescriptor
(
@NotNull
JetScope
outerScope
)
{
public
MutableClassDescriptor
(
@NotNull
DeclarationDescriptor
containingDeclaration
,
@NotNull
JetScope
outerScope
)
{
super
(
containingDeclaration
);
this
.
unsubstitutedMemberScope
=
new
WritableScope
(
outerScope
,
this
);
}
...
...
idea/src/org/jetbrains/jet/lang/resolve/MutableDeclarationDescriptor.java
浏览文件 @
ae2a4afa
package
org.jetbrains.jet.lang.resolve
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.types.Attribute
;
import
org.jetbrains.jet.lang.types.DeclarationDescriptor
;
import
org.jetbrains.jet.lang.types.DeclarationDescriptorVisitor
;
...
...
@@ -13,7 +12,11 @@ import java.util.List;
*/
public
abstract
class
MutableDeclarationDescriptor
implements
DeclarationDescriptor
{
private
String
name
;
private
DeclarationDescriptor
containingDeclaration
;
private
final
DeclarationDescriptor
containingDeclaration
;
public
MutableDeclarationDescriptor
(
DeclarationDescriptor
containingDeclaration
)
{
this
.
containingDeclaration
=
containingDeclaration
;
}
@Override
public
List
<
Attribute
>
getAttributes
()
{
...
...
@@ -35,16 +38,11 @@ public abstract class MutableDeclarationDescriptor implements DeclarationDescrip
return
this
;
}
@NotNull
@Override
public
DeclarationDescriptor
getContainingDeclaration
()
{
return
containingDeclaration
;
}
public
void
setContainingDeclaration
(
@Nullable
DeclarationDescriptor
containingDeclaration
)
{
this
.
containingDeclaration
=
containingDeclaration
;
}
@Override
public
void
acceptVoid
(
DeclarationDescriptorVisitor
<
Void
,
Void
>
visitor
)
{
accept
(
visitor
,
null
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
浏览文件 @
ae2a4afa
...
...
@@ -58,7 +58,7 @@ public class TopDownAnalyzer {
List
<
JetImportDirective
>
importDirectives
=
namespace
.
getImportDirectives
();
String
name
=
namespace
.
getName
();
NamespaceDescriptor
namespaceDescriptor
=
declaringScope
.
getNamespace
(
name
);
NamespaceDescriptor
namespaceDescriptor
=
declaringScope
.
get
Declared
Namespace
(
name
);
if
(
namespaceDescriptor
==
null
)
{
namespaceDescriptor
=
new
NamespaceDescriptor
(
declaringScope
.
getContainingDeclaration
(),
...
...
@@ -104,7 +104,7 @@ public class TopDownAnalyzer {
}
private
WritableScope
processClass
(
@NotNull
WritableScope
declaringScope
,
JetClass
klass
)
{
MutableClassDescriptor
mutableClassDescriptor
=
new
MutableClassDescriptor
(
declaringScope
);
MutableClassDescriptor
mutableClassDescriptor
=
new
MutableClassDescriptor
(
declaringScope
.
getContainingDeclaration
(),
declaringScope
);
mutableClassDescriptor
.
setName
(
klass
.
getName
());
declaringScope
.
addClassDescriptor
(
mutableClassDescriptor
);
...
...
idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java
浏览文件 @
ae2a4afa
...
...
@@ -216,10 +216,16 @@ public class WritableScope extends JetScopeAdapter {
}
}
@Override
public
NamespaceDescriptor
getNamespace
(
@NotNull
String
name
)
{
public
NamespaceDescriptor
getDeclaredNamespace
(
@NotNull
String
name
)
{
NamespaceDescriptor
namespaceDescriptor
=
getNamespaceDescriptors
().
get
(
name
);
if
(
namespaceDescriptor
!=
null
)
return
namespaceDescriptor
;
return
null
;
}
@Override
public
NamespaceDescriptor
getNamespace
(
@NotNull
String
name
)
{
NamespaceDescriptor
declaredNamespace
=
getDeclaredNamespace
(
name
);
if
(
declaredNamespace
!=
null
)
return
declaredNamespace
;
NamespaceDescriptor
namespace
=
super
.
getNamespace
(
name
);
if
(
namespace
!=
null
)
return
namespace
;
...
...
idea/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java
浏览文件 @
ae2a4afa
...
...
@@ -25,7 +25,6 @@ public class JavaTypeTransformer {
@NotNull
public
Type
transform
(
PsiType
javaType
)
{
System
.
out
.
println
(
"javaType = "
+
javaType
.
getInternalCanonicalText
());
return
javaType
.
accept
(
new
PsiTypeVisitor
<
Type
>()
{
@Override
public
Type
visitClassType
(
PsiClassType
classType
)
{
...
...
idea/src/org/jetbrains/jet/lang/types/DeclarationDescriptorImpl.java
浏览文件 @
ae2a4afa
...
...
@@ -31,7 +31,6 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
return
this
;
}
@NotNull
@Override
public
DeclarationDescriptor
getContainingDeclaration
()
{
return
containingDeclaration
;
...
...
idea/src/org/jetbrains/jet/lang/types/DeclarationDescriptorVisitor.java
浏览文件 @
ae2a4afa
package
org.jetbrains.jet.lang.types
;
import
org.jetbrains.jet.lang.resolve.LazySubstitutingClassDescriptor
;
/**
* @author abreslav
*/
...
...
@@ -25,4 +23,8 @@ public class DeclarationDescriptorVisitor<R, D> {
public
R
visitClassDescriptor
(
ClassDescriptor
descriptor
,
D
data
)
{
return
null
;
}
public
R
visitModuleDeclaration
(
ModuleDescriptor
moduleDescriptor
,
D
data
)
{
return
null
;
}
}
idea/src/org/jetbrains/jet/lang/types/ModuleDescriptor.java
0 → 100644
浏览文件 @
ae2a4afa
package
org.jetbrains.jet.lang.types
;
import
java.util.Collections
;
/**
* @author abreslav
*/
public
class
ModuleDescriptor
extends
DeclarationDescriptorImpl
{
public
ModuleDescriptor
(
String
name
)
{
super
(
null
,
Collections
.<
Attribute
>
emptyList
(),
name
);
}
@Override
public
<
R
,
D
>
R
accept
(
DeclarationDescriptorVisitor
<
R
,
D
>
visitor
,
D
data
)
{
return
visitor
.
visitModuleDeclaration
(
this
,
data
);
}
}
idea/src/org/jetbrains/jet/plugin/JetQuickDocumentationProvider.java
浏览文件 @
ae2a4afa
...
...
@@ -4,11 +4,13 @@ import com.intellij.lang.documentation.QuickDocumentationProvider;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.util.PsiTreeUtil
;
import
org.jetbrains.jet.lang.ErrorHandler
;
import
org.jetbrains.jet.lang.psi.JetDeclaration
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetReferenceExpression
;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.types.DeclarationDescriptor
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
org.jetbrains.jet.resolve.DescriptorUtil
;
/**
...
...
@@ -29,14 +31,27 @@ public class JetQuickDocumentationProvider extends QuickDocumentationProvider {
BindingContext
bindingContext
=
AnalyzingUtils
.
analyzeFile
((
JetFile
)
element
.
getContainingFile
(),
ErrorHandler
.
DO_NOTHING
);
DeclarationDescriptor
declarationDescriptor
=
bindingContext
.
resolveReferenceExpression
(
ref
);
if
(
declarationDescriptor
!=
null
)
{
String
text
=
DescriptorUtil
.
renderPresentableText
(
declarationDescriptor
);
text
=
text
.
replaceAll
(
"<"
,
"<"
);
return
text
;
return
render
(
declarationDescriptor
);
}
return
"Unresolved"
;
}
// if (originalElement.getNode().getElementType() == JetTokens.IDENTIFIER) {
// JetDeclaration declaration = PsiTreeUtil.getParentOfType(originalElement, JetDeclaration.class);
// BindingContext bindingContext = AnalyzingUtils.analyzeFile((JetFile) element.getContainingFile(), ErrorHandler.DO_NOTHING);
// DeclarationDescriptor declarationDescriptor = bindingContext.getDeclarationDescriptor(declaration);
// if (declarationDescriptor != null) {
// return render(declarationDescriptor);
// }
// }
return
"Not a reference"
;
}
private
String
render
(
DeclarationDescriptor
declarationDescriptor
)
{
String
text
=
DescriptorUtil
.
renderPresentableText
(
declarationDescriptor
);
text
=
text
.
replaceAll
(
"<"
,
"<"
);
return
text
;
}
}
idea/src/org/jetbrains/jet/resolve/DescriptorUtil.java
浏览文件 @
ae2a4afa
...
...
@@ -16,13 +16,13 @@ public class DescriptorUtil {
@Override
public
Void
visitPropertyDescriptor
(
PropertyDescriptor
descriptor
,
StringBuilder
builder
)
{
Type
type
=
descriptor
.
getType
();
builder
.
append
(
descriptor
.
getName
(
)).
append
(
" : "
).
append
(
type
);
builder
.
append
(
renderName
(
descriptor
)).
append
(
" : "
).
append
(
type
);
return
super
.
visitPropertyDescriptor
(
descriptor
,
builder
);
}
@Override
public
Void
visitFunctionDescriptor
(
FunctionDescriptor
descriptor
,
StringBuilder
builder
)
{
builder
.
append
(
"fun "
).
append
(
descriptor
.
getName
(
));
builder
.
append
(
"fun "
).
append
(
renderName
(
descriptor
));
List
<
TypeParameterDescriptor
>
typeParameters
=
descriptor
.
getTypeParameters
();
renderTypeParameters
(
typeParameters
,
builder
);
builder
.
append
(
"("
);
...
...
@@ -61,13 +61,13 @@ public class DescriptorUtil {
@Override
public
Void
visitNamespaceDescriptor
(
NamespaceDescriptor
namespaceDescriptor
,
StringBuilder
builder
)
{
builder
.
append
(
"namespace "
).
append
(
namespaceDescriptor
.
getName
(
));
builder
.
append
(
"namespace "
).
append
(
renderName
(
namespaceDescriptor
));
return
super
.
visitNamespaceDescriptor
(
namespaceDescriptor
,
builder
);
}
@Override
public
Void
visitClassDescriptor
(
ClassDescriptor
descriptor
,
StringBuilder
builder
)
{
builder
.
append
(
"class "
).
append
(
descriptor
.
getName
(
));
builder
.
append
(
"class "
).
append
(
renderName
(
descriptor
));
renderTypeParameters
(
descriptor
.
getTypeConstructor
().
getParameters
(),
builder
);
return
super
.
visitClassDescriptor
(
descriptor
,
builder
);
}
...
...
@@ -76,8 +76,23 @@ public class DescriptorUtil {
return
stringBuilder
.
toString
();
}
private
static
StringBuilder
renderName
(
DeclarationDescriptor
descriptor
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
renderName
(
descriptor
,
stringBuilder
);
return
stringBuilder
;
}
private
static
void
renderName
(
DeclarationDescriptor
descriptor
,
StringBuilder
stringBuilder
)
{
DeclarationDescriptor
containingDeclaration
=
descriptor
.
getContainingDeclaration
();
if
(
containingDeclaration
!=
null
)
{
renderName
(
containingDeclaration
,
stringBuilder
);
stringBuilder
.
append
(
"::"
);
}
stringBuilder
.
append
(
descriptor
.
getName
());
}
private
static
void
renderTypeParameter
(
TypeParameterDescriptor
descriptor
,
StringBuilder
builder
)
{
builder
.
append
(
descriptor
.
getName
(
));
builder
.
append
(
renderName
(
descriptor
));
if
(!
descriptor
.
getUpperBounds
().
isEmpty
())
{
Type
bound
=
descriptor
.
getUpperBounds
().
iterator
().
next
();
if
(
bound
!=
JetStandardClasses
.
getAnyType
())
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录