Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
783dbdd6
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,发现更多精彩内容 >>
提交
783dbdd6
编写于
5月 23, 2012
作者:
D
Dmitry Jemerov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
index occurrences of superclass names for Kotlin classes
上级
cc0a5326
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
207 addition
and
17 deletion
+207
-17
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
...ler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
+46
-2
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
...iler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
+10
-0
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
...src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
+7
-1
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
...ains/jet/lang/psi/stubs/elements/JetClassElementType.java
+9
-3
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java
...rains/jet/lang/psi/stubs/elements/JetFileElementType.java
+2
-7
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
...etbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
+30
-4
idea/src/META-INF/plugin.xml
idea/src/META-INF/plugin.xml
+1
-0
idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
.../src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
+1
-0
idea/src/org/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
...rg/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
+47
-0
idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
.../jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
+4
-0
idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
+50
-0
未找到文件。
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
浏览文件 @
783dbdd6
...
...
@@ -39,7 +39,7 @@ import java.util.List;
* @author max
*/
public
class
JetClass
extends
JetTypeParameterListOwner
implements
JetClassOrObject
,
JetModifierListOwner
,
StubBasedPsiElement
<
PsiJetClassStub
<?>
>
{
implements
JetClassOrObject
,
JetModifierListOwner
,
StubBasedPsiElement
<
PsiJetClassStub
>
{
private
PsiJetClassStub
stub
;
...
...
@@ -158,7 +158,7 @@ public class JetClass extends JetTypeParameterListOwner
}
@Override
public
PsiJetClassStub
<?>
getStub
()
{
public
PsiJetClassStub
getStub
()
{
// TODO (stubs)
return
null
;
}
...
...
@@ -198,4 +198,48 @@ public class JetClass extends JetTypeParameterListOwner
Collections
.
reverse
(
parts
);
return
StringUtil
.
join
(
parts
,
"."
);
}
/**
* Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
* via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).
*
* @return the list of possible superclass names
*/
@NotNull
public
List
<
String
>
getSuperNames
()
{
final
JetDelegationSpecifierList
delegationSpecifierList
=
getDelegationSpecifierList
();
if
(
delegationSpecifierList
==
null
)
return
Collections
.
emptyList
();
final
List
<
JetDelegationSpecifier
>
specifiers
=
delegationSpecifierList
.
getDelegationSpecifiers
();
if
(
specifiers
.
size
()
==
0
)
return
Collections
.
emptyList
();
List
<
String
>
result
=
new
ArrayList
<
String
>();
for
(
JetDelegationSpecifier
specifier
:
specifiers
)
{
final
JetTypeReference
typeReference
=
specifier
.
getTypeReference
();
if
(
typeReference
!=
null
)
{
final
JetTypeElement
typeElement
=
typeReference
.
getTypeElement
();
if
(
typeElement
instanceof
JetUserType
)
{
final
String
referencedName
=
((
JetUserType
)
typeElement
).
getReferencedName
();
if
(
referencedName
!=
null
)
{
addSuperName
(
result
,
referencedName
);
}
}
}
}
return
result
;
}
private
void
addSuperName
(
List
<
String
>
result
,
String
referencedName
)
{
result
.
add
(
referencedName
);
if
(
getContainingFile
()
instanceof
JetFile
)
{
final
JetImportDirective
directive
=
((
JetFile
)
getContainingFile
()).
findImportByAlias
(
referencedName
);
if
(
directive
!=
null
)
{
JetExpression
reference
=
directive
.
getImportedReference
();
while
(
reference
instanceof
JetDotQualifiedExpression
)
{
reference
=
((
JetDotQualifiedExpression
)
reference
).
getSelectorExpression
();
}
if
(
reference
instanceof
JetSimpleNameExpression
)
{
result
.
add
(((
JetSimpleNameExpression
)
reference
).
getReferencedName
());
}
}
}
}
}
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
浏览文件 @
783dbdd6
...
...
@@ -61,6 +61,16 @@ public class JetFile extends PsiFileBase implements JetDeclarationContainer {
return
PsiTreeUtil
.
getChildrenOfTypeAsList
(
this
,
JetImportDirective
.
class
);
}
@Nullable
public
JetImportDirective
findImportByAlias
(
@NotNull
String
name
)
{
for
(
JetImportDirective
directive
:
getImportDirectives
())
{
if
(
name
.
equals
(
directive
.
getAliasName
()))
{
return
directive
;
}
}
return
null
;
}
// scripts has no namespace header
@Nullable
public
JetNamespaceHeader
getNamespaceHeader
()
{
...
...
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
浏览文件 @
783dbdd6
...
...
@@ -18,13 +18,16 @@ package org.jetbrains.jet.lang.psi.stubs;
import
com.intellij.psi.stubs.StubElement
;
import
org.jetbrains.annotations.NonNls
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.psi.JetClass
;
import
java.util.List
;
/**
* @author Nikolay Krasko
*/
public
interface
PsiJetClassStub
<
T
extends
JetClass
>
extends
StubElement
<
T
>
{
public
interface
PsiJetClassStub
extends
StubElement
<
JetClass
>
{
@NonNls
@Nullable
String
getQualifiedName
();
...
...
@@ -32,6 +35,9 @@ public interface PsiJetClassStub<T extends JetClass> extends StubElement<T> {
@Nullable
String
getName
();
@NotNull
List
<
String
>
getSuperNames
();
boolean
isDeprecated
();
boolean
hasDeprecatedAnnotation
();
}
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
浏览文件 @
783dbdd6
...
...
@@ -62,7 +62,8 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
@Override
public
PsiJetClassStub
createStub
(
@NotNull
JetClass
psi
,
StubElement
parentStub
)
{
FqName
fqName
=
JetPsiUtil
.
getFQName
(
psi
);
return
new
PsiJetClassStubImpl
(
JetStubElementTypes
.
CLASS
,
parentStub
,
fqName
!=
null
?
fqName
.
getFqName
()
:
null
,
psi
.
getName
());
return
new
PsiJetClassStubImpl
(
JetStubElementTypes
.
CLASS
,
parentStub
,
fqName
!=
null
?
fqName
.
getFqName
()
:
null
,
psi
.
getName
(),
psi
.
getSuperNames
());
}
@Override
...
...
@@ -75,9 +76,14 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
public
PsiJetClassStub
deserialize
(
StubInputStream
dataStream
,
StubElement
parentStub
)
throws
IOException
{
final
StringRef
name
=
dataStream
.
readName
();
final
StringRef
qualifiedName
=
dataStream
.
readName
();
final
int
superCount
=
dataStream
.
readVarInt
();
final
StringRef
[]
superNames
=
StringRef
.
createArray
(
superCount
);
for
(
int
i
=
0
;
i
<
superCount
;
i
++)
{
superNames
[
i
]
=
dataStream
.
readName
();
}
final
JetClassElementType
type
=
JetStubElementTypes
.
CLASS
;
final
PsiJetClassStubImpl
classStub
=
new
PsiJetClassStubImpl
(
type
,
parentStub
,
qualifiedName
,
name
);
final
PsiJetClassStubImpl
classStub
=
new
PsiJetClassStubImpl
(
type
,
parentStub
,
qualifiedName
,
name
,
superNames
);
return
classStub
;
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java
浏览文件 @
783dbdd6
...
...
@@ -16,12 +16,7 @@
package
org.jetbrains.jet.lang.psi.stubs.elements
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.lang.Language
;
import
com.intellij.lang.LanguageParserDefinitions
;
import
com.intellij.lang.PsiBuilder
;
import
com.intellij.lang.PsiBuilderFactory
;
import
com.intellij.lang.PsiParser
;
import
com.intellij.lang.*
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.StubBuilder
;
...
...
@@ -43,7 +38,7 @@ import java.io.IOException;
* @author Nikolay Krasko
*/
public
class
JetFileElementType
extends
IStubFileElementType
<
PsiJetFileStub
>
{
public
static
final
int
STUB_VERSION
=
3
;
public
static
final
int
STUB_VERSION
=
4
;
public
JetFileElementType
()
{
super
(
"jet.FILE"
,
JetLanguage
.
INSTANCE
);
...
...
compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
浏览文件 @
783dbdd6
...
...
@@ -19,37 +19,53 @@ package org.jetbrains.jet.lang.psi.stubs.impl;
import
com.intellij.psi.stubs.StubBase
;
import
com.intellij.psi.stubs.StubElement
;
import
com.intellij.util.io.StringRef
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.psi.JetClass
;
import
org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub
;
import
org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author Nikolay Krasko
*/
public
class
PsiJetClassStubImpl
extends
StubBase
<
JetClass
>
implements
PsiJetClassStub
<
JetClass
>
{
public
class
PsiJetClassStubImpl
extends
StubBase
<
JetClass
>
implements
PsiJetClassStub
{
private
final
StringRef
qualifiedName
;
private
final
StringRef
name
;
private
final
StringRef
[]
superNames
;
public
PsiJetClassStubImpl
(
JetClassElementType
type
,
final
StubElement
parent
,
@Nullable
final
String
qualifiedName
,
final
String
name
)
{
final
String
name
,
final
List
<
String
>
superNames
)
{
this
(
type
,
parent
,
StringRef
.
fromString
(
qualifiedName
),
StringRef
.
fromString
(
name
),
wrapStrings
(
superNames
));
}
this
(
type
,
parent
,
StringRef
.
fromString
(
qualifiedName
),
StringRef
.
fromString
(
name
));
private
static
StringRef
[]
wrapStrings
(
List
<
String
>
names
)
{
StringRef
[]
refs
=
new
StringRef
[
names
.
size
()];
for
(
int
i
=
0
;
i
<
names
.
size
();
i
++)
{
refs
[
i
]
=
StringRef
.
fromString
(
names
.
get
(
i
));
}
return
refs
;
}
public
PsiJetClassStubImpl
(
JetClassElementType
type
,
final
StubElement
parent
,
final
StringRef
qualifiedName
,
final
StringRef
name
)
{
final
StringRef
name
,
final
StringRef
[]
superNames
)
{
super
(
parent
,
type
);
this
.
qualifiedName
=
qualifiedName
;
this
.
name
=
name
;
this
.
superNames
=
superNames
;
}
@Override
...
...
@@ -71,4 +87,14 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
public
String
getName
()
{
return
StringRef
.
toString
(
name
);
}
@NotNull
@Override
public
List
<
String
>
getSuperNames
()
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
for
(
StringRef
ref
:
superNames
)
{
result
.
add
(
ref
.
toString
());
}
return
result
;
}
}
idea/src/META-INF/plugin.xml
浏览文件 @
783dbdd6
...
...
@@ -175,6 +175,7 @@
<stubIndex
implementation=
"org.jetbrains.jet.plugin.stubindex.JetShortFunctionNameIndex"
/>
<stubIndex
implementation=
"org.jetbrains.jet.plugin.stubindex.JetExtensionFunctionNameIndex"
/>
<stubIndex
implementation=
"org.jetbrains.jet.plugin.stubindex.JetAllShortFunctionNameIndex"
/>
<stubIndex
implementation=
"org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex"
/>
<contentBasedClassFileProcessor
implementation=
"org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor"
/>
<psi.clsCustomNavigationPolicy
implementation=
"org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy"
/>
...
...
idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
浏览文件 @
783dbdd6
...
...
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction;
*/
public
interface
JetIndexKeys
{
StubIndexKey
<
String
,
JetClassOrObject
>
SHORT_NAME_KEY
=
StubIndexKey
.
createIndexKey
(
"jet.class.shortName"
);
StubIndexKey
<
String
,
JetClassOrObject
>
SUPERCLASS_NAME_KEY
=
StubIndexKey
.
createIndexKey
(
"jet.class.superClassName"
);
StubIndexKey
<
String
,
JetClassOrObject
>
FQN_KEY
=
StubIndexKey
.
createIndexKey
(
"jet.fqn"
);
StubIndexKey
<
String
,
JetNamedFunction
>
TOP_LEVEL_FUNCTION_SHORT_NAME_KEY
=
StubIndexKey
.
createIndexKey
(
"jet.top.level.function.short.name"
);
...
...
idea/src/org/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
0 → 100644
浏览文件 @
783dbdd6
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jetbrains.jet.plugin.stubindex
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.psi.search.GlobalSearchScope
;
import
com.intellij.psi.stubs.StringStubIndexExtension
;
import
com.intellij.psi.stubs.StubIndexKey
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.psi.JetClassOrObject
;
import
java.util.Collection
;
/**
* @author yole
*/
public
class
JetSuperClassIndex
extends
StringStubIndexExtension
<
JetClassOrObject
>
{
private
static
final
JetSuperClassIndex
ourInstance
=
new
JetSuperClassIndex
();
public
static
JetSuperClassIndex
getInstance
()
{
return
ourInstance
;
}
@NotNull
@Override
public
StubIndexKey
<
String
,
JetClassOrObject
>
getKey
()
{
return
JetIndexKeys
.
SUPERCLASS_NAME_KEY
;
}
@Override
public
Collection
<
JetClassOrObject
>
get
(
final
String
s
,
final
Project
project
,
@NotNull
final
GlobalSearchScope
scope
)
{
return
super
.
get
(
s
,
project
,
new
JetSourceFilterScope
(
scope
));
}
}
idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
浏览文件 @
783dbdd6
...
...
@@ -37,6 +37,10 @@ public class StubIndexServiceImpl implements StubIndexService {
if
(
fqn
!=
null
)
{
sink
.
occurrence
(
JetIndexKeys
.
FQN_KEY
,
fqn
);
}
for
(
String
superName
:
stub
.
getSuperNames
())
{
sink
.
occurrence
(
JetIndexKeys
.
SUPERCLASS_NAME_KEY
,
superName
);
}
}
@Override
...
...
idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
0 → 100644
浏览文件 @
783dbdd6
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jetbrains.jet.plugin.stubs
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.testFramework.LightProjectDescriptor
;
import
com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.psi.JetClass
;
import
org.jetbrains.jet.lang.psi.JetDeclaration
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub
;
import
org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes
;
import
org.jetbrains.jet.plugin.JetLightProjectDescriptor
;
import
java.util.List
;
/**
* @author yole
*/
public
class
JetStubsTest
extends
LightCodeInsightFixtureTestCase
{
@NotNull
@Override
protected
LightProjectDescriptor
getProjectDescriptor
()
{
return
JetLightProjectDescriptor
.
INSTANCE
;
}
public
void
testSuperclassNames
()
{
final
PsiFile
psiFile
=
myFixture
.
configureByText
(
"foo.kt"
,
"import java.util.ArrayList as alist\nclass C(): alist() { }"
);
final
List
<
JetDeclaration
>
declarations
=
((
JetFile
)
psiFile
).
getDeclarations
();
final
JetClass
jetClass
=
(
JetClass
)
declarations
.
get
(
0
);
final
PsiJetClassStub
stub
=
JetStubElementTypes
.
CLASS
.
createStub
(
jetClass
,
null
);
final
List
<
String
>
names
=
stub
.
getSuperNames
();
assertSameElements
(
names
,
"ArrayList"
,
"alist"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录