Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
9b403bfb
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,发现更多精彩内容 >>
提交
9b403bfb
编写于
5月 31, 2012
作者:
E
Evgeny Gerashchenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
KT-2111 Highlight Java classes/interfaces/etc in Kotlin code
#KT-2111 fixed
上级
f083c325
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
50 deletion
+45
-50
idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java
...c/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java
+1
-1
idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java
...s/jet/plugin/highlighter/TypeKindHighlightingVisitor.java
+32
-49
idea/testData/highlighter/JavaTypes.kt
idea/testData/highlighter/JavaTypes.kt
+2
-0
idea/tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java
...tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java
+10
-0
未找到文件。
idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java
浏览文件 @
9b403bfb
...
...
@@ -83,7 +83,6 @@ public class JetPsiChecker implements Annotator {
return
new
HighlightingVisitor
[]{
new
SoftKeywordsHighlightingVisitor
(
holder
),
new
LabelsHighlightingVisitor
(
holder
),
new
TypeKindHighlightingVisitor
(
holder
),
};
}
...
...
@@ -92,6 +91,7 @@ public class JetPsiChecker implements Annotator {
new
PropertiesHighlightingVisitor
(
holder
,
bindingContext
),
new
FunctionsHighlightingVisitor
(
holder
,
bindingContext
),
new
VariablesHighlightingVisitor
(
holder
,
bindingContext
),
new
TypeKindHighlightingVisitor
(
holder
,
bindingContext
),
};
}
...
...
idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java
浏览文件 @
9b403bfb
...
...
@@ -21,87 +21,70 @@ import com.intellij.openapi.editor.colors.TextAttributesKey;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiReference
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.l
exer.JetTokens
;
import
org.jetbrains.jet.l
ang.resolve.BindingContext
;
/**
* @author Evgeny Gerashchenko
* @since 3/29/12
*/
class
TypeKindHighlightingVisitor
extends
HighlightingVisitor
{
protected
TypeKindHighlightingVisitor
(
AnnotationHolder
holder
)
{
super
(
holder
);
class
TypeKindHighlightingVisitor
extends
AfterAnalysis
HighlightingVisitor
{
TypeKindHighlightingVisitor
(
AnnotationHolder
holder
,
BindingContext
bindingContext
)
{
super
(
holder
,
bindingContext
);
}
@Override
public
void
visitAnnotationEntry
(
JetAnnotationEntry
annotationEntry
)
{
JetTypeReference
typeReference
=
annotationEntry
.
getTypeReference
();
if
(
typeReference
==
null
)
return
;
JetTypeElement
typeElement
=
typeReference
.
getTypeElement
();
if
(!(
typeElement
instanceof
JetUserType
))
return
;
JetUserType
userType
=
(
JetUserType
)
typeElement
;
if
(
userType
.
getQualifier
()
!=
null
)
return
;
JetSimpleNameExpression
referenceExpression
=
userType
.
getReferenceExpression
();
if
(
referenceExpression
!=
null
)
{
holder
.
createInfoAnnotation
(
referenceExpression
.
getNode
(),
null
).
setTextAttributes
(
JetHighlightingColors
.
ANNOTATION
);
}
}
private
void
visitNameExpression
(
JetExpression
expression
)
{
public
void
visitSimpleNameExpression
(
JetSimpleNameExpression
expression
)
{
PsiReference
ref
=
expression
.
getReference
();
if
(
ref
==
null
)
return
;
if
(
JetPsiChecker
.
isNamesHighlightingEnabled
())
{
PsiElement
target
=
ref
.
resolve
(
);
if
(
target
instanceof
JetClass
)
{
highlightClassByKind
((
JetClass
)
target
,
expression
);
DeclarationDescriptor
referenceTarget
=
bindingContext
.
get
(
BindingContext
.
REFERENCE_TARGET
,
expression
);
if
(
referenceTarget
instanceof
ConstructorDescriptor
)
{
referenceTarget
=
referenceTarget
.
getContainingDeclaration
(
);
}
else
if
(
target
instanceof
JetTypeParameter
)
{
if
(
referenceTarget
instanceof
ClassDescriptor
)
{
highlightClassByKind
((
ClassDescriptor
)
referenceTarget
,
expression
);
}
else
if
(
referenceTarget
instanceof
TypeParameterDescriptor
)
{
JetPsiChecker
.
highlightName
(
holder
,
expression
,
JetHighlightingColors
.
TYPE_PARAMETER
);
}
}
}
@Override
public
void
visitSimpleNameExpression
(
JetSimpleNameExpression
expression
)
{
visitNameExpression
(
expression
);
}
@Override
public
void
visitQualifiedExpression
(
JetQualifiedExpression
expression
)
{
visitNameExpression
(
expression
);
}
@Override
public
void
visitTypeParameter
(
JetTypeParameter
parameter
)
{
PsiElement
identifier
=
parameter
.
getNameIdentifier
();
if
(
identifier
!=
null
)
{
JetPsiChecker
.
highlightName
(
holder
,
identifier
,
JetHighlightingColors
.
TYPE_PARAMETER
);
}
super
.
visitTypeParameter
(
parameter
);
}
@Override
public
void
visitClass
(
JetClass
klass
)
{
PsiElement
identifier
=
klass
.
getNameIdentifier
();
if
(
identifier
!=
null
)
{
highlightClassByKind
(
klass
,
identifier
);
ClassDescriptor
classDescriptor
=
bindingContext
.
get
(
BindingContext
.
CLASS
,
klass
);
if
(
identifier
!=
null
&&
classDescriptor
!=
null
)
{
highlightClassByKind
(
classDescriptor
,
identifier
);
}
super
.
visitClass
(
klass
);
}
private
void
highlightClassByKind
(
@NotNull
JetClass
klass
,
@NotNull
PsiElement
whatToHighlight
)
{
TextAttributesKey
textAttributes
=
JetHighlightingColors
.
CLASS
;
if
(
klass
.
isTrait
())
{
textAttributes
=
JetHighlightingColors
.
TRAIT
;
}
else
{
JetModifierList
modifierList
=
klass
.
getModifierList
();
if
(
modifierList
!=
null
)
{
if
(
modifierList
.
hasModifier
(
JetTokens
.
ANNOTATION_KEYWORD
))
{
textAttributes
=
JetHighlightingColors
.
ANNOTATION
;
}
else
if
(
modifierList
.
hasModifier
(
JetTokens
.
ABSTRACT_KEYWORD
))
{
textAttributes
=
JetHighlightingColors
.
ABSTRACT_CLASS
;
}
}
private
void
highlightClassByKind
(
@NotNull
ClassDescriptor
classDescriptor
,
@NotNull
PsiElement
whatToHighlight
)
{
TextAttributesKey
textAttributes
;
switch
(
classDescriptor
.
getKind
())
{
case
TRAIT:
textAttributes
=
JetHighlightingColors
.
TRAIT
;
break
;
case
ANNOTATION_CLASS:
textAttributes
=
JetHighlightingColors
.
ANNOTATION
;
break
;
default
:
textAttributes
=
classDescriptor
.
getModality
()
==
Modality
.
ABSTRACT
?
JetHighlightingColors
.
ABSTRACT_CLASS
:
JetHighlightingColors
.
CLASS
;
}
JetPsiChecker
.
highlightName
(
holder
,
whatToHighlight
,
textAttributes
);
}
...
...
idea/testData/highlighter/JavaTypes.kt
0 → 100644
浏览文件 @
9b403bfb
<
info
textAttributesKey
=
"KOTLIN_ANNOTATION"
>
Override
<
/
in
fo
>
class
<info text
AttributesKey
=
"KOTLIN_CLASS"
>
TheClass
<
/
in
fo
>
:
<
info
textAttributesKey
=
"KOTLIN_TRAIT"
>
Runnable
<
/
in
fo
>,
<
info
textAttributesKey
=
"KOTLIN_CLASS"
><
info
textAttributesKey
=
"KOTLIN_CONSTRUCTOR"
>
Thread
<
/
in
fo
></
info
>()
{
}
\ No newline at end of file
idea/tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java
浏览文件 @
9b403bfb
...
...
@@ -17,6 +17,7 @@
package
org.jetbrains.jet.plugin
;
import
com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase
;
import
com.intellij.openapi.projectRoots.Sdk
;
import
org.jetbrains.jet.plugin.highlighter.JetPsiChecker
;
/**
...
...
@@ -40,6 +41,15 @@ public class NamesHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest
();
}
public
void
testJavaTypes
()
throws
Exception
{
doTest
();
}
@Override
protected
Sdk
getProjectJDK
()
{
return
PluginTestCaseBase
.
jdkFromIdeaHome
();
}
private
void
doTest
()
throws
Exception
{
doTest
(
getTestName
(
false
)
+
".kt"
,
false
,
true
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录