Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
75b23344
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,发现更多精彩内容 >>
提交
75b23344
编写于
2月 27, 2012
作者:
P
pTalanov
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
3fc7e849
4c70d341
变更
67
展开全部
隐藏空白更改
内联
并排
Showing
67 changed file
with
1346 addition
and
267 deletion
+1346
-267
bin/kotlin
bin/kotlin
+2
-2
build.xml
build.xml
+2
-2
compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java
...backend/src/org/jetbrains/jet/codegen/CallableMethod.java
+1
-1
compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java
...backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java
+11
-0
compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java
...ackend/src/org/jetbrains/jet/codegen/FunctionCodegen.java
+8
-0
compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java
compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java
.../org/jetbrains/jet/lang/parsing/JetExpressionParsing.java
+7
-7
compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java
...ontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java
+19
-7
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java
...c/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java
+9
-9
compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java
...d/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java
+22
-18
compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
.../src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/types/checker/TypeCheckingProcedure.java
...tbrains/jet/lang/types/checker/TypeCheckingProcedure.java
+56
-2
compiler/testData/codegen/regressions/kt1345.kt
compiler/testData/codegen/regressions/kt1345.kt
+13
-0
compiler/testData/diagnostics/tests/QualifiedExpressions.jet
compiler/testData/diagnostics/tests/QualifiedExpressions.jet
+1
-1
compiler/testData/diagnostics/tests/subtyping/kt-1457.jet
compiler/testData/diagnostics/tests/subtyping/kt-1457.jet
+8
-0
compiler/testData/psi/Imports_ERR.txt
compiler/testData/psi/Imports_ERR.txt
+15
-21
compiler/testData/psi/PredicateExpression.jet
compiler/testData/psi/PredicateExpression.jet
+0
-3
compiler/testData/psi/PredicateExpression.txt
compiler/testData/psi/PredicateExpression.txt
+0
-26
compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java
compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java
+4
-0
compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java
compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java
+13
-13
compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
...ler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
+18
-3
examples/example-vfs/src/Main.kt
examples/example-vfs/src/Main.kt
+2
-1
examples/example-vfs/src/RefreshQueue.kt
examples/example-vfs/src/RefreshQueue.kt
+5
-5
examples/src/guice-kotlin/guice-kotlin.iws
examples/src/guice-kotlin/guice-kotlin.iws
+97
-91
idea/src/META-INF/plugin.xml
idea/src/META-INF/plugin.xml
+3
-0
idea/src/org/jetbrains/jet/plugin/JetCodeBlockSelectioner.java
...src/org/jetbrains/jet/plugin/JetCodeBlockSelectioner.java
+93
-0
idea/src/org/jetbrains/jet/plugin/JetStatementGroupSelectioner.java
...rg/jetbrains/jet/plugin/JetStatementGroupSelectioner.java
+112
-0
idea/src/org/jetbrains/jet/plugin/completion/handlers/JetFunctionInsertHandler.java
.../plugin/completion/handlers/JetFunctionInsertHandler.java
+1
-1
idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java
...rains/jet/plugin/formatter/JetFormattingModelBuilder.java
+2
-0
idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java
.../org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java
+8
-3
idea/src/org/jetbrains/jet/plugin/references/JetArrayAccessReference.java
...brains/jet/plugin/references/JetArrayAccessReference.java
+2
-1
idea/src/org/jetbrains/jet/plugin/references/JetPackageReference.java
.../jetbrains/jet/plugin/references/JetPackageReference.java
+3
-5
idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java
.../org/jetbrains/jet/plugin/references/JetPsiReference.java
+7
-1
idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.java
...tbrains/jet/plugin/references/JetSimpleNameReference.java
+10
-4
idea/testData/checker/QualifiedExpressions.jet
idea/testData/checker/QualifiedExpressions.jet
+1
-1
idea/testData/wordSelection/Statements.1.kt
idea/testData/wordSelection/Statements.1.kt
+24
-0
idea/testData/wordSelection/Statements.10.kt
idea/testData/wordSelection/Statements.10.kt
+24
-0
idea/testData/wordSelection/Statements.11.kt
idea/testData/wordSelection/Statements.11.kt
+24
-0
idea/testData/wordSelection/Statements.2.kt
idea/testData/wordSelection/Statements.2.kt
+24
-0
idea/testData/wordSelection/Statements.3.kt
idea/testData/wordSelection/Statements.3.kt
+24
-0
idea/testData/wordSelection/Statements.4.kt
idea/testData/wordSelection/Statements.4.kt
+24
-0
idea/testData/wordSelection/Statements.5.kt
idea/testData/wordSelection/Statements.5.kt
+24
-0
idea/testData/wordSelection/Statements.6.kt
idea/testData/wordSelection/Statements.6.kt
+24
-0
idea/testData/wordSelection/Statements.7.kt
idea/testData/wordSelection/Statements.7.kt
+24
-0
idea/testData/wordSelection/Statements.8.kt
idea/testData/wordSelection/Statements.8.kt
+24
-0
idea/testData/wordSelection/Statements.9.kt
idea/testData/wordSelection/Statements.9.kt
+24
-0
idea/testData/wordSelection/Statements.kt
idea/testData/wordSelection/Statements.kt
+24
-0
idea/testData/wordSelection/WhenEntries.1.kt
idea/testData/wordSelection/WhenEntries.1.kt
+24
-0
idea/testData/wordSelection/WhenEntries.2.kt
idea/testData/wordSelection/WhenEntries.2.kt
+24
-0
idea/testData/wordSelection/WhenEntries.3.kt
idea/testData/wordSelection/WhenEntries.3.kt
+24
-0
idea/testData/wordSelection/WhenEntries.4.kt
idea/testData/wordSelection/WhenEntries.4.kt
+24
-0
idea/testData/wordSelection/WhenEntries.5.kt
idea/testData/wordSelection/WhenEntries.5.kt
+24
-0
idea/testData/wordSelection/WhenEntries.6.kt
idea/testData/wordSelection/WhenEntries.6.kt
+24
-0
idea/testData/wordSelection/WhenEntries.kt
idea/testData/wordSelection/WhenEntries.kt
+24
-0
idea/tests/org/jetbrains/jet/WordSelectionTest.java
idea/tests/org/jetbrains/jet/WordSelectionTest.java
+56
-0
idea/tests/org/jetbrains/jet/plugin/quickfix/ImportClassHelperTest.java
.../jetbrains/jet/plugin/quickfix/ImportClassHelperTest.java
+26
-0
kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt
...kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt
+10
-5
kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt
...jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt
+4
-1
kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt
.../jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt
+2
-1
kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt
...src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt
+59
-19
stdlib/ktSrc/JavaIterablesSpecial.kt
stdlib/ktSrc/JavaIterablesSpecial.kt
+37
-1
stdlib/ktSrc/JavaUtil.kt
stdlib/ktSrc/JavaUtil.kt
+6
-2
stdlib/ktSrc/JavaUtilMap.kt
stdlib/ktSrc/JavaUtilMap.kt
+5
-0
stdlib/ktSrc/String.kt
stdlib/ktSrc/String.kt
+2
-0
stdlib/ktSrc/dom/Dom.kt
stdlib/ktSrc/dom/Dom.kt
+63
-7
testlib/test/ListTest.kt
testlib/test/ListTest.kt
+11
-0
testlib/test/dom/DomBuilderTest.kt
testlib/test/dom/DomBuilderTest.kt
+52
-1
未找到文件。
bin/kotlin
浏览文件 @
75b23344
...
...
@@ -8,7 +8,7 @@ die() {
root
=
`
cd
$(
dirname
$0
)
/..
;
pwd
`
ideaRoot
=
for
d
in
/Applications/Nika-
*
.app
;
do
for
d
in
$root
/ideaSDK
/Applications/Nika-
*
.app
;
do
if
[
-d
"
$d
/lib"
]
;
then
ideaRoot
=
"
$d
"
break
...
...
@@ -18,7 +18,7 @@ done
test
-n
"
$ideaRoot
"
||
die
"Idea root not found"
classpath
=
"
$root
/out/production/cli"
classpath
=
"
$classpath
:
$root
/out/production/backend:
$root
/out/production/frontend:
$root
/out/production/frontend.java:
$root
/out/production/jet.as.java.psi"
classpath
=
"
$classpath
:
$root
/out/production/backend:
$root
/out/production/frontend:
$root
/out/production/frontend.java:
$root
/out/production/jet.as.java.psi
:
$root
/out/production/util
"
classpath
=
"
$classpath
:
$root
/out/production/stdlib"
classpath
=
"
$classpath
:
$root
/lib/*:
$ideaRoot
/lib/*:
$ideaRoot
/lib/rt/*"
...
...
build.xml
浏览文件 @
75b23344
...
...
@@ -130,7 +130,7 @@
<target
name=
"testlib"
depends=
"compileTestlib"
>
<mkdir
dir=
"${output}/test-reports"
/>
<junit
printsummary=
"yes"
haltonfailure=
"
no
"
>
<junit
printsummary=
"yes"
haltonfailure=
"
true
"
>
<classpath>
<pathelement
location=
"${kotlin-home}/lib/kotlin-runtime.jar"
/>
<pathelement
location=
"${basedir}/testlib/lib/junit-4.9.jar"
/>
...
...
@@ -148,7 +148,7 @@
</test>
-->
<batchtest
fork=
"yes"
todir=
"${output}/test-reports"
>
<batchtest
fork=
"yes"
todir=
"${output}/test-reports"
haltonerror=
"true"
>
<fileset
dir=
"${output}/classes/testlib"
>
<include
name=
"**/*Test.*"
/>
</fileset>
...
...
compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java
浏览文件 @
75b23344
...
...
@@ -124,7 +124,7 @@ public class CallableMethod implements Callable {
}
public
boolean
isNeedsThis
()
{
return
thisClass
!=
null
;
return
thisClass
!=
null
&&
generateCalleeType
==
null
;
}
public
boolean
isNeedsReceiver
()
{
...
...
compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java
浏览文件 @
75b23344
...
...
@@ -91,6 +91,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
if
(
fd
.
getReceiverParameter
().
exists
())
{
result
.
setNeedsReceiver
(
fd
);
}
result
.
setNeedsThis
(
getInternalType
(
fd
));
result
.
requestGenerateCallee
(
Type
.
getObjectType
(
getInternalClassName
(
fd
)));
return
result
;
}
...
...
@@ -337,6 +338,16 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
}
}
public
static
ClassDescriptor
getInternalType
(
FunctionDescriptor
descriptor
)
{
final
int
paramCount
=
descriptor
.
getValueParameters
().
size
();
if
(
descriptor
.
getReceiverParameter
().
exists
())
{
return
JetStandardClasses
.
getReceiverFunction
(
paramCount
);
}
else
{
return
JetStandardClasses
.
getFunction
(
paramCount
);
}
}
private
void
appendType
(
SignatureWriter
signatureWriter
,
JetType
type
,
char
variance
)
{
signatureWriter
.
visitTypeArgument
(
variance
);
...
...
compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java
浏览文件 @
75b23344
...
...
@@ -431,6 +431,14 @@ public class FunctionCodegen {
private
static
void
checkOverride
(
CodegenContext
owner
,
GenerationState
state
,
ClassBuilder
v
,
Method
jvmSignature
,
FunctionDescriptor
functionDescriptor
,
FunctionDescriptor
overriddenFunction
)
{
Method
method
=
state
.
getTypeMapper
().
mapSignature
(
functionDescriptor
.
getName
(),
functionDescriptor
).
getAsmMethod
();
Method
overriden
=
state
.
getTypeMapper
().
mapSignature
(
overriddenFunction
.
getName
(),
overriddenFunction
.
getOriginal
()).
getAsmMethod
();
if
(
overriddenFunction
.
getModality
()
==
Modality
.
ABSTRACT
)
{
Set
<?
extends
FunctionDescriptor
>
overriddenFunctions
=
overriddenFunction
.
getOverriddenDescriptors
();
for
(
FunctionDescriptor
of
:
overriddenFunctions
)
{
checkOverride
(
owner
,
state
,
v
,
jvmSignature
,
overriddenFunction
,
of
.
getOriginal
());
}
}
if
(
differentMethods
(
method
,
overriden
))
{
int
flags
=
ACC_PUBLIC
|
ACC_BRIDGE
;
// TODO.
...
...
compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java
浏览文件 @
75b23344
...
...
@@ -138,7 +138,7 @@ public interface JetNodeTypes {
JetNodeType
DOT_QUALIFIED_EXPRESSION
=
new
JetNodeType
(
"DOT_QUALIFIED_EXPRESSION"
,
JetDotQualifiedExpression
.
class
);
JetNodeType
HASH_QUALIFIED_EXPRESSION
=
new
JetNodeType
(
"HASH_QUALIFIED_EXPRESSION"
,
JetHashQualifiedExpression
.
class
);
JetNodeType
SAFE_ACCESS_EXPRESSION
=
new
JetNodeType
(
"SAFE_ACCESS_EXPRESSION"
,
JetSafeQualifiedExpression
.
class
);
JetNodeType
PREDICATE_EXPRESSION
=
new
JetNodeType
(
"PREDICATE_EXPRESSION"
,
JetPredicateExpression
.
class
);
//
JetNodeType PREDICATE_EXPRESSION = new JetNodeType("PREDICATE_EXPRESSION", JetPredicateExpression.class);
JetNodeType
OBJECT_LITERAL
=
new
JetNodeType
(
"OBJECT_LITERAL"
,
JetObjectLiteralExpression
.
class
);
JetNodeType
ROOT_NAMESPACE
=
new
JetNodeType
(
"ROOT_NAMESPACE"
,
JetRootNamespaceExpression
.
class
);
...
...
compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java
浏览文件 @
75b23344
...
...
@@ -385,13 +385,13 @@ public class JetExpressionParsing extends AbstractJetParsing {
expression
.
done
(
SAFE_ACCESS_EXPRESSION
);
}
else
if
(
at
(
QUEST
))
{
advance
();
// QUEST
parseCallExpression
();
expression
.
done
(
PREDICATE_EXPRESSION
);
}
//
else if (at(QUEST)) {
//
advance(); // QUEST
//
//
parseCallExpression();
//
//
expression.done(PREDICATE_EXPRESSION);
//
}
// else if (at(HASH)) {
// advance(); // HASH
//
...
...
compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java
浏览文件 @
75b23344
...
...
@@ -207,8 +207,12 @@ public class JetParsing extends AbstractJetParsing {
advance
();
// DOT
reference
=
mark
();
expect
(
IDENTIFIER
,
"Qualified name must be a '.'-separated identifier list"
,
TokenSet
.
create
(
AS_KEYWORD
,
DOT
,
SEMICOLON
));
reference
.
done
(
REFERENCE_EXPRESSION
);
if
(
expect
(
IDENTIFIER
,
"Qualified name must be a '.'-separated identifier list"
,
TokenSet
.
create
(
AS_KEYWORD
,
DOT
,
SEMICOLON
)))
{
reference
.
done
(
REFERENCE_EXPRESSION
);
}
else
{
reference
.
drop
();
}
PsiBuilder
.
Marker
precede
=
qualifiedName
.
precede
();
qualifiedName
.
done
(
DOT_QUALIFIED_EXPRESSION
);
...
...
@@ -817,7 +821,7 @@ public class JetParsing extends AbstractJetParsing {
errorAndAdvance
(
"Expecting 'val' or 'var'"
);
}
boolean
typeParametersDeclared
=
at
(
LT
)
?
parseTypeParameterList
(
TokenSet
.
create
(
IDENTIFIER
,
EQ
,
COLON
,
SEMICOLON
))
:
false
;
boolean
typeParametersDeclared
=
at
(
LT
)
&&
parseTypeParameterList
(
TokenSet
.
create
(
IDENTIFIER
,
EQ
,
COLON
,
SEMICOLON
))
;
TokenSet
propertyNameFollow
=
TokenSet
.
create
(
COLON
,
EQ
,
LBRACE
,
SEMICOLON
,
VAL_KEYWORD
,
VAR_KEYWORD
,
FUN_KEYWORD
,
CLASS_KEYWORD
);
...
...
@@ -1236,8 +1240,11 @@ public class JetParsing extends AbstractJetParsing {
}
PsiBuilder
.
Marker
reference
=
mark
();
expect
(
IDENTIFIER
,
"Expecting type parameter name"
,
TokenSet
.
orSet
(
TokenSet
.
create
(
COLON
,
COMMA
),
TYPE_REF_FIRST
));
reference
.
done
(
REFERENCE_EXPRESSION
);
if
(
expect
(
IDENTIFIER
,
"Expecting type parameter name"
,
TokenSet
.
orSet
(
TokenSet
.
create
(
COLON
,
COMMA
),
TYPE_REF_FIRST
)))
{
reference
.
done
(
REFERENCE_EXPRESSION
);
}
else
{
reference
.
drop
();
}
expect
(
COLON
,
"Expecting ':' before the upper bound"
,
TYPE_REF_FIRST
);
...
...
@@ -1394,8 +1401,13 @@ public class JetParsing extends AbstractJetParsing {
PsiBuilder
.
Marker
reference
=
mark
();
while
(
true
)
{
expect
(
IDENTIFIER
,
"Expecting type name"
,
TokenSet
.
orSet
(
JetExpressionParsing
.
EXPRESSION_FIRST
,
JetExpressionParsing
.
EXPRESSION_FOLLOW
));
reference
.
done
(
REFERENCE_EXPRESSION
);
if
(
expect
(
IDENTIFIER
,
"Expecting type name"
,
TokenSet
.
orSet
(
JetExpressionParsing
.
EXPRESSION_FIRST
,
JetExpressionParsing
.
EXPRESSION_FOLLOW
)))
{
reference
.
done
(
REFERENCE_EXPRESSION
);
}
else
{
reference
.
drop
();
break
;
}
parseTypeArgumentList
(-
1
);
if
(!
at
(
DOT
))
{
...
...
compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java
浏览文件 @
75b23344
...
...
@@ -81,27 +81,27 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
@Nullable
@IfNotParsed
public
String
getReferencedName
()
{
PsiElement
referencedNameElement
=
getReferencedNameElement
();
if
(
referencedNameElement
==
null
)
{
return
null
;
}
String
text
=
referencedNameElement
.
getNode
().
getText
();
String
text
=
getReferencedNameElement
().
getNode
().
getText
();
return
text
!=
null
?
JetPsiUtil
.
unquoteIdentifierOrFieldReference
(
text
)
:
null
;
}
@N
ullable
@IfNotParsed
@N
otNull
public
PsiElement
getReferencedNameElement
()
{
PsiElement
element
=
findChildByType
(
REFERENCE_TOKENS
);
if
(
element
==
null
)
{
element
=
findChildByType
(
JetExpressionParsing
.
ALL_OPERATIONS
);
}
return
element
;
if
(
element
!=
null
)
{
return
element
;
}
return
this
;
}
@Nullable
@IfNotParsed
public
IElementType
getReferencedNameElementType
()
{
PsiElement
element
=
getReferencedNameElement
();
return
element
==
null
?
null
:
element
.
getNode
().
getElementType
();
return
getReferencedNameElement
().
getNode
().
getElementType
();
}
@NotNull
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportsResolver.java
浏览文件 @
75b23344
...
...
@@ -194,27 +194,31 @@ public class ImportsResolver {
}
JetExpression
selectorExpression
=
importedReference
.
getSelectorExpression
();
assert
selectorExpression
instanceof
JetSimpleNameExpression
;
JetSimpleNameExpression
selector
=
(
JetSimpleNameExpression
)
selectorExpression
;
JetSimpleNameExpression
lastReference
=
getLastReference
(
receiverExpression
);
if
(
lastReference
==
null
||
!
canImportMembersFrom
(
declarationDescriptors
,
lastReference
))
{
return
Collections
.
emptyList
();
}
Collection
<?
extends
DeclarationDescriptor
>
result
;
for
(
DeclarationDescriptor
declarationDescriptor
:
declarationDescriptors
)
{
if
(
declarationDescriptor
instanceof
NamespaceDescriptor
)
{
result
=
lookupDescriptorsForSimpleNameReference
(
selector
,
((
NamespaceDescriptor
)
declarationDescriptor
).
getMemberScope
(),
true
);
if
(!
result
.
isEmpty
())
return
result
;
}
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
result
=
lookupObjectMembers
((
ClassDescriptor
)
declarationDescriptor
,
selector
);
if
(!
result
.
isEmpty
())
return
result
;
if
(
selectorExpression
instanceof
JetSimpleNameExpression
)
{
JetSimpleNameExpression
selector
=
(
JetSimpleNameExpression
)
selectorExpression
;
JetSimpleNameExpression
lastReference
=
getLastReference
(
receiverExpression
);
if
(
lastReference
==
null
||
!
canImportMembersFrom
(
declarationDescriptors
,
lastReference
))
{
return
Collections
.
emptyList
();
}
if
(
declarationDescriptor
instanceof
VariableDescriptor
)
{
result
=
lookupVariableMembers
((
VariableDescriptor
)
declarationDescriptor
,
selector
);
if
(!
result
.
isEmpty
())
return
result
;
Collection
<?
extends
DeclarationDescriptor
>
result
;
for
(
DeclarationDescriptor
declarationDescriptor
:
declarationDescriptors
)
{
if
(
declarationDescriptor
instanceof
NamespaceDescriptor
)
{
result
=
lookupDescriptorsForSimpleNameReference
(
selector
,
((
NamespaceDescriptor
)
declarationDescriptor
).
getMemberScope
(),
true
);
if
(!
result
.
isEmpty
())
return
result
;
}
if
(
declarationDescriptor
instanceof
ClassDescriptor
)
{
result
=
lookupObjectMembers
((
ClassDescriptor
)
declarationDescriptor
,
selector
);
if
(!
result
.
isEmpty
())
return
result
;
}
if
(
declarationDescriptor
instanceof
VariableDescriptor
)
{
result
=
lookupVariableMembers
((
VariableDescriptor
)
declarationDescriptor
,
selector
);
if
(!
result
.
isEmpty
())
return
result
;
}
}
}
return
Collections
.
emptyList
();
}
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
浏览文件 @
75b23344
...
...
@@ -31,7 +31,7 @@ import org.jetbrains.jet.lang.types.JetType;
import
org.jetbrains.jet.lang.types.checker.JetTypeChecker
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
org.jetbrains.jet.util.CommonSuppliers
;
import
org.jetbrains.jet.util
.LinkedMultiMap
;
import
com.intellij.util.containers
.LinkedMultiMap
;
import
java.util.*
;
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/checker/TypeCheckingProcedure.java
浏览文件 @
75b23344
...
...
@@ -87,9 +87,11 @@ public class TypeCheckingProcedure {
}
for
(
int
i
=
0
;
i
<
type1Arguments
.
size
();
i
++)
{
TypeParameterDescriptor
typeParameter1
=
constructor1
.
getParameters
().
get
(
i
);
TypeProjection
typeProjection1
=
type1Arguments
.
get
(
i
);
TypeParameterDescriptor
typeParameter2
=
constructor2
.
getParameters
().
get
(
i
);
TypeProjection
typeProjection2
=
type2Arguments
.
get
(
i
);
if
(
typeProjection1
.
getProjectionKind
()
!=
typeProjection2
.
getProjectionKind
(
))
{
if
(
getEffectiveProjectionKind
(
typeParameter1
,
typeProjection1
)
!=
getEffectiveProjectionKind
(
typeParameter2
,
typeProjection2
))
{
return
false
;
}
...
...
@@ -100,6 +102,58 @@ public class TypeCheckingProcedure {
return
true
;
}
private
enum
EnrichedProjectionKind
{
IN
,
OUT
,
INV
,
STAR
;
@NotNull
public
static
EnrichedProjectionKind
fromVariance
(
@NotNull
Variance
variance
)
{
switch
(
variance
)
{
case
INVARIANT:
return
INV
;
case
IN_VARIANCE:
return
IN
;
case
OUT_VARIANCE:
return
OUT
;
}
throw
new
IllegalStateException
(
"Unknown variance"
);
}
}
// If class C<out T> then C<T> and C<out T> mean the same
// out * out = out
// out * in = *
// out * inv = out
//
// in * out = *
// in * in = in
// in * inv = in
//
// inv * out = out
// inv * in = out
// inv * inv = inv
private
EnrichedProjectionKind
getEffectiveProjectionKind
(
@NotNull
TypeParameterDescriptor
typeParameter
,
@NotNull
TypeProjection
typeArgument
)
{
Variance
a
=
typeParameter
.
getVariance
();
Variance
b
=
typeArgument
.
getProjectionKind
();
// If they are not both invariant, let's make b not invariant for sure
if
(
b
==
INVARIANT
)
{
Variance
t
=
a
;
a
=
b
;
b
=
t
;
}
// Opposites yield STAR
if
(
a
==
IN_VARIANCE
&&
b
==
OUT_VARIANCE
)
{
return
EnrichedProjectionKind
.
STAR
;
}
if
(
a
==
OUT_VARIANCE
&&
b
==
IN_VARIANCE
)
{
return
EnrichedProjectionKind
.
STAR
;
}
// If they are not opposite, return b, because b is either equal to a or b is in/out and a is inv
return
EnrichedProjectionKind
.
fromVariance
(
b
);
}
public
boolean
isSubtypeOf
(
@NotNull
JetType
subtype
,
@NotNull
JetType
supertype
)
{
if
(
ErrorUtils
.
isErrorType
(
subtype
)
||
ErrorUtils
.
isErrorType
(
supertype
))
{
return
true
;
...
...
@@ -127,7 +181,7 @@ public class TypeCheckingProcedure {
List
<
TypeProjection
>
subArguments
=
subtype
.
getArguments
();
List
<
TypeProjection
>
superArguments
=
supertype
.
getArguments
();
List
<
TypeParameterDescriptor
>
parameters
=
constructor
.
getParameters
();
for
(
int
i
=
0
,
parametersSize
=
parameters
.
size
();
i
<
parametersSize
;
i
++)
{
for
(
int
i
=
0
;
i
<
parameters
.
size
()
;
i
++)
{
TypeParameterDescriptor
parameter
=
parameters
.
get
(
i
);
...
...
compiler/testData/codegen/regressions/kt1345.kt
0 → 100644
浏览文件 @
75b23344
trait
Creator
<
T
>
{
fun
create
()
:
T
}
class
Actor
(
val
code
:
String
=
"OK"
)
trait
Factory
:
Creator
<
Actor
>
class
MyFactory
()
:
Factory
{
override
fun
create
():
Actor
=
Actor
()
}
fun
box
()
:
String
=
MyFactory
().
create
().
code
\ No newline at end of file
compiler/testData/diagnostics/tests/QualifiedExpressions.jet
浏览文件 @
75b23344
...
...
@@ -7,7 +7,7 @@ fun test(s: String?) {
val
<
!UNUSED_VARIABLE!>d<!>: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!>
val
e
:
String
=
<
!TYPE_MISMATCH!>s?.length<!> ?: "empty"
val
<
!UNUSED_VARIABLE!>f<!>: Int = s?.length ?: b ?: 1
val
<
!UNUSED_VARIABLE!>g<!>:
Int? = e? startsWith("s")
?.length
val
<
!UNUSED_VARIABLE!>g<!>:
Boolean? = e.startsWith("s")//
?.length
}
fun
String
.
startsWith
(<
!UNUSED_PARAMETER!>s<!>: String): Boolean = true
\ No newline at end of file
compiler/testData/diagnostics/tests/subtyping/kt-1457.jet
0 → 100644
浏览文件 @
75b23344
// +JDK
import java.util.ArrayList
class MyListOfPairs<T> : ArrayList<#(T, T)>() { }
fun test() {
MyListOfPairs<Int> : ArrayList<#(Int, Int)>
}
compiler/testData/psi/Imports_ERR.txt
浏览文件 @
75b23344
...
...
@@ -92,9 +92,8 @@ JetFile: Imports_ERR.jet
PsiElement(IDENTIFIER)('foo')
PsiElement(DOT)('.')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiErrorElement:Expecting type name
PsiElement(as)('as')
PsiErrorElement:Expecting type name
PsiElement(as)('as')
PsiWhiteSpace(' ')
ANNOTATION_ENTRY
CONSTRUCTOR_CALLEE
...
...
@@ -122,9 +121,8 @@ JetFile: Imports_ERR.jet
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiErrorElement:Expecting type name
PsiElement(MUL)('*')
PsiErrorElement:Expecting type name
PsiElement(MUL)('*')
PsiWhiteSpace(' ')
PsiErrorElement:Expecting namespace or top level declaration
PsiElement(as)('as')
...
...
@@ -156,9 +154,8 @@ JetFile: Imports_ERR.jet
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiErrorElement:Expecting type name
PsiElement(MUL)('*')
PsiErrorElement:Expecting type name
PsiElement(MUL)('*')
PsiWhiteSpace(' ')
PsiErrorElement:Expecting namespace or top level declaration
PsiElement(as)('as')
...
...
@@ -182,10 +179,9 @@ JetFile: Imports_ERR.jet
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
PsiElement(DOT)('.')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiErrorElement:Qualified name must be a '.'-separated identifier list
<empty list>
PsiErrorElement:Qualified name must be a '.'-separated identifier list
<empty list>
PsiWhiteSpace(' ')
PsiElement(SEMICOLON)(';')
PsiWhiteSpace('\n')
IMPORT_DIRECTIVE
...
...
@@ -199,10 +195,9 @@ JetFile: Imports_ERR.jet
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
PsiElement(DOT)('.')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiErrorElement:Qualified name must be a '.'-separated identifier list
<empty list>
PsiErrorElement:Qualified name must be a '.'-separated identifier list
<empty list>
PsiWhiteSpace(' ')
PsiElement(SEMICOLON)(';')
PsiWhiteSpace('\n')
IMPORT_DIRECTIVE
...
...
@@ -212,10 +207,9 @@ JetFile: Imports_ERR.jet
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
PsiElement(DOT)('.')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiErrorElement:Qualified name must be a '.'-separated identifier list
<empty list>
PsiErrorElement:Qualified name must be a '.'-separated identifier list
<empty list>
PsiWhiteSpace(' ')
PsiElement(as)('as')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('bar')
...
...
compiler/testData/psi/PredicateExpression.jet
已删除
100644 → 0
浏览文件 @
3fc7e849
fun foo() {
a?f.foo
}
\ No newline at end of file
compiler/testData/psi/PredicateExpression.txt
已删除
100644 → 0
浏览文件 @
3fc7e849
JetFile: PredicateExpression.jet
NAMESPACE_HEADER
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
DOT_QUALIFIED_EXPRESSION
PREDICATE_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiElement(QUEST)('?')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('f')
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java
浏览文件 @
75b23344
...
...
@@ -303,4 +303,8 @@ public class ClassGenTest extends CodegenTestCase {
blackBoxFile
(
"regressions/kt633.kt"
);
}
public
void
testKt1345
()
throws
Exception
{
blackBoxFile
(
"regressions/kt1345.kt"
);
}
}
compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java
浏览文件 @
75b23344
...
...
@@ -88,19 +88,19 @@ public class StdlibTest extends CodegenTestCase {
}
//from NamespaceGenTest
public
void
testPredicateOperator
()
throws
Exception
{
loadText
(
"fun foo(s: String) = s?startsWith(\"J\")"
);
final
Method
main
=
generateFunction
();
try
{
assertEquals
(
"JetBrains"
,
main
.
invoke
(
null
,
"JetBrains"
));
assertNull
(
main
.
invoke
(
null
,
"IntelliJ"
));
}
catch
(
Throwable
t
)
{
// System.out.println(generateToText());
t
.
printStackTrace
();
throw
t
instanceof
Exception
?
(
Exception
)
t
:
new
RuntimeException
(
t
);
}
}
//
public void testPredicateOperator() throws Exception {
//
loadText("fun foo(s: String) = s?startsWith(\"J\")");
//
final Method main = generateFunction();
//
try {
//
assertEquals("JetBrains", main.invoke(null, "JetBrains"));
//
assertNull(main.invoke(null, "IntelliJ"));
//
} catch (Throwable t) {
//
//
System.out.println(generateToText());
//
t.printStackTrace();
//
throw t instanceof Exception ? (Exception)t : new RuntimeException(t);
//
}
//
}
//
public
void
testForInString
()
throws
Exception
{
loadText
(
"fun foo() : Int { var sum = 0\n"
+
" for(c in \"239\")\n"
+
...
...
compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java
浏览文件 @
75b23344
...
...
@@ -460,9 +460,9 @@ public class JetTypeCheckerTest extends JetLiteFixture {
assertType
(
"true && false"
,
"Boolean"
);
assertType
(
"true || false"
,
"Boolean"
);
assertType
(
"null ?: false"
,
"Boolean"
);
assertType
(
"WithPredicate()?isValid()"
,
"WithPredicate?"
);
assertType
(
"WithPredicate()?isValid(1)"
,
"WithPredicate?"
);
assertType
(
"WithPredicate()?p"
,
"WithPredicate?"
);
//
assertType("WithPredicate()?isValid()", "WithPredicate?");
//
assertType("WithPredicate()?isValid(1)", "WithPredicate?");
//
assertType("WithPredicate()?p", "WithPredicate?");
}
public
void
testSupertypes
()
throws
Exception
{
...
...
@@ -471,6 +471,21 @@ public class JetTypeCheckerTest extends JetLiteFixture {
assertSupertypes
(
"Derived1_inT<Int>"
,
"Derived_T<Int>"
,
"Base_T<Int>"
,
"Any"
,
"Base_inT<Int>"
);
}
public
void
testEffectiveProjectionKinds
()
throws
Exception
{
assertSubtype
(
"Tuple1<Int>"
,
"Tuple1<Int>"
);
assertSubtype
(
"Tuple1<out Int>"
,
"Tuple1<out Int>"
);
assertSubtype
(
"Tuple1<out Int>"
,
"Tuple1<Int>"
);
assertSubtype
(
"Tuple1<Int>"
,
"Tuple1<out Int>"
);
assertSubtype
(
"Tuple1<in Int>"
,
"Tuple1<out Any?>"
);
assertSubtype
(
"Tuple1<out Any?>"
,
"Tuple1<in String>"
);
assertSubtype
(
"Base_inT<Int>"
,
"Base_inT<Int>"
);
assertSubtype
(
"Base_inT<in Int>"
,
"Base_inT<in Int>"
);
assertSubtype
(
"Base_inT<in Int>"
,
"Base_inT<Int>"
);
assertSubtype
(
"Base_inT<Int>"
,
"Base_inT<in Int>"
);
assertSubtype
(
"Base_inT<out Int>"
,
"Base_inT<out Any?>"
);
assertSubtype
(
"Base_inT<out Any?>"
,
"Base_inT<out Int>"
);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private
void
assertSupertypes
(
String
typeStr
,
String
...
supertypeStrs
)
{
...
...
examples/example-vfs/src/Main.kt
浏览文件 @
75b23344
...
...
@@ -26,7 +26,8 @@ fun main(args : Array<String>) {
FileSystem
.
addVirtualFileListener
{
event
->
println
(
event
)
if
(
event
is
VirtualFileChangedEvent
)
{
println
(
"new file size is ${event.file.size()}"
)
// FIXME explicit type casting to avoid overload ambiguity (KT-1461)
println
(
"new file size is ${(event as VirtualFileChangedEvent).file.size()}"
)
}
}
...
...
examples/example-vfs/src/RefreshQueue.kt
浏览文件 @
75b23344
...
...
@@ -50,9 +50,12 @@ internal object RefreshQueue {
/* Checks for changes in virtual file recursively, notifying listeners. */
private
fun
refreshFile
(
file
:
VirtualFile
)
{
FileSystem
.
assertCanWrite
()
val
fileInfo
=
FileSystem
.
fileToInfo
[
file
.
path
]
assert
(
fileInfo
!=
null
)
if
(
fileInfo
==
null
)
{
return
}
if
(
file
.
isDirectory
())
{
val
fileToInfo
=
FileSystem
.
fileToInfo
val
fileInfo
=
fileToInfo
[
file
.
path
]
val
oldChildren
=
fileInfo
.
children
val
newChildren
=
file
.
children
()
...
...
@@ -69,9 +72,6 @@ internal object RefreshQueue {
commonChildren
.
foreach
{
refreshFile
(
it
)
}
}
else
{
val
fileInfo
=
FileSystem
.
fileToInfo
[
file
.
path
]
assert
(
fileInfo
!=
null
)
val
newModificationTime
=
file
.
modificationTime
()
if
(
fileInfo
.
lastModified
!=
newModificationTime
)
{
fileInfo
.
lastModified
=
newModificationTime
...
...
examples/src/guice-kotlin/guice-kotlin.iws
浏览文件 @
75b23344
此差异已折叠。
点击以展开。
idea/src/META-INF/plugin.xml
浏览文件 @
75b23344
...
...
@@ -128,6 +128,9 @@
<annotator
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.annotations.JetPsiChecker"
/>
<annotator
language=
"jet"
implementationClass=
"org.jetbrains.jet.plugin.annotations.DebugInfoAnnotator"
/>
<extendWordSelectionHandler
implementation=
"org.jetbrains.jet.plugin.JetStatementGroupSelectioner"
/>
<extendWordSelectionHandler
implementation=
"org.jetbrains.jet.plugin.JetCodeBlockSelectioner"
/>
<documentationProvider
implementation=
"org.jetbrains.jet.plugin.JetQuickDocumentationProvider"
/>
<configurationType
implementation=
"org.jetbrains.jet.plugin.run.JetRunConfigurationType"
/>
<configurationProducer
implementation=
"org.jetbrains.jet.plugin.run.JetRunConfigurationProducer"
/>
...
...
idea/src/org/jetbrains/jet/plugin/JetCodeBlockSelectioner.java
0 → 100644
浏览文件 @
75b23344
/*
* Copyright 2000-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
;
import
com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner
;
import
com.intellij.lang.ASTNode
;
import
com.intellij.openapi.editor.Editor
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiWhiteSpace
;
import
com.intellij.psi.impl.source.tree.LeafPsiElement
;
import
org.jetbrains.jet.lang.psi.JetBlockExpression
;
import
org.jetbrains.jet.lang.psi.JetWhenExpression
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Originally from IDEA platform: CodeBlockOrInitializerSelectioner
*/
public
class
JetCodeBlockSelectioner
extends
BasicSelectioner
{
public
boolean
canSelect
(
PsiElement
e
)
{
return
e
instanceof
JetBlockExpression
||
e
instanceof
JetWhenExpression
;
}
public
List
<
TextRange
>
select
(
PsiElement
e
,
CharSequence
editorText
,
int
cursorOffset
,
Editor
editor
)
{
List
<
TextRange
>
result
=
new
ArrayList
<
TextRange
>();
ASTNode
[]
children
=
e
.
getNode
().
getChildren
(
null
);
int
start
=
findOpeningBrace
(
children
);
int
end
=
findClosingBrace
(
children
,
start
);
result
.
add
(
e
.
getTextRange
());
result
.
addAll
(
expandToWholeLine
(
editorText
,
new
TextRange
(
start
,
end
)));
return
result
;
}
public
static
int
findOpeningBrace
(
ASTNode
[]
children
)
{
int
start
=
children
[
children
.
length
-
1
].
getTextRange
().
getStartOffset
();
for
(
int
i
=
0
;
i
<
children
.
length
;
i
++)
{
PsiElement
child
=
children
[
i
].
getPsi
();
if
(
child
instanceof
LeafPsiElement
)
{
if
(((
LeafPsiElement
)
child
).
getElementType
()
==
JetTokens
.
LBRACE
)
{
int
j
=
i
+
1
;
while
(
children
[
j
]
instanceof
PsiWhiteSpace
)
{
j
++;
}
start
=
children
[
j
].
getTextRange
().
getStartOffset
();
}
}
}
return
start
;
}
public
static
int
findClosingBrace
(
ASTNode
[]
children
,
int
startOffset
)
{
int
end
=
children
[
children
.
length
-
1
].
getTextRange
().
getEndOffset
();
for
(
int
i
=
0
;
i
<
children
.
length
;
i
++)
{
PsiElement
child
=
children
[
i
].
getPsi
();
if
(
child
instanceof
LeafPsiElement
)
{
if
(((
LeafPsiElement
)
child
).
getElementType
()
==
JetTokens
.
RBRACE
)
{
int
j
=
i
-
1
;
while
(
children
[
j
]
instanceof
PsiWhiteSpace
&&
children
[
j
].
getTextRange
().
getStartOffset
()
>
startOffset
)
{
j
--;
}
end
=
children
[
j
].
getTextRange
().
getEndOffset
();
}
}
}
return
end
;
}
}
idea/src/org/jetbrains/jet/plugin/JetStatementGroupSelectioner.java
0 → 100644
浏览文件 @
75b23344
/*
* Copyright 2000-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
;
import
com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner
;
import
com.intellij.openapi.editor.Editor
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.openapi.util.text.LineTokenizer
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiWhiteSpace
;
import
com.intellij.psi.impl.source.tree.LeafPsiElement
;
import
org.jetbrains.jet.lang.psi.JetBlockExpression
;
import
org.jetbrains.jet.lang.psi.JetExpression
;
import
org.jetbrains.jet.lang.psi.JetWhenEntry
;
import
org.jetbrains.jet.lang.psi.JetWhenExpression
;
import
org.jetbrains.jet.lexer.JetTokens
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Originally from IDEA platform: StatementGroupSelectioner
*/
public
class
JetStatementGroupSelectioner
extends
BasicSelectioner
{
public
boolean
canSelect
(
PsiElement
e
)
{
return
e
instanceof
JetExpression
||
e
instanceof
JetWhenEntry
;
}
public
List
<
TextRange
>
select
(
PsiElement
e
,
CharSequence
editorText
,
int
cursorOffset
,
Editor
editor
)
{
List
<
TextRange
>
result
=
new
ArrayList
<
TextRange
>();
PsiElement
parent
=
e
.
getParent
();
if
(!(
parent
instanceof
JetBlockExpression
)
&&
!(
parent
instanceof
JetWhenExpression
))
{
return
result
;
}
PsiElement
startElement
=
e
;
PsiElement
endElement
=
e
;
while
(
startElement
.
getPrevSibling
()
!=
null
)
{
PsiElement
sibling
=
startElement
.
getPrevSibling
();
if
(
sibling
instanceof
LeafPsiElement
)
{
if
(((
LeafPsiElement
)
sibling
).
getElementType
()
==
JetTokens
.
LBRACE
)
{
break
;
}
}
if
(
sibling
instanceof
PsiWhiteSpace
)
{
PsiWhiteSpace
whiteSpace
=
(
PsiWhiteSpace
)
sibling
;
String
[]
strings
=
LineTokenizer
.
tokenize
(
whiteSpace
.
getText
().
toCharArray
(),
false
);
if
(
strings
.
length
>
2
)
{
break
;
}
}
startElement
=
sibling
;
}
while
(
startElement
instanceof
PsiWhiteSpace
)
{
startElement
=
startElement
.
getNextSibling
();
}
while
(
endElement
.
getNextSibling
()
!=
null
)
{
PsiElement
sibling
=
endElement
.
getNextSibling
();
if
(
sibling
instanceof
LeafPsiElement
)
{
if
(((
LeafPsiElement
)
sibling
).
getElementType
()
==
JetTokens
.
RBRACE
)
{
break
;
}
}
if
(
sibling
instanceof
PsiWhiteSpace
)
{
PsiWhiteSpace
whiteSpace
=
(
PsiWhiteSpace
)
sibling
;
String
[]
strings
=
LineTokenizer
.
tokenize
(
whiteSpace
.
getText
().
toCharArray
(),
false
);
if
(
strings
.
length
>
2
)
{
break
;
}
}
endElement
=
sibling
;
}
while
(
endElement
instanceof
PsiWhiteSpace
)
{
endElement
=
endElement
.
getPrevSibling
();
}
result
.
addAll
(
expandToWholeLine
(
editorText
,
new
TextRange
(
startElement
.
getTextRange
().
getStartOffset
(),
endElement
.
getTextRange
().
getEndOffset
())));
return
result
;
}
}
idea/src/org/jetbrains/jet/plugin/completion/handlers/JetFunctionInsertHandler.java
浏览文件 @
75b23344
...
...
@@ -90,7 +90,7 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
// Insert () if it's not already exist
document
.
insertString
(
endOffset
,
"()"
);
bothParentheses
=
true
;
}
else
if
(
endOffset
+
1
<
documentText
.
length
()
&&
documentText
.
charAt
(
endOffset
)
==
')'
)
{
}
else
if
(
endOffset
+
1
<
documentText
.
length
()
&&
documentText
.
charAt
(
endOffset
+
1
)
==
')'
)
{
bothParentheses
=
true
;
}
...
...
idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java
浏览文件 @
75b23344
...
...
@@ -44,6 +44,8 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
private
static
SpacingBuilder
createSpacingBuilder
(
CodeStyleSettings
settings
)
{
return
new
SpacingBuilder
(
settings
)
.
after
(
NAMESPACE_HEADER
).
blankLines
(
1
)
.
before
(
IMPORT_DIRECTIVE
).
lineBreakInCode
()
.
between
(
IMPORT_DIRECTIVE
,
CLASS
).
blankLines
(
1
)
.
between
(
IMPORT_DIRECTIVE
,
FUN
).
blankLines
(
1
)
...
...
idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java
浏览文件 @
75b23344
...
...
@@ -89,9 +89,14 @@ public class ImportClassHelper {
}
else
{
List
<
JetDeclaration
>
declarations
=
file
.
getDeclarations
();
assert
!
declarations
.
isEmpty
();
JetDeclaration
firstDeclaration
=
declarations
.
iterator
().
next
();
firstDeclaration
.
getParent
().
addBefore
(
newDirective
,
firstDeclaration
);
if
(!
declarations
.
isEmpty
())
{
JetDeclaration
firstDeclaration
=
declarations
.
iterator
().
next
();
firstDeclaration
.
getParent
().
addBefore
(
newDirective
,
firstDeclaration
);
}
else
{
file
.
getNamespaceHeader
().
getParent
().
addAfter
(
newDirective
,
file
.
getNamespaceHeader
());
}
}
}
...
...
idea/src/org/jetbrains/jet/plugin/references/JetArrayAccessReference.java
浏览文件 @
75b23344
...
...
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.references;
import
com.intellij.lang.ASTNode
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.psi.*
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.descriptors.FunctionDescriptor
;
import
org.jetbrains.jet.lang.psi.JetArrayAccessExpression
;
import
org.jetbrains.jet.lang.psi.JetContainerNode
;
...
...
@@ -44,7 +45,7 @@ class JetArrayAccessReference extends JetPsiReference implements MultiRangeRefer
return
indicesNode
==
null
?
PsiReference
.
EMPTY_ARRAY
:
new
PsiReference
[]
{
new
JetArrayAccessReference
(
expression
)
};
}
public
JetArrayAccessReference
(
JetArrayAccessExpression
expression
)
{
public
JetArrayAccessReference
(
@NotNull
JetArrayAccessExpression
expression
)
{
super
(
expression
);
this
.
expression
=
expression
;
}
...
...
idea/src/org/jetbrains/jet/plugin/references/JetPackageReference.java
浏览文件 @
75b23344
...
...
@@ -17,7 +17,6 @@
package
org.jetbrains.jet.plugin.references
;
import
com.intellij.openapi.util.TextRange
;
import
com.intellij.psi.PsiElement
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.compiler.TipsManager
;
import
org.jetbrains.jet.lang.psi.JetFile
;
...
...
@@ -33,7 +32,7 @@ public class JetPackageReference extends JetPsiReference {
private
JetNamespaceHeader
packageExpression
;
public
JetPackageReference
(
JetNamespaceHeader
expression
)
{
public
JetPackageReference
(
@NotNull
JetNamespaceHeader
expression
)
{
super
(
expression
);
packageExpression
=
expression
;
}
...
...
@@ -48,11 +47,10 @@ public class JetPackageReference extends JetPsiReference {
bindingContext
,
TipsManager
.
getReferenceVariants
(
packageExpression
,
bindingContext
));
}
@NotNull
@Override
public
TextRange
getRangeInElement
()
{
PsiElement
element
=
getElement
();
if
(
element
==
null
)
return
null
;
return
new
TextRange
(
0
,
element
.
getTextLength
());
return
new
TextRange
(
0
,
getElement
().
getTextLength
());
}
@NotNull
...
...
idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java
浏览文件 @
75b23344
...
...
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiPolyVariantReference;
import
com.intellij.psi.ResolveResult
;
import
com.intellij.util.IncorrectOperationException
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetReferenceExpression
;
...
...
@@ -36,12 +37,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_
import
static
org
.
jetbrains
.
jet
.
lang
.
resolve
.
BindingContext
.
DESCRIPTOR_TO_DECLARATION
;
public
abstract
class
JetPsiReference
implements
PsiPolyVariantReference
{
@NotNull
protected
final
JetReferenceExpression
myExpression
;
protected
JetPsiReference
(
JetReferenceExpression
expression
)
{
protected
JetPsiReference
(
@NotNull
JetReferenceExpression
expression
)
{
this
.
myExpression
=
expression
;
}
@NotNull
@Override
public
PsiElement
getElement
()
{
return
myExpression
;
...
...
@@ -69,6 +73,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
throw
new
IncorrectOperationException
();
}
@NotNull
@Override
public
PsiElement
bindToElement
(
@NotNull
PsiElement
element
)
throws
IncorrectOperationException
{
throw
new
IncorrectOperationException
();
...
...
@@ -90,6 +95,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
return
false
;
}
@Nullable
protected
PsiElement
doResolve
()
{
JetFile
file
=
(
JetFile
)
getElement
().
getContainingFile
();
BindingContext
bindingContext
=
WholeProjectAnalyzerFacade
.
analyzeProjectWithCacheOnAFile
(
file
);
...
...
idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.java
浏览文件 @
75b23344
...
...
@@ -33,23 +33,29 @@ import org.jetbrains.jet.plugin.completion.DescriptorLookupConverter;
*/
public
class
JetSimpleNameReference
extends
JetPsiReference
{
@NotNull
private
final
JetSimpleNameExpression
myExpression
;
public
JetSimpleNameReference
(
JetSimpleNameExpression
jetSimpleNameExpression
)
{
public
JetSimpleNameReference
(
@NotNull
JetSimpleNameExpression
jetSimpleNameExpression
)
{
super
(
jetSimpleNameExpression
);
myExpression
=
jetSimpleNameExpression
;
}
@NotNull
@Override
public
PsiElement
getElement
()
{
return
myExpression
.
getReferencedNameElement
();
}
@NotNull
public
JetSimpleNameExpression
getExpression
()
{
return
myExpression
;
}
@NotNull
@Override
public
TextRange
getRangeInElement
()
{
PsiElement
element
=
getElement
();
if
(
element
==
null
)
return
null
;
return
new
TextRange
(
0
,
element
.
getTextLength
());
return
new
TextRange
(
0
,
getElement
().
getTextLength
());
}
@NotNull
...
...
idea/testData/checker/QualifiedExpressions.jet
浏览文件 @
75b23344
...
...
@@ -7,7 +7,7 @@ fun test(s: String?) {
val
<
warning
>
d
</
warning
>:
Int
=
s
?.
length
?:
<
error
>
"empty"
</
error
>
val
e
:
String
=
<
error
>
s
?.
length
</
error
>
?:
"empty"
val
<
warning
>
f
</
warning
>:
Int
=
s
?.
length
?:
b
?:
1
val
<
warning
>
g
</
warning
>:
Int
?
=
e
?
startsWith
(
"s"
)
?.
length
val
<
warning
>
g
</
warning
>:
Boolean
?
=
e
.
startsWith
(
"s"
)//
?.
length
}
fun
String
.
startsWith
(<
warning
>
s
</
warning
>:
String
):
Boolean
=
true
\ No newline at end of file
idea/testData/wordSelection/Statements.1.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
<
selection
>
pr
<
caret
>
intln
</
selection
>()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.10.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
<
selection
>
fun
foo
()
:
Unit
{
println
()
{
println
()
pr
<
caret
>
intln
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}</
selection
>
\ No newline at end of file
idea/testData/wordSelection/Statements.11.kt
0 → 100644
浏览文件 @
75b23344
<
selection
>
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
pr
<
caret
>
intln
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}</
selection
>
\ No newline at end of file
idea/testData/wordSelection/Statements.2.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
<
selection
>
pr
<
caret
>
intln
()</
selection
>
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.3.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
<
selection
>
pr
<
caret
>
intln
()
</
selection
>
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.4.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
<
selection
>
pr
<
caret
>
intln
()
println
()
</
selection
>
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.5.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
<
selection
>
println
()
pr
<
caret
>
intln
()
println
()
</
selection
>
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.6.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
<
selection
>{
println
()
pr
<
caret
>
intln
()
println
()
}
</
selection
>
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.7.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
<
selection
>
println
()
{
println
()
pr
<
caret
>
intln
()
println
()
}
</
selection
>
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/Statements.8.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
<
selection
>
println
()
{
println
()
pr
<
caret
>
intln
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
</
selection
>}
\ No newline at end of file
idea/testData/wordSelection/Statements.9.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
<
selection
>{
println
()
{
println
()
pr
<
caret
>
intln
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}</
selection
>
\ No newline at end of file
idea/testData/wordSelection/Statements.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
pr
<
caret
>
intln
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.1.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
<
selection
>{
print
(
i
);
continue
;}<
caret
></
selection
>
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.2.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
<
selection
>(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}<
caret
></
selection
>
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.3.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
<
selection
>
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}<
caret
>
</
selection
>
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.4.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
<
selection
>
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}<
caret
>
else
->
println
()
</
selection
>
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.5.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
<
selection
>
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}<
caret
>
else
->
println
()
</
selection
>
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.6.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
<
selection
>
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
continue
;}<
caret
>
else
->
println
()
}</
selection
>
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
idea/testData/wordSelection/WhenEntries.kt
0 → 100644
浏览文件 @
75b23344
fun
main
(
args
:
Array
<
String
>)
{
for
(
i
in
1
..
100
)
{
when
{
i
%
3
==
0
->
{
print
(
"Fizz"
);
continue
;}
i
%
5
==
0
->
{
print
(
"Buzz"
);
continue
;}
(
i
%
3
!=
0
&&
i
%
5
!=
0
)
->
{
print
(
i
);
<
selection
>
continue
;}<
caret
></
selection
>
else
->
println
()
}
}
}
fun
foo
()
:
Unit
{
println
()
{
println
()
println
()
println
()
}
println
(
array
(
1
,
2
,
3
))
println
()
}
\ No newline at end of file
compiler/frontend/src/org/jetbrains/jet/util/LinkedMultiMap
.java
→
idea/tests/org/jetbrains/jet/WordSelectionTest
.java
浏览文件 @
75b23344
...
...
@@ -14,26 +14,43 @@
* limitations under the License.
*/
package
org.jetbrains.jet
.util
;
package
org.jetbrains.jet
;
import
com.intellij.util.containers.MultiMap
;
import
com.intellij.testFramework.fixtures.CodeInsightTestUtil
;
import
com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
;
import
org.jetbrains.jet.plugin.PluginTestCaseBase
;
import
java.util.Collection
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.io.File
;
/**
* @author Evgeny Gerashchenko
*
TODO reuse LinkedMultiMap from IDEA platform when it will be available there
*
@since 2/24/12
*/
public
class
LinkedMultiMap
<
K
,
V
>
extends
MultiMap
<
K
,
V
>
{
@Override
protected
Map
<
K
,
Collection
<
V
>>
createMap
()
{
return
new
LinkedHashMap
<
K
,
Collection
<
V
>>();
public
class
WordSelectionTest
extends
LightCodeInsightFixtureTestCase
{
public
void
testStatements
()
{
doTest
(
11
);
}
public
void
testWhenEntries
()
{
doTest
(
6
);
}
private
void
doTest
(
int
howMany
)
{
String
testName
=
getTestName
(
false
);
String
[]
afterFiles
=
new
String
[
howMany
];
for
(
int
i
=
1
;
i
<=
howMany
;
i
++)
{
afterFiles
[
i
-
1
]
=
String
.
format
(
"%s.%d.kt"
,
testName
,
i
);
}
CodeInsightTestUtil
.
doWordSelectionTest
(
myFixture
,
testName
+
".kt"
,
afterFiles
);
}
@Override
protected
Map
<
K
,
Collection
<
V
>>
createMap
(
int
i
,
float
v
)
{
return
new
LinkedHashMap
<
K
,
Collection
<
V
>>(
i
,
v
);
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
final
String
testRelativeDir
=
"wordSelection"
;
myFixture
.
setTestDataPath
(
new
File
(
PluginTestCaseBase
.
getTestDataPathBase
(),
testRelativeDir
).
getPath
()
+
File
.
separator
);
}
}
idea/tests/org/jetbrains/jet/plugin/quickfix/ImportClassHelperTest.java
浏览文件 @
75b23344
...
...
@@ -21,6 +21,8 @@ import com.intellij.openapi.application.ApplicationManager;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.plugin.PluginTestCaseBase
;
import
java.io.IOException
;
/**
* @author Nikolay Krasko
*/
...
...
@@ -48,6 +50,30 @@ public class ImportClassHelperTest extends LightDaemonAnalyzerTestCase {
checkResultByFile
(
getTestName
(
false
)
+
".kt.after"
);
}
public
void
testInsertInEmptyFile
()
throws
IOException
{
configureFromFileText
(
"testInsertInEmptyFile.kt"
,
""
);
ApplicationManager
.
getApplication
().
runWriteAction
(
new
Runnable
()
{
@Override
public
void
run
()
{
ImportClassHelper
.
addImportDirective
(
"java.util.ArrayList"
,
(
JetFile
)
getFile
());
}
});
checkResultByText
(
"import java.util.ArrayList"
);
}
public
void
testInsertInPackageOnlyFile
()
throws
IOException
{
configureFromFileText
(
"testInsertInPackageOnlyFile.kt"
,
"package some"
);
ApplicationManager
.
getApplication
().
runWriteAction
(
new
Runnable
()
{
@Override
public
void
run
()
{
ImportClassHelper
.
addImportDirective
(
"java.util.ArrayList"
,
(
JetFile
)
getFile
());
}
});
checkResultByText
(
"package some\n\nimport java.util.ArrayList"
);
}
@Override
protected
String
getTestDataPath
()
{
return
PluginTestCaseBase
.
getTestDataPathBase
()
+
"/quickfix/importHelper/"
;
...
...
kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt
浏览文件 @
75b23344
...
...
@@ -45,11 +45,16 @@ class JavadocStyleHtmlDoclet() : Doclet {
fun
generateExtensionFunctions
(
p
:
KPackage
):
Unit
{
val
map
=
inheritedExtensionFunctions
(
p
.
functions
)
for
(
e
in
map
.
entrySet
())
{
val
c
=
e
?.
getKey
()
val
functions
=
e
?.
getValue
()
if
(
c
!=
null
&&
functions
!=
null
)
{
run
(
"${p.nameAsPath}/${c.simpleName}-extensions.html"
,
ClassExtensionsTemplate
(
model
,
p
,
c
,
functions
))
val
pmap
=
inheritedExtensionProperties
(
p
.
properties
)
val
classes
=
hashSet
<
KClass
>()
classes
.
addAll
(
map
.
keySet
())
classes
.
addAll
(
pmap
.
keySet
())
for
(
c
in
classes
)
{
if
(
c
!=
null
)
{
val
functions
=
map
.
get
(
c
).
notNull
()
val
properties
=
pmap
.
get
(
c
).
notNull
()
run
(
"${p.nameAsPath}/${c.simpleName}-extensions.html"
,
ClassExtensionsTemplate
(
model
,
p
,
c
,
functions
,
properties
))
}
}
}
...
...
kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt
浏览文件 @
75b23344
...
...
@@ -10,8 +10,10 @@ import org.jetbrains.kotlin.model.KPackage
import
org.jetbrains.kotlin.model.KClass
import
org.jetbrains.kotlin.model.KFunction
import
org.jetbrains.kotlin.model.KAnnotation
import
org.jetbrains.kotlin.model.KProperty
class
ClassExtensionsTemplate
(
m
:
KModel
,
p
:
KPackage
,
k
:
KClass
,
var
functions
:
Collection
<
KFunction
>)
:
ClassTemplate
(
m
,
p
,
k
)
{
class
ClassExtensionsTemplate
(
m
:
KModel
,
p
:
KPackage
,
k
:
KClass
,
val
functions
:
Collection
<
KFunction
>,
val
properties
:
Collection
<
KProperty
>)
:
ClassTemplate
(
m
,
p
,
k
)
{
override
fun
pageTitle
():
String
=
"${klass.name} Extensions fom ${pkg.name} (${model.title})"
...
...
@@ -31,6 +33,7 @@ from package ${link(pkg)}
</PRE>
<P>"""
)
printPropertySummary
(
properties
)
printFunctionSummary
(
functions
)
printFunctionDetail
(
functions
)
println
(
"""<!-- ========= END OF CLASS EXTENSIONS DATA ========= -->
...
...
kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt
浏览文件 @
75b23344
...
...
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.model.KModel
import
org.jetbrains.kotlin.model.KPackage
import
org.jetbrains.kotlin.model.KClass
import
org.jetbrains.kotlin.model.extensionFunctions
import
org.jetbrains.kotlin.model.inheritedExtensionFunctions
class
PackageSummaryTemplate
(
val
model
:
KModel
,
pkg
:
KPackage
)
:
PackageTemplateSupport
(
pkg
)
{
override
fun
render
()
{
...
...
@@ -263,7 +264,7 @@ Copyright © 2010-2012. All Rights Reserved.
}
protected
fun
printExtensionFunctions
():
Unit
{
val
map
=
e
xtensionFunctions
(
pkg
.
functions
)
val
map
=
inheritedE
xtensionFunctions
(
pkg
.
functions
)
if
(!
map
.
isEmpty
())
{
print
(
"""<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
...
...
kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt
浏览文件 @
75b23344
...
...
@@ -64,15 +64,55 @@ fun inheritedExtensionFunctions(functions: Collection<KFunction>): Map<KClass, S
return
answer
}
// TODO for some reason the SortedMap causes kotlin to freak out a little :)
fun
inheritedExtensionProperties
(
properties
:
Collection
<
KProperty
>):
Map
<
KClass
,
SortedSet
<
KProperty
>>
{
val
map
=
extensionProperties
(
properties
)
// for each class, lets walk its base classes and add any other extension properties from base classes
val
classes
=
map
.
keySet
().
toList
()
val
answer
=
TreeMap
<
KClass
,
SortedSet
<
KProperty
>>()
for
(
c
in
map
.
keySet
())
{
val
allProperties
=
map
.
get
(
c
).
notNull
().
toSortedSet
()
answer
.
put
(
c
,
allProperties
)
val
des
=
c
.
descendants
()
for
(
b
in
des
)
{
val
list
=
map
.
get
(
b
)
if
(
list
!=
null
)
{
if
(
allProperties
!=
null
)
{
for
(
f
in
list
)
{
if
(
f
!=
null
)
{
// add the proeprties from the base class if we don't have a matching method
if
(!
allProperties
.
any
{
it
.
name
==
f
.
name
})
{
allProperties
.
add
(
f
)
}
}
}
}
}
}
}
return
answer
}
// TODO for some reason the SortedMap causes kotlin to freak out a little :)
fun
extensionFunctions
(
functions
:
Collection
<
KFunction
>):
Map
<
KClass
,
List
<
KFunction
>>
{
//fun extensionFunctions(functions: Collection<KFunction>): SortedMap<KClass, List<KFunction>> {
val
map
=
TreeMap
<
KClass
,
List
<
KFunction
>>()
functions
.
filter
{
it
.
extensionClass
!=
null
}.
groupBy
(
map
){
it
.
extensionClass
.
sure
()
}
return
map
}
trait
KClassOrPackage
{
// TODO for some reason the SortedMap causes kotlin to freak out a little :)
fun
extensionProperties
(
properties
:
Collection
<
KProperty
>):
Map
<
KClass
,
List
<
KProperty
>>
{
val
map
=
TreeMap
<
KClass
,
List
<
KProperty
>>()
properties
.
filter
{
it
.
extensionClass
!=
null
}.
groupBy
(
map
){
it
.
extensionClass
.
sure
()
}
return
map
}
abstract
class
KClassOrPackage
:
KAnnotated
()
{
public
open
val
functions
:
SortedSet
<
KFunction
>
=
TreeSet
<
KFunction
>()
public
open
val
properties
:
SortedSet
<
KProperty
>
=
TreeSet
<
KProperty
>()
}
class
KModel
(
var
context
:
BindingContext
,
var
title
:
String
=
"Documentation"
,
var
version
:
String
=
"TODO"
)
{
...
...
@@ -131,7 +171,7 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
}
if
(
created
)
{
pkg
.
description
=
commentsFor
(
descriptor
)
addFunctions
(
pkg
,
pkg
.
functions
,
descriptor
.
getMemberScope
())
addFunctions
(
pkg
,
descriptor
.
getMemberScope
())
if
(
pkg
.
functions
.
notEmpty
())
{
pkg
.
local
=
true
}
...
...
@@ -139,23 +179,26 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
return
pkg
;
}
protected
fun
addFunctions
(
owner
:
KClassOrPackage
,
list
:
Collection
<
KFunction
>,
scope
:
JetScope
):
Unit
{
protected
fun
addFunctions
(
owner
:
KClassOrPackage
,
scope
:
JetScope
):
Unit
{
try
{
val
descriptors
=
scope
.
getAllDescriptors
()
for
(
descriptor
in
descriptors
)
{
if
(
descriptor
is
PropertyDescriptor
)
{
if
(
owner
is
KClass
)
{
val
name
=
descriptor
.
getName
()
val
returnType
=
getClass
(
descriptor
.
getReturnType
())
if
(
returnType
!=
null
)
{
val
property
=
KProperty
(
owner
,
descriptor
,
name
,
returnType
)
owner
.
properties
.
add
(
property
)
}
val
name
=
descriptor
.
getName
()
val
returnType
=
getClass
(
descriptor
.
getReturnType
())
if
(
returnType
!=
null
)
{
val
receiver
=
descriptor
.
getReceiverParameter
()
val
extensionClass
=
if
(
receiver
is
ExtensionReceiver
)
{
getClass
(
receiver
.
getType
())
}
else
null
val
property
=
KProperty
(
owner
,
descriptor
,
name
,
returnType
,
extensionClass
)
owner
.
properties
.
add
(
property
)
}
}
else
if
(
descriptor
is
CallableDescriptor
)
{
val
function
=
createFunction
(
owner
,
descriptor
)
if
(
function
!=
null
)
{
list
.
add
(
function
)
owner
.
functions
.
add
(
function
)
}
}
}
...
...
@@ -271,8 +314,7 @@ abstract class KAnnotated {
class
KPackage
(
val
model
:
KModel
,
val
descriptor
:
NamespaceDescriptor
,
val
name
:
String
,
var
external
:
Boolean
=
false
,
var
functions
:
SortedSet
<
KFunction
>
=
TreeSet
<
KFunction
>(),
var
local
:
Boolean
=
false
)
:
KAnnotated
(),
Comparable
<
KPackage
>,
KClassOrPackage
{
var
local
:
Boolean
=
false
)
:
KClassOrPackage
(),
Comparable
<
KPackage
>
{
override
fun
compareTo
(
other
:
KPackage
):
Int
=
name
.
compareTo
(
other
.
name
)
...
...
@@ -296,7 +338,7 @@ class KPackage(val model: KModel, val descriptor: NamespaceDescriptor,
klass
.
baseClasses
.
add
(
sc
)
}
}
model
.
addFunctions
(
klass
,
klass
.
functions
,
classElement
.
getDefaultType
().
getMemberScope
())
model
.
addFunctions
(
klass
,
classElement
.
getDefaultType
().
getMemberScope
())
}
return
klass
}
...
...
@@ -364,11 +406,9 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
var
annotations
:
List
<
KAnnotation
>
=
arrayList
<
KAnnotation
>(),
var
since
:
String
=
""
,
var
authors
:
List
<
String
>
=
arrayList
<
String
>(),
var
functions
:
SortedSet
<
KFunction
>
=
TreeSet
<
KFunction
>(),
var
properties
:
SortedSet
<
KProperty
>
=
TreeSet
<
KProperty
>(),
var
baseClasses
:
List
<
KClass
>
=
arrayList
<
KClass
>(),
var
nestedClasses
:
List
<
KClass
>
=
arrayList
<
KClass
>(),
var
sourceLine
:
Int
=
2
)
:
K
Annotated
(),
Comparable
<
KClass
>,
KClassOrPackage
{
var
sourceLine
:
Int
=
2
)
:
K
ClassOrPackage
(),
Comparable
<
KClass
>
{
override
fun
compareTo
(
other
:
KClass
):
Int
=
name
.
compareTo
(
other
.
name
)
...
...
@@ -444,7 +484,7 @@ class KFunction(val owner: KClassOrPackage, val name: String,
}
class
KProperty
(
val
owner
:
KClassOrPackage
,
val
descriptor
:
PropertyDescriptor
,
val
name
:
String
,
val
returnType
:
KClass
)
:
KAnnotated
(),
Comparable
<
KProperty
>
{
val
returnType
:
KClass
,
val
extensionClass
:
KClass
?
)
:
KAnnotated
(),
Comparable
<
KProperty
>
{
override
fun
compareTo
(
other
:
KProperty
):
Int
=
name
.
compareTo
(
other
.
name
)
...
...
stdlib/ktSrc/JavaIterablesSpecial.kt
浏览文件 @
75b23344
package
std.util
// Number of extension function for ava.lang.Iterable that shouldn't participate in auto generation
// Number of extension function for
j
ava.lang.Iterable that shouldn't participate in auto generation
import
java.util.Collection
import
java.util.List
import
java.util.AbstractList
import
java.util.Iterator
/**
* Count the number of elements in collection.
...
...
@@ -83,3 +84,38 @@ fun <T> java.lang.Iterable<T>.contains(item : T) : Boolean {
return
false
}
/**
* Convert collection of arbitrary elements to collection of
*/
fun
<
T
>
java
.
lang
.
Iterable
<
T
>.
withIndices
()
:
java
.
lang
.
Iterable
<
#(
Int
,
T
)
>
{
return
object
: java.lang.
Iterable
<
#
(
Int
,
T
)>
{
override
fun
iterator
():
java
.
util
.
Iterator
<
#(
Int
,
T
)
>
{
// TODO explicit typecast as a workaround for KT-1457, should be removed when it is fixed
return
NumberedIterator
<
T
>(
this
@withIndices
.
iterator
().
sure
())
as
java
.
util
.
Iterator
<
#(
Int
,
T
)
>
}
}
}
private
class
NumberedIterator
<
TT
>(
private
val
sourceIterator
:
java
.
util
.
Iterator
<
TT
>)
:
java
.
util
.
Iterator
<
#(
Int
,
TT
)
>
{
private
var
nextIndex
=
0
override
fun
remove
()
{
try
{
sourceIterator
.
remove
()
nextIndex--
;
}
catch
(
e
:
UnsupportedOperationException
)
{
throw
e
}
}
override
fun
hasNext
():
Boolean
{
return
sourceIterator
.
hasNext
();
}
override
fun
next
():
#
(
Int
,
TT
)
{
val
result
=
#
(
nextIndex
,
sourceIterator
.
next
())
nextIndex
++
return
result
}
}
\ No newline at end of file
stdlib/ktSrc/JavaUtil.kt
浏览文件 @
75b23344
...
...
@@ -55,8 +55,12 @@ inline fun <in T: java.lang.Comparable<T>> List<T>.sort(comparator: java.util.Co
}
/** Converts the nullable List into an empty List if its null */
inline
fun
<
T
>
java
.
util
.
List
<
T
>
?.
notNull
()
:
List
<
T
>
=
if
(
this
!=
null
)
this
else
Collections
.
EMPTY_LIST
as
List
<
T
>
inline
fun
<
T
>
java
.
util
.
List
<
T
>
?.
notNull
()
:
java
.
util
.
List
<
T
>
=
if
(
this
!=
null
)
this
else
Collections
.
EMPTY_LIST
as
java
.
util
.
List
<
T
>
/** Converts the nullable Set into an empty Set if its null */
inline
fun
<
T
>
java
.
util
.
Set
<
T
>
?.
notNull
()
:
java
.
util
.
Set
<
T
>
=
if
(
this
!=
null
)
this
else
Collections
.
EMPTY_SET
as
java
.
util
.
Set
<
T
>
/**
TODO figure out necessary variance/generics ninja stuff... :)
...
...
stdlib/ktSrc/JavaUtilMap.kt
浏览文件 @
75b23344
...
...
@@ -2,6 +2,7 @@ package std.util
import
java.util.Map
as
JMap
import
java.util.HashMap
import
java.util.Collections
// Temporary workaround: commenting out
//import java.util.Map.Entry as JEntry
...
...
@@ -19,6 +20,10 @@ val JMap<*,*>.empty : Boolean
/** Provides [] access to maps */
fun
<
K
,
V
>
JMap
<
K
,
V
>.
set
(
key
:
K
,
value
:
V
)
=
this
.
put
(
key
,
value
)
/** Converts the nullable Map into an empty Map if its null */
inline
fun
<
K
,
V
>
java
.
util
.
Map
<
K
,
V
>
?.
notNull
()
:
java
.
util
.
Map
<
K
,
V
>
=
if
(
this
!=
null
)
this
else
Collections
.
EMPTY_MAP
as
java
.
util
.
Map
<
K
,
V
>
/** Returns the key of the entry */
// Temporary workaround: commenting out
...
...
stdlib/ktSrc/String.kt
浏览文件 @
75b23344
...
...
@@ -10,6 +10,8 @@ inline fun String.equalsIgnoreCase(anotherString: String) = (this as java.lang.S
inline
fun
String
.
indexOf
(
str
:
String
)
=
(
this
as
java
.
lang
.
String
).
indexOf
(
str
)
inline
fun
String
.
matches
(
regex
:
String
):
Boolean
=
(
this
as
java
.
lang
.
String
).
matches
(
regex
)
inline
fun
String
.
indexOf
(
str
:
String
,
fromIndex
:
Int
)
=
(
this
as
java
.
lang
.
String
).
indexOf
(
str
,
fromIndex
)
inline
fun
String
.
replace
(
oldChar
:
Char
,
newChar
:
Char
)
=
(
this
as
java
.
lang
.
String
).
replace
(
oldChar
,
newChar
).
sure
()
...
...
stdlib/ktSrc/dom/Dom.kt
浏览文件 @
75b23344
...
...
@@ -56,6 +56,7 @@ var Element.id : String
get
()
=
this
.
getAttribute
(
"id"
)
?:
""
set
(
value
)
{
this
.
setAttribute
(
"id"
,
value
)
this
.
setIdAttribute
(
"id"
,
true
)
}
var
Element
.
style
:
String
...
...
@@ -73,23 +74,76 @@ set(value) {
// Helper methods
fun
Element
.
hasClass
(
cssClass
:
String
):
Boolean
{
val
c
=
this
.
cssClass
return
if
(
c
!=
null
)
c
.
matches
(
"""(^|\s+)$cssClass($|\s+)"""
)
else
false
}
/** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */
fun
Document
?.
get
(
selector
:
String
):
List
<
Element
>
{
val
root
=
this
?.
getDocumentElement
()
return
if
(
root
!=
null
)
{
if
(
selector
==
"*"
)
{
elements
}
else
if
(
selector
.
startsWith
(
"."
))
{
elements
.
filter
{
it
.
hasClass
(
selector
.
substring
(
1
))
}.
toList
()
}
else
if
(
selector
.
startsWith
(
"#"
))
{
val
id
=
selector
.
substring
(
1
)
val
element
=
this
?.
getElementById
(
id
)
return
if
(
element
!=
null
)
Collections
.
singletonList
(
element
).
sure
()
as
List
<
Element
>
else
Collections
.
EMPTY_LIST
.
sure
()
as
List
<
Element
>
}
else
{
// assume its a vanilla element name
this
?.
getElementsByTagName
(
selector
).
toElementList
()
}
}
else
{
Collections
.
EMPTY_LIST
as
List
<
Element
>
}
}
/** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */
fun
Element
.
get
(
selector
:
String
):
List
<
Element
>
{
return
if
(
selector
==
"*"
)
{
elements
}
else
if
(
selector
.
startsWith
(
"."
))
{
elements
.
filter
{
it
.
hasClass
(
selector
.
substring
(
1
))
}.
toList
()
}
else
if
(
selector
.
startsWith
(
"#"
))
{
val
element
=
this
.
getOwnerDocument
()
?.
getElementById
(
selector
.
substring
(
1
))
return
if
(
element
!=
null
)
Collections
.
singletonList
(
element
).
sure
()
as
List
<
Element
>
else
Collections
.
EMPTY_LIST
.
sure
()
as
List
<
Element
>
}
else
{
// assume its a vanilla element name
this
.
getElementsByTagName
(
selector
).
toElementList
()
}
}
/** Returns the attribute value or null if its not present */
inline
fun
Element
?.
attribute
(
name
:
String
):
String
?
{
return
this
?.
getAttribute
(
name
)
}
/** Returns the children of the element as a list */
inline
fun
Element
?.
children
():
List
<
Node
>
{
return
this
?.
getChildNodes
().
toList
()
}
inline
fun
Element
?.
elementsByTagName
(
name
:
String
?):
List
<
Element
>
{
return
this
?.
getElementsByTagName
(
name
).
toElementList
()
}
val
Document
?.
elements
:
List
<
Element
>
get
()
=
this
?.
getElementsByTagName
(
"*"
).
toElementList
()
val
Element
?.
elements
:
List
<
Element
>
get
()
=
this
?.
getElementsByTagName
(
"*"
).
toElementList
()
inline
fun
Element
?.
elementsByTagNameNS
(
namespaceUri
:
String
?,
localName
:
String
?):
List
<
Element
>
{
return
this
?.
getElementsByTagNameNS
(
namespaceUri
,
localName
).
toElementList
()
}
inline
fun
Document
?.
elementsByTagName
(
name
:
String
?):
List
<
Element
>
{
return
this
?.
getElementsByTagName
(
name
).
toElementList
()
}
inline
fun
Document
?.
elementsByTagNameNS
(
namespaceUri
:
String
?,
localName
:
String
?):
List
<
Element
>
{
return
this
?.
getElementsByTagNameNS
(
namespaceUri
,
localName
).
toElementList
()
}
...
...
@@ -169,6 +223,8 @@ class ElementListAsList(val nodeList: NodeList): AbstractList<Element>() {
override
fun
size
():
Int
=
nodeList
.
getLength
()
}
// Syntax sugar
inline
fun
Node
.
plus
(
child
:
Node
?):
Node
{
...
...
testlib/test/ListTest.kt
浏览文件 @
75b23344
...
...
@@ -27,4 +27,15 @@ class ListTest() : TestSupport() {
val
t
=
data
.
last
assertEquals
(
"bar"
,
t
)
}
fun
testWithIndices
()
{
val
withIndices
=
data
.
withIndices
()
var
index
=
0
for
(
withIndex
in
withIndices
)
{
assertEquals
(
withIndex
.
_1
,
index
)
assertEquals
(
withIndex
.
_2
,
data
[
index
])
index
++
}
assertEquals
(
data
.
size
(),
index
)
}
}
testlib/test/dom/DomBuilderTest.kt
浏览文件 @
75b23344
...
...
@@ -11,13 +11,19 @@ class DomBuilderTest() : TestSupport() {
fun
testBuildDocument
()
{
var
doc
=
createDocument
()
assert
{
doc
[
"grandchild"
].
isEmpty
()
}
doc
.
addElement
(
"foo"
)
{
id
=
"id1"
style
=
"bold"
cssClass
=
"bar"
addElement
(
"child"
)
{
id
=
"id2"
cssClass
=
"another"
addElement
(
"grandChild"
)
{
id
=
"id3"
cssClass
=
"tiny"
addText
(
"Hello World!"
)
// TODO support neater syntax sugar for adding text?
...
...
@@ -28,10 +34,55 @@ class DomBuilderTest() : TestSupport() {
println
(
"builder document: ${doc.toXmlString()}"
)
val
grandChild
=
doc
.
elementsByTagName
(
"grandChild"
).
first
// test css selections on document
assertEquals
(
0
,
doc
[
".doesNotExist"
].
size
())
assertEquals
(
1
,
doc
[
".another"
].
size
())
assertEquals
(
1
,
doc
[
".tiny"
].
size
())
assertEquals
(
1
,
doc
[
".bar"
].
size
())
// element tag selections
assertEquals
(
0
,
doc
[
"doesNotExist"
].
size
())
assertEquals
(
1
,
doc
[
"foo"
].
size
())
assertEquals
(
1
,
doc
[
"child"
].
size
())
assertEquals
(
1
,
doc
[
"grandChild"
].
size
())
// id selections
assertEquals
(
1
,
doc
[
"#id1"
].
size
())
assertEquals
(
1
,
doc
[
"#id2"
].
size
())
assertEquals
(
1
,
doc
[
"#id3"
].
size
())
val
root
=
doc
.
rootElement
if
(
root
!=
null
)
{
assert
{
root
.
hasClass
(
"bar"
)
}
// test css selections on element
assertEquals
(
0
,
root
[
".doesNotExist"
].
size
())
assertEquals
(
1
,
root
[
".another"
].
size
())
assertEquals
(
1
,
root
[
".tiny"
].
size
())
assertEquals
(
0
,
root
[
".bar"
].
size
())
// element tag selections
assertEquals
(
0
,
root
[
"doesNotExist"
].
size
())
assertEquals
(
0
,
root
[
"foo"
].
size
())
assertEquals
(
1
,
root
[
"child"
].
size
())
assertEquals
(
1
,
root
[
"grandChild"
].
size
())
// id selections
assertEquals
(
1
,
root
[
"#id1"
].
size
())
assertEquals
(
1
,
root
[
"#id2"
].
size
())
assertEquals
(
1
,
root
[
"#id3"
].
size
())
}
else
{
fail
(
"No root!"
)
}
val
grandChild
=
doc
[
"grandChild"
].
first
if
(
grandChild
!=
null
)
{
println
(
"got element ${grandChild.toXmlString()} with text '${grandChild.text}`"
)
assertEquals
(
"Hello World!"
,
grandChild
.
text
)
assertEquals
(
"tiny"
,
grandChild
.
attribute
(
"class"
)
?:
""
)
}
else
{
fail
(
"Not an Element $grandChild"
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录