Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
30d69710
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,发现更多精彩内容 >>
提交
30d69710
编写于
10月 09, 2015
作者:
A
Alexey Sedunov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code Insight: "Generate secondary constructor" action
#KT-6970 Fixed
上级
78829b9e
变更
37
隐藏空白更改
内联
并排
Showing
37 changed file
with
1024 addition
and
245 deletion
+1024
-245
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
...frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
+3
-0
generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
...rc/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
+6
-1
idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt
...is/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt
+9
-8
idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideImplementMembersHandler.kt
...core/overrideImplement/OverrideImplementMembersHandler.kt
+2
-2
idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt
...rc/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt
+8
-5
idea/src/META-INF/plugin.xml
idea/src/META-INF/plugin.xml
+4
-0
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateActionBase.kt
.../kotlin/idea/actions/generate/KotlinGenerateActionBase.kt
+5
-2
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateMemberActionBase.kt
...n/idea/actions/generate/KotlinGenerateMemberActionBase.kt
+47
-0
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateSecondaryConstructorAction.kt
...ions/generate/KotlinGenerateSecondaryConstructorAction.kt
+201
-0
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateTestSupportActionBase.kt
...a/actions/generate/KotlinGenerateTestSupportActionBase.kt
+58
-67
idea/testData/codeInsight/generate/secondaryConstructors/empty.kt
...tData/codeInsight/generate/secondaryConstructors/empty.kt
+20
-0
idea/testData/codeInsight/generate/secondaryConstructors/empty.kt.after
...codeInsight/generate/secondaryConstructors/empty.kt.after
+22
-0
idea/testData/codeInsight/generate/secondaryConstructors/emptyExists.kt
...codeInsight/generate/secondaryConstructors/emptyExists.kt
+24
-0
idea/testData/codeInsight/generate/secondaryConstructors/emptyExists.kt.messages
...ht/generate/secondaryConstructors/emptyExists.kt.messages
+1
-0
idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.java
...odeInsight/generate/secondaryConstructors/javaSupers.java
+9
-0
idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.kt
.../codeInsight/generate/secondaryConstructors/javaSupers.kt
+12
-0
idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.kt.after
...nsight/generate/secondaryConstructors/javaSupers.kt.after
+16
-0
idea/testData/codeInsight/generate/secondaryConstructors/properties.kt
.../codeInsight/generate/secondaryConstructors/properties.kt
+16
-0
idea/testData/codeInsight/generate/secondaryConstructors/properties.kt.after
...nsight/generate/secondaryConstructors/properties.kt.after
+21
-0
idea/testData/codeInsight/generate/secondaryConstructors/propertiesWithSupers.kt
...ht/generate/secondaryConstructors/propertiesWithSupers.kt
+18
-0
idea/testData/codeInsight/generate/secondaryConstructors/propertiesWithSupers.kt.after
...erate/secondaryConstructors/propertiesWithSupers.kt.after
+26
-0
idea/testData/codeInsight/generate/secondaryConstructors/supers.kt
...Data/codeInsight/generate/secondaryConstructors/supers.kt
+16
-0
idea/testData/codeInsight/generate/secondaryConstructors/supers.kt.after
...odeInsight/generate/secondaryConstructors/supers.kt.after
+20
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersAllExist.kt
...eInsight/generate/secondaryConstructors/supersAllExist.kt
+20
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersAllExist.kt.messages
...generate/secondaryConstructors/supersAllExist.kt.messages
+1
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersPrimaryExists.kt
...ght/generate/secondaryConstructors/supersPrimaryExists.kt
+16
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersPrimaryExists.kt.after
...nerate/secondaryConstructors/supersPrimaryExists.kt.after
+18
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersSomeExist.kt
...Insight/generate/secondaryConstructors/supersSomeExist.kt
+18
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersSomeExist.kt.after
...t/generate/secondaryConstructors/supersSomeExist.kt.after
+20
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersWithGenerics.kt
...ight/generate/secondaryConstructors/supersWithGenerics.kt
+16
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersWithGenerics.kt.after
...enerate/secondaryConstructors/supersWithGenerics.kt.after
+20
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersWithVarargs.kt
...sight/generate/secondaryConstructors/supersWithVarargs.kt
+16
-0
idea/testData/codeInsight/generate/secondaryConstructors/supersWithVarargs.kt.after
...generate/secondaryConstructors/supersWithVarargs.kt.after
+18
-0
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateActionTest.kt
...n/idea/codeInsight/generate/AbstractGenerateActionTest.kt
+22
-19
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateTestSupportMethodActionTest.kt
...t/generate/AbstractGenerateTestSupportMethodActionTest.kt
+40
-0
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateActionTestGenerated.java
...dea/codeInsight/generate/GenerateActionTestGenerated.java
+57
-141
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateTestSupportMethodActionTestGenerated.java
...enerate/GenerateTestSupportMethodActionTestGenerated.java
+178
-0
未找到文件。
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
浏览文件 @
30d69710
...
...
@@ -756,6 +756,9 @@ public interface Errors {
TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER
,
TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS
,
TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR
,
TYPE_INFERENCE_UPPER_BOUND_VIOLATED
,
TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH
);
ImmutableSet
<?
extends
DiagnosticFactory
<?>>
MUST_BE_INITIALIZED_DIAGNOSTICS
=
ImmutableSet
.
of
(
MUST_BE_INITIALIZED
,
MUST_BE_INITIALIZED_OR_BE_ABSTRACT
);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...
...
generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt
浏览文件 @
30d69710
...
...
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
import
org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
import
org.jetbrains.kotlin.idea.codeInsight.*
import
org.jetbrains.kotlin.idea.codeInsight.generate.AbstractGenerateActionTest
import
org.jetbrains.kotlin.idea.codeInsight.generate.AbstractGenerateTestSupportMethodActionTest
import
org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractCodeMoverTest
import
org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest
import
org.jetbrains.kotlin.idea.codeInsight.unwrap.AbstractUnwrapRemoveTest
...
...
@@ -731,8 +732,12 @@ fun main(args: Array<String>) {
model
(
"kdoc/typing"
)
}
testClass
<
AbstractGenerateTestSupportMethodActionTest
>()
{
model
(
"codeInsight/generate/testFrameworkSupport"
)
}
testClass
<
AbstractGenerateActionTest
>()
{
model
(
"codeInsight/generate"
)
model
(
"codeInsight/generate
/secondaryConstructors
"
)
}
}
...
...
idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt
浏览文件 @
30d69710
...
...
@@ -142,20 +142,21 @@ private fun removeAfterOffset(offset: Int, whiteSpace: PsiWhiteSpace): PsiElemen
return
whiteSpace
}
public
fun
<
T
:
JetDeclaration
>
generateMembers
(
public
fun
<
T
:
JetDeclaration
>
insertMembersAfter
(
editor
:
Editor
,
classOrObject
:
JetClassOrObject
,
generators
:
Collection
<
()
-
>
T
>
members
:
Collection
<
T
>,
anchor
:
PsiElement
?
=
null
):
List
<
T
>
{
generato
rs
.
ifEmpty
{
return
emptyList
()
}
membe
rs
.
ifEmpty
{
return
emptyList
()
}
return
runWriteAction
<
List
<
T
>>
{
val
body
=
classOrObject
.
getOrCreateBody
()
var
afterAnchor
=
findInsertAfterAnchor
(
editor
,
body
)
?:
return
@runWriteAction
emptyList
()
val
insertedMembers
=
generato
rs
.
mapTo
(
SmartList
<
T
>())
{
var
afterAnchor
=
anchor
?:
findInsertAfterAnchor
(
editor
,
body
)
?:
return
@runWriteAction
emptyList
()
val
insertedMembers
=
membe
rs
.
mapTo
(
SmartList
<
T
>())
{
@Suppress
(
"UNCHECKED_CAST"
)
(
body
.
addAfter
(
it
()
,
afterAnchor
)
as
T
).
apply
{
afterAnchor
=
this
}
(
body
.
addAfter
(
it
,
afterAnchor
)
as
T
).
apply
{
afterAnchor
=
this
}
}
ShortenReferences
.
DEFAULT
.
process
(
insertedMembers
)
...
...
@@ -166,6 +167,6 @@ public fun <T : JetDeclaration> generateMembers(
}
}
public
fun
<
T
:
JetDeclaration
>
generate
Member
(
editor
:
Editor
,
classOrObject
:
JetClassOrObject
,
declaration
:
T
):
T
{
return
generateMembers
(
editor
,
classOrObject
,
listOf
({
declaration
}
)).
single
()
public
fun
<
T
:
JetDeclaration
>
insert
Member
(
editor
:
Editor
,
classOrObject
:
JetClassOrObject
,
declaration
:
T
):
T
{
return
insertMembersAfter
(
editor
,
classOrObject
,
listOf
(
declaration
)).
single
()
}
\ No newline at end of file
idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideImplementMembersHandler.kt
浏览文件 @
30d69710
...
...
@@ -26,7 +26,7 @@ import com.intellij.psi.PsiDocumentManager
import
com.intellij.psi.PsiFile
import
org.jetbrains.kotlin.descriptors.ClassDescriptor
import
org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import
org.jetbrains.kotlin.idea.quickfix.
generateMembers
import
org.jetbrains.kotlin.idea.quickfix.
insertMembersAfter
import
org.jetbrains.kotlin.psi.JetClassOrObject
import
org.jetbrains.kotlin.psi.JetFile
import
org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
...
...
@@ -90,7 +90,7 @@ public abstract class OverrideImplementMembersHandler : LanguageCodeInsightActio
companion
object
{
public
fun
generateMembers
(
editor
:
Editor
,
classOrObject
:
JetClassOrObject
,
selectedElements
:
Collection
<
OverrideMemberChooserObject
>)
{
val
project
=
classOrObject
.
project
generateMembers
(
editor
,
classOrObject
,
selectedElements
.
map
{
chooser
->
{
chooser
.
generateMember
(
project
)
}
})
insertMembersAfter
(
editor
,
classOrObject
,
selectedElements
.
map
{
it
.
generateMember
(
project
)
})
}
}
}
idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt
浏览文件 @
30d69710
...
...
@@ -21,8 +21,6 @@ import com.intellij.psi.PsiWhiteSpace
import
com.intellij.psi.impl.source.codeStyle.CodeEditUtil
import
com.intellij.psi.util.PsiTreeUtil
import
org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import
org.jetbrains.kotlin.descriptors.Visibilities
import
org.jetbrains.kotlin.descriptors.Visibility
import
org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import
org.jetbrains.kotlin.lexer.JetModifierKeywordToken
import
org.jetbrains.kotlin.lexer.JetTokens
...
...
@@ -103,16 +101,21 @@ public fun JetCallExpression.moveFunctionLiteralOutsideParentheses() {
}
}
public
fun
JetBlockExpression
.
appendElement
(
element
:
JetElement
):
JetElement
{
public
fun
JetBlockExpression
.
appendElement
(
element
:
JetElement
,
addNewLine
:
Boolean
=
false
):
JetElement
{
val
rBrace
=
getRBrace
()
val
newLine
=
JetPsiFactory
(
this
).
createNewLine
()
val
anchor
=
if
(
rBrace
==
null
)
{
val
lastChild
=
getLastChild
()
if
(
lastChild
!
is
PsiWhiteSpace
)
addAfter
(
JetPsiFactory
(
this
).
createNewLine
()
,
lastChild
)
!!
else
lastChild
if
(
lastChild
!
is
PsiWhiteSpace
)
addAfter
(
newLine
,
lastChild
)
!!
else
lastChild
}
else
{
rBrace
.
getPrevSibling
()
!!
}
return
addAfter
(
element
,
anchor
)
!!
as
JetElement
val
addedElement
=
addAfter
(
element
,
anchor
)
!!
as
JetElement
if
(
addNewLine
)
{
addAfter
(
newLine
,
addedElement
)
}
return
addedElement
}
//TODO: git rid of this method
...
...
idea/src/META-INF/plugin.xml
浏览文件 @
30d69710
...
...
@@ -169,6 +169,10 @@
<action
id=
"KotlinGenerateTearDownMethod"
class=
"org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown"
text=
"TearDown Function"
/>
<separator
/>
<action
id=
"KotlinGenerateSecondaryConstructor"
class=
"org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction"
text=
"Secondary Constructor"
/>
<add-to-group
group-id=
"GenerateGroup"
anchor=
"first"
/>
</group>
...
...
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateActionBase.kt
浏览文件 @
30d69710
...
...
@@ -23,14 +23,13 @@ import com.intellij.openapi.actionSystem.DataContext
import
com.intellij.openapi.actionSystem.Presentation
import
com.intellij.openapi.editor.Editor
import
com.intellij.openapi.project.Project
import
com.intellij.psi.PsiDocumentManager
import
com.intellij.psi.PsiFile
import
org.jetbrains.kotlin.idea.core.refactoring.canRefactor
import
org.jetbrains.kotlin.psi.JetClassOrObject
import
org.jetbrains.kotlin.psi.JetFile
import
org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
abstract
class
KotlinGenerateActionBase
()
:
CodeInsightAction
()
{
abstract
class
KotlinGenerateActionBase
()
:
CodeInsightAction
()
,
CodeInsightActionHandler
{
override
fun
update
(
presentation
:
Presentation
,
project
:
Project
,
...
...
@@ -58,4 +57,8 @@ abstract class KotlinGenerateActionBase() : CodeInsightAction() {
}
protected
abstract
fun
isValidForClass
(
targetClass
:
JetClassOrObject
):
Boolean
override
fun
startInWriteAction
()
=
false
override
fun
getHandler
()
=
this
}
\ No newline at end of file
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateMemberActionBase.kt
0 → 100644
浏览文件 @
30d69710
/*
* Copyright 2010-2015 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.kotlin.idea.actions.generate
import
com.intellij.codeInsight.CodeInsightUtilBase
import
com.intellij.codeInsight.generation.GenerateMembersUtil
import
com.intellij.codeInspection.ex.GlobalInspectionContextBase
import
com.intellij.openapi.editor.Editor
import
com.intellij.openapi.fileEditor.FileDocumentManager
import
com.intellij.openapi.project.Project
import
com.intellij.psi.PsiFile
import
org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import
org.jetbrains.kotlin.psi.JetClassOrObject
import
org.jetbrains.kotlin.psi.JetDeclaration
abstract
class
KotlinGenerateMemberActionBase
<
Info
:
Any
>
:
KotlinGenerateActionBase
()
{
protected
abstract
fun
prepareMembersInfo
(
klass
:
JetClassOrObject
,
project
:
Project
):
Info
?
protected
abstract
fun
generateMembers
(
editor
:
Editor
,
info
:
Info
):
List
<
JetDeclaration
>
override
fun
invoke
(
project
:
Project
,
editor
:
Editor
,
file
:
PsiFile
)
{
if
(!
CodeInsightUtilBase
.
prepareEditorForWrite
(
editor
))
return
if
(!
FileDocumentManager
.
getInstance
().
requestWriting
(
editor
.
document
,
project
))
return
val
klass
=
getTargetClass
(
editor
,
file
)
?:
return
val
membersInfo
=
prepareMembersInfo
(
klass
,
project
)
?:
return
project
.
executeWriteCommand
(
commandName
,
this
)
{
val
newMembers
=
generateMembers
(
editor
,
membersInfo
)
GlobalInspectionContextBase
.
cleanupElements
(
project
,
null
,
*
newMembers
.
toTypedArray
())
newMembers
.
firstOrNull
()
?.
let
{
GenerateMembersUtil
.
positionCaret
(
editor
,
it
,
false
)
}
}
}
}
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateSecondaryConstructorAction.kt
0 → 100644
浏览文件 @
30d69710
/*
* Copyright 2010-2015 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.kotlin.idea.actions.generate
import
com.intellij.codeInsight.CodeInsightBundle
import
com.intellij.ide.util.MemberChooser
import
com.intellij.openapi.application.ApplicationManager
import
com.intellij.openapi.editor.Editor
import
com.intellij.openapi.project.Project
import
com.intellij.psi.PsiElement
import
com.intellij.refactoring.util.CommonRefactoringUtil
import
org.jetbrains.kotlin.descriptors.ClassDescriptor
import
org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import
org.jetbrains.kotlin.descriptors.PropertyDescriptor
import
org.jetbrains.kotlin.diagnostics.Errors
import
org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import
org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import
org.jetbrains.kotlin.idea.core.CollectingNameValidator
import
org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import
org.jetbrains.kotlin.idea.core.appendElement
import
org.jetbrains.kotlin.idea.core.isVisible
import
org.jetbrains.kotlin.idea.core.util.DescriptorMemberChooserObject
import
org.jetbrains.kotlin.idea.quickfix.insertMembersAfter
import
org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import
org.jetbrains.kotlin.psi.*
import
org.jetbrains.kotlin.psi.psiUtil.siblings
import
org.jetbrains.kotlin.resolve.BindingContext
import
org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import
org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
import
org.jetbrains.kotlin.resolve.source.getPsi
import
org.jetbrains.kotlin.types.JetType
import
org.jetbrains.kotlin.types.TypeSubstitutor
import
org.jetbrains.kotlin.types.Variance
import
org.jetbrains.kotlin.types.checker.JetTypeChecker
import
org.jetbrains.kotlin.types.substitutions.getTypeSubstitutor
import
org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import
org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
import
org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import
java.util.*
class
KotlinGenerateSecondaryConstructorAction
:
KotlinGenerateMemberActionBase
<
KotlinGenerateSecondaryConstructorAction
.
Info
>()
{
class
Info
(
val
propertiesToInitialize
:
List
<
PropertyDescriptor
>,
val
superConstructors
:
List
<
ConstructorDescriptor
>,
val
classDescriptor
:
ClassDescriptor
)
override
fun
isValidForClass
(
targetClass
:
JetClassOrObject
):
Boolean
{
return
targetClass
is
JetClass
&&
targetClass
!
is
JetEnumEntry
&&
!
targetClass
.
isInterface
()
&&
!
targetClass
.
isAnnotation
()
}
private
fun
shouldPreselect
(
element
:
PsiElement
)
=
element
is
JetProperty
&&
!
element
.
isVar
private
fun
chooseSuperConstructors
(
klass
:
JetClassOrObject
,
classDescriptor
:
ClassDescriptor
):
List
<
DescriptorMemberChooserObject
>
{
val
project
=
klass
.
project
val
superClassDescriptor
=
classDescriptor
.
getSuperClassNotAny
()
?:
return
emptyList
()
val
candidates
=
superClassDescriptor
.
constructors
.
filter
{
it
.
isVisible
(
classDescriptor
)
}
.
map
{
DescriptorMemberChooserObject
(
DescriptorToSourceUtilsIde
.
getAnyDeclaration
(
project
,
it
)
?:
klass
,
it
)
}
if
(
ApplicationManager
.
getApplication
().
isUnitTestMode
||
candidates
.
size
<=
1
)
return
candidates
return
with
(
MemberChooser
(
candidates
.
toTypedArray
(),
false
,
true
,
klass
.
project
))
{
title
=
CodeInsightBundle
.
message
(
"generate.constructor.super.constructor.chooser.title"
)
setCopyJavadocVisible
(
false
)
show
()
selectedElements
?:
emptyList
()
}
}
private
fun
choosePropertiesToInitialize
(
klass
:
JetClassOrObject
,
context
:
BindingContext
):
List
<
DescriptorMemberChooserObject
>
{
val
candidates
=
klass
.
declarations
.
filterIsInstance
<
JetProperty
>()
.
filter
{
it
.
isVar
||
context
.
diagnostics
.
forElement
(
it
).
any
{
it
.
factory
in
Errors
.
MUST_BE_INITIALIZED_DIAGNOSTICS
}
}
.
map
{
context
.
get
(
BindingContext
.
VARIABLE
,
it
)
as
PropertyDescriptor
}
.
map
{
DescriptorMemberChooserObject
(
it
.
source
.
getPsi
()
!!
,
it
)
}
if
(
ApplicationManager
.
getApplication
().
isUnitTestMode
||
candidates
.
isEmpty
)
return
candidates
return
with
(
MemberChooser
(
candidates
.
toTypedArray
(),
true
,
true
,
klass
.
project
,
false
,
null
))
{
title
=
"Choose Properties to Initialize by Constructor"
setCopyJavadocVisible
(
false
)
selectElements
(
candidates
.
filter
{
shouldPreselect
(
it
.
element
)
}.
toTypedArray
())
show
()
selectedElements
?:
emptyList
()
}
}
override
fun
prepareMembersInfo
(
klass
:
JetClassOrObject
,
project
:
Project
):
Info
?
{
val
context
=
klass
.
analyzeFully
()
val
classDescriptor
=
context
.
get
(
BindingContext
.
CLASS
,
klass
)
?:
return
null
val
superConstructors
=
chooseSuperConstructors
(
klass
,
classDescriptor
).
map
{
it
.
descriptor
as
ConstructorDescriptor
}
val
propertiesToInitialize
=
choosePropertiesToInitialize
(
klass
,
context
).
map
{
it
.
descriptor
as
PropertyDescriptor
}
return
Info
(
propertiesToInitialize
,
superConstructors
,
classDescriptor
)
}
override
fun
generateMembers
(
editor
:
Editor
,
info
:
Info
):
List
<
JetDeclaration
>
{
val
targetClass
=
info
.
classDescriptor
.
source
.
getPsi
()
as
?
JetClass
?:
return
emptyList
()
fun
Info
.
findAnchor
():
PsiElement
?
{
targetClass
.
declarations
.
lastIsInstanceOrNull
<
JetSecondaryConstructor
>()
?.
let
{
return
it
}
val
lastPropertyToInitialize
=
propertiesToInitialize
.
lastOrNull
()
?.
source
?.
getPsi
()
val
declarationsAfter
=
lastPropertyToInitialize
?.
siblings
()
?.
filterIsInstance
<
JetDeclaration
>()
?:
targetClass
.
declarations
.
asSequence
()
val
firstNonProperty
=
declarationsAfter
.
firstOrNull
{
it
!
is
JetProperty
}
?:
return
null
return
firstNonProperty
.
siblings
(
forward
=
false
).
firstIsInstanceOrNull
<
JetProperty
>()
?:
targetClass
.
getOrCreateBody
().
lBrace
}
return
with
(
info
)
{
val
prototypes
=
if
(
superConstructors
.
isNotEmpty
())
{
superConstructors
.
map
{
generateConstructor
(
classDescriptor
,
propertiesToInitialize
,
it
)
}.
filterNotNull
()
}
else
{
generateConstructor
(
classDescriptor
,
propertiesToInitialize
,
null
).
singletonOrEmptyList
()
}
if
(
prototypes
.
isEmpty
)
{
CommonRefactoringUtil
.
showErrorHint
(
targetClass
.
project
,
editor
,
"Constructor already exists"
,
commandName
,
null
)
return
emptyList
()
}
insertMembersAfter
(
editor
,
targetClass
,
prototypes
,
findAnchor
())
}
}
private
fun
generateConstructor
(
classDescriptor
:
ClassDescriptor
,
propertiesToInitialize
:
List
<
PropertyDescriptor
>,
superConstructor
:
ConstructorDescriptor
?
):
JetSecondaryConstructor
?
{
fun
equalTypes
(
types1
:
Collection
<
JetType
>,
types2
:
Collection
<
JetType
>):
Boolean
{
return
types1
.
size
==
types2
.
size
&&
(
types1
.
zip
(
types2
)).
all
{
JetTypeChecker
.
DEFAULT
.
equalTypes
(
it
.
first
,
it
.
second
)
}
}
val
constructorParamTypes
=
propertiesToInitialize
.
map
{
it
.
type
}
+
(
superConstructor
?.
valueParameters
?.
map
{
it
.
varargElementType
?:
it
.
type
}
?:
emptyList
())
if
(
classDescriptor
.
constructors
.
any
{
it
.
source
.
getPsi
()
is
JetConstructor
<
*
>
&&
equalTypes
(
it
.
valueParameters
.
map
{
it
.
varargElementType
?:
it
.
type
},
constructorParamTypes
)
})
return
null
val
targetClass
=
classDescriptor
.
source
.
getPsi
()
as
JetClass
val
psiFactory
=
JetPsiFactory
(
targetClass
)
val
validator
=
CollectingNameValidator
()
val
constructor
=
psiFactory
.
createSecondaryConstructor
(
"constructor()"
)
val
parameterList
=
constructor
.
valueParameterList
!!
if
(
superConstructor
!=
null
)
{
val
substitutor
=
getTypeSubstitutor
(
superConstructor
.
containingDeclaration
.
defaultType
,
classDescriptor
.
defaultType
)
?:
TypeSubstitutor
.
EMPTY
val
delegationCallArguments
=
ArrayList
<
String
>()
for
(
parameter
in
superConstructor
.
valueParameters
)
{
val
isVararg
=
parameter
.
varargElementType
!=
null
val
paramName
=
KotlinNameSuggester
.
suggestNameByName
(
parameter
.
name
.
asString
(),
validator
)
val
typeToUse
=
parameter
.
varargElementType
?:
parameter
.
type
val
paramType
=
IdeDescriptorRenderers
.
SOURCE_CODE
.
renderType
(
substitutor
.
substitute
(
typeToUse
,
Variance
.
INVARIANT
)
?:
classDescriptor
.
builtIns
.
anyType
)
val
modifiers
=
if
(
isVararg
)
"vararg "
else
""
parameterList
.
addParameter
(
psiFactory
.
createParameter
(
"$modifiers$paramName: $paramType"
))
delegationCallArguments
.
add
(
if
(
isVararg
)
"*$paramName"
else
paramName
)
}
val
delegationCall
=
psiFactory
.
createConstructorDelegationCall
(
delegationCallArguments
.
joinToString
(
prefix
=
"super("
,
postfix
=
")"
))
constructor
.
replaceImplicitDelegationCallWithExplicit
(
false
).
replace
(
delegationCall
)
}
if
(
propertiesToInitialize
.
isNotEmpty
())
{
val
body
=
psiFactory
.
createEmptyBody
()
for
(
property
in
propertiesToInitialize
)
{
val
propertyName
=
property
.
name
val
paramName
=
KotlinNameSuggester
.
suggestNameByName
(
propertyName
.
asString
(),
validator
)
val
paramType
=
IdeDescriptorRenderers
.
SOURCE_CODE
.
renderType
(
property
.
type
)
parameterList
.
addParameter
(
psiFactory
.
createParameter
(
"$paramName: $paramType"
))
body
.
appendElement
(
psiFactory
.
createExpression
(
"this.$propertyName = $paramName"
),
true
)
}
constructor
.
add
(
body
)
}
return
constructor
}
}
\ No newline at end of file
idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateTestSupportActionBase.kt
浏览文件 @
30d69710
...
...
@@ -16,7 +16,6 @@
package
org.jetbrains.kotlin.idea.actions.generate
import
com.intellij.codeInsight.CodeInsightActionHandler
import
com.intellij.codeInsight.generation.actions.GenerateActionPopupTemplateInjector
import
com.intellij.codeInsight.hint.HintManager
import
com.intellij.ide.fileTemplates.FileTemplateManager
...
...
@@ -48,7 +47,7 @@ import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObj
import
org.jetbrains.kotlin.idea.core.overrideImplement.generateUnsupportedOrSuperCall
import
org.jetbrains.kotlin.idea.core.refactoring.j2k
import
org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.setupEditorSelection
import
org.jetbrains.kotlin.idea.quickfix.
generate
Member
import
org.jetbrains.kotlin.idea.quickfix.
insert
Member
import
org.jetbrains.kotlin.idea.testIntegration.findSuitableFrameworks
import
org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import
org.jetbrains.kotlin.lexer.JetTokens
...
...
@@ -117,82 +116,74 @@ abstract class KotlinGenerateTestSupportActionBase(
}
}
private
inner
class
HandlerImpl
:
CodeInsightActionHandler
{
override
fun
startInWriteAction
()
=
false
override
fun
getTargetClass
(
editor
:
Editor
,
file
:
PsiFile
):
JetClassOrObject
?
{
return
findTargetClass
(
editor
,
file
)
}
override
fun
invoke
(
project
:
Project
,
editor
:
Editor
,
file
:
PsiFile
)
{
val
klass
=
findTargetClass
(
editor
,
file
)
?:
return
val
frameworks
=
findSuitableFrameworks
(
klass
)
.
filter
{
methodKind
.
getFileTemplateDescriptor
(
it
)
!=
null
&&
isApplicableTo
(
it
,
klass
)
}
chooseAndPerform
(
editor
,
frameworks
)
{
doGenerate
(
editor
,
file
,
klass
,
it
)
}
}
override
fun
isValidForClass
(
targetClass
:
JetClassOrObject
):
Boolean
{
return
findSuitableFrameworks
(
targetClass
).
any
{
isApplicableTo
(
it
,
targetClass
)
}
}
private
fun
doGenerate
(
editor
:
Editor
,
file
:
PsiFile
,
klass
:
JetClassOrObject
,
framework
:
TestFramework
)
{
val
project
=
file
.
project
val
commandName
=
"Generate test function"
project
.
executeWriteCommand
(
commandName
)
{
try
{
PsiDocumentManager
.
getInstance
(
project
).
commitAllDocuments
()
val
fileTemplateDescriptor
=
methodKind
.
getFileTemplateDescriptor
(
framework
)
val
fileTemplate
=
FileTemplateManager
.
getInstance
(
project
).
getCodeTemplate
(
fileTemplateDescriptor
.
fileName
)
var
templateText
=
fileTemplate
.
text
.
replace
(
BODY_VAR
,
""
)
if
(
templateText
.
contains
(
NAME_VAR
))
{
var
name
=
"Name"
if
(!
ApplicationManager
.
getApplication
().
isUnitTestMode
)
{
name
=
Messages
.
showInputDialog
(
"Choose test name: "
,
commandName
,
null
,
name
,
NAME_VALIDATOR
)
?:
return
@executeWriteCommand
}
templateText
=
fileTemplate
.
text
.
replace
(
NAME_VAR
,
name
)
}
val
factory
=
PsiElementFactory
.
SERVICE
.
getInstance
(
project
)
val
psiMethod
=
factory
.
createMethodFromText
(
templateText
,
null
)
psiMethod
.
throwsList
.
referenceElements
.
forEach
{
it
.
delete
()
}
val
function
=
psiMethod
.
j2k
()
as
?
JetNamedFunction
if
(
function
==
null
)
{
HintManager
.
getInstance
().
showErrorHint
(
editor
,
"Couldn't convert Java template to Kotlin"
)
return
@executeWriteCommand
}
val
functionInPlace
=
generateMember
(
editor
,
klass
,
function
)
val
functionDescriptor
=
functionInPlace
.
resolveToDescriptor
()
as
FunctionDescriptor
val
overriddenDescriptors
=
functionDescriptor
.
overriddenDescriptors
val
bodyText
=
when
(
overriddenDescriptors
.
size
())
{
0
->
generateUnsupportedOrSuperCall
(
functionDescriptor
,
BodyType
.
EMPTY
)
1
->
generateUnsupportedOrSuperCall
(
overriddenDescriptors
.
single
(),
BodyType
.
SUPER
)
else
->
generateUnsupportedOrSuperCall
(
overriddenDescriptors
.
first
(),
BodyType
.
QUALIFIED_SUPER
)
}
functionInPlace
.
bodyExpression
?.
delete
()
functionInPlace
.
add
(
JetPsiFactory
(
project
).
createBlock
(
bodyText
))
protected
abstract
fun
isApplicableTo
(
framework
:
TestFramework
,
targetClass
:
JetClassOrObject
):
Boolean
if
(
overriddenDescriptors
.
isNotEmpty
())
{
functionInPlace
.
addModifier
(
JetTokens
.
OVERRIDE_KEYWORD
)
override
fun
invoke
(
project
:
Project
,
editor
:
Editor
,
file
:
PsiFile
)
{
val
klass
=
findTargetClass
(
editor
,
file
)
?:
return
val
frameworks
=
findSuitableFrameworks
(
klass
)
.
filter
{
methodKind
.
getFileTemplateDescriptor
(
it
)
!=
null
&&
isApplicableTo
(
it
,
klass
)
}
chooseAndPerform
(
editor
,
frameworks
)
{
doGenerate
(
editor
,
file
,
klass
,
it
)
}
}
private
fun
doGenerate
(
editor
:
Editor
,
file
:
PsiFile
,
klass
:
JetClassOrObject
,
framework
:
TestFramework
)
{
val
project
=
file
.
project
val
commandName
=
"Generate test function"
project
.
executeWriteCommand
(
commandName
)
{
try
{
PsiDocumentManager
.
getInstance
(
project
).
commitAllDocuments
()
val
fileTemplateDescriptor
=
methodKind
.
getFileTemplateDescriptor
(
framework
)
val
fileTemplate
=
FileTemplateManager
.
getInstance
(
project
).
getCodeTemplate
(
fileTemplateDescriptor
.
fileName
)
var
templateText
=
fileTemplate
.
text
.
replace
(
BODY_VAR
,
""
)
if
(
templateText
.
contains
(
NAME_VAR
))
{
var
name
=
"Name"
if
(!
ApplicationManager
.
getApplication
().
isUnitTestMode
)
{
name
=
Messages
.
showInputDialog
(
"Choose test name: "
,
commandName
,
null
,
name
,
NAME_VALIDATOR
)
?:
return
@executeWriteCommand
}
setupEditorSelection
(
editor
,
functionInPlac
e
)
templateText
=
fileTemplate
.
text
.
replace
(
NAME_VAR
,
nam
e
)
}
catch
(
e
:
IncorrectOperationException
)
{
HintManager
.
getInstance
().
showErrorHint
(
editor
,
"Cannot generate method: "
+
e
.
getMessage
())
val
factory
=
PsiElementFactory
.
SERVICE
.
getInstance
(
project
)
val
psiMethod
=
factory
.
createMethodFromText
(
templateText
,
null
)
psiMethod
.
throwsList
.
referenceElements
.
forEach
{
it
.
delete
()
}
val
function
=
psiMethod
.
j2k
()
as
?
JetNamedFunction
if
(
function
==
null
)
{
HintManager
.
getInstance
().
showErrorHint
(
editor
,
"Couldn't convert Java template to Kotlin"
)
return
@executeWriteCommand
}
}
}
}
private
val
handler
=
HandlerImpl
()
override
fun
getHandler
()
=
handler
val
functionInPlace
=
insertMember
(
editor
,
klass
,
function
)
val
functionDescriptor
=
functionInPlace
.
resolveToDescriptor
()
as
FunctionDescriptor
val
overriddenDescriptors
=
functionDescriptor
.
overriddenDescriptors
val
bodyText
=
when
(
overriddenDescriptors
.
size
)
{
0
->
generateUnsupportedOrSuperCall
(
functionDescriptor
,
BodyType
.
EMPTY
)
1
->
generateUnsupportedOrSuperCall
(
overriddenDescriptors
.
single
(),
BodyType
.
SUPER
)
else
->
generateUnsupportedOrSuperCall
(
overriddenDescriptors
.
first
(),
BodyType
.
QUALIFIED_SUPER
)
}
functionInPlace
.
bodyExpression
?.
delete
()
functionInPlace
.
add
(
JetPsiFactory
(
project
).
createBlock
(
bodyText
))
override
fun
getTargetClass
(
editor
:
Editor
,
file
:
PsiFile
):
JetClassOrObject
?
{
return
findTargetClass
(
editor
,
file
)
}
if
(
overriddenDescriptors
.
isNotEmpty
())
{
functionInPlace
.
addModifier
(
JetTokens
.
OVERRIDE_KEYWORD
)
}
override
fun
isValidForClass
(
targetClass
:
JetClassOrObject
):
Boolean
{
return
findSuitableFrameworks
(
targetClass
).
any
{
isApplicableTo
(
it
,
targetClass
)
}
setupEditorSelection
(
editor
,
functionInPlace
)
}
catch
(
e
:
IncorrectOperationException
)
{
HintManager
.
getInstance
().
showErrorHint
(
editor
,
"Cannot generate method: "
+
e
.
getMessage
())
}
}
}
protected
abstract
fun
isApplicableTo
(
framework
:
TestFramework
,
targetClass
:
JetClassOrObject
):
Boolean
override
fun
createEditTemplateAction
(
dataContext
:
DataContext
):
AnAction
?
{
val
project
=
CommonDataKeys
.
PROJECT
.
getData
(
dataContext
)
?:
return
null
val
editor
=
CommonDataKeys
.
EDITOR
.
getData
(
dataContext
)
?:
return
null
...
...
idea/testData/codeInsight/generate/secondaryConstructors/empty.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
// WITH_RUNTIME
class
Foo
{<
caret
>
val
x
=
1
val
y
:
Int
val
z
:
Int
get
()
=
3
val
u
:
Int
by
lazy
{
4
}
init
{
y
=
2
}
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/empty.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
// WITH_RUNTIME
class Foo {
val x = 1
val y: Int
val z: Int get() = 3
val u: Int by lazy { 4 }
<caret>constructor()
init {
y = 2
}
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/emptyExists.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
// WITH_RUNTIME
class
Foo
{<
caret
>
constructor
()
{
}
val
x
=
1
val
y
:
Int
val
z
:
Int
get
()
=
3
val
u
:
Int
by
lazy
{
4
}
init
{
y
=
2
}
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/emptyExists.kt.messages
0 → 100644
浏览文件 @
30d69710
Constructor already exists
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.java
0 → 100644
浏览文件 @
30d69710
public
class
Base
<
X
,
Y
>
{
public
Base
(
X
x
)
{
}
public
Base
(
X
x
,
Y
y
)
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
class
Foo
<
U
>
:
Base
<
U
,
Int
>
{<
caret
>
val
x
=
1
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
class Foo<U> : Base<U, Int> {
val x = 1
<caret>constructor(x: U) : super(x)
constructor(x: U, y: Int?) : super(x, y)
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/properties.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
class
Foo
{<
caret
>
val
n
:
Int
val
x
=
1
val
m
:
Int
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/properties.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
class Foo {
val n: Int
val x = 1
val m: Int
<caret>constructor(n: Int, m: Int) {
this.n = n
this.m = m
}
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/propertiesWithSupers.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
(
n
:
Int
)
{
constructor
(
a
:
Int
,
b
:
Int
):
this
(
a
+
b
)
}
class
Foo
:
Base
{<
caret
>
val
n
:
Int
val
x
=
1
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/propertiesWithSupers.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base(n: Int) {
constructor(a: Int, b: Int): this(a + b)
}
class Foo : Base {
val n: Int
val x = 1
<caret>constructor(a: Int, b: Int, n: Int) : super(a, b) {
this.n = n
}
constructor(n: Int, n1: Int) : super(n) {
this.n = n1
}
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supers.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
(
n
:
Int
)
{
constructor
(
a
:
Int
,
b
:
Int
):
this
(
a
+
b
)
}
class
Foo
:
Base
{<
caret
>
val
x
=
1
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supers.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base(n: Int) {
constructor(a: Int, b: Int): this(a + b)
}
class Foo : Base {
val x = 1
<caret>constructor(a: Int, b: Int) : super(a, b)
constructor(n: Int) : super(n)
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersAllExist.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
(
n
:
Int
)
{
constructor
(
a
:
Int
,
b
:
Int
):
this
(
a
+
b
)
}
class
Foo
:
Base
{<
caret
>
val
x
=
1
constructor
(
t
:
Int
,
u
:
Int
)
:
super
(
u
,
t
)
constructor
(
x
:
Int
)
:
super
(
x
)
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersAllExist.kt.messages
0 → 100644
浏览文件 @
30d69710
Constructor already exists
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersPrimaryExists.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
(
n
:
Int
)
{
constructor
(
a
:
Int
,
b
:
Int
):
this
(
a
+
b
)
}
class
Foo
(
x
:
Int
)
:
Base
(
x
)
{<
caret
>
val
x
=
1
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersPrimaryExists.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base(n: Int) {
constructor(a: Int, b: Int): this(a + b)
}
class Foo(x: Int) : Base(x) {
val x = 1
<caret>constructor(a: Int, b: Int) : super(a, b)
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersSomeExist.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
(
n
:
Int
)
{
constructor
(
a
:
Int
,
b
:
Int
):
this
(
a
+
b
)
}
class
Foo
:
Base
{<
caret
>
val
x
=
1
constructor
(
x
:
Int
)
:
super
(
x
)
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersSomeExist.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base(n: Int) {
constructor(a: Int, b: Int): this(a + b)
}
class Foo : Base {
val x = 1
constructor(x: Int) : super(x)
<caret>constructor(a: Int, b: Int) : super(a, b)
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersWithGenerics.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
<
X
,
Y
>(
n
:
X
)
{
constructor
(
x
:
X
,
y
:
Y
):
this
(
x
)
}
class
Foo
<
U
>
:
Base
<
U
,
Int
>
{<
caret
>
val
x
=
1
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersWithGenerics.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base<X, Y>(n: X) {
constructor(x: X, y: Y): this(x)
}
class Foo<U> : Base<U, Int> {
val x = 1
<caret>constructor(x: U, y: Int) : super(x, y)
constructor(n: U) : super(n)
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersWithVarargs.kt
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open
class
Base
{
constructor
(
a
:
Int
,
vararg
b
:
Int
)
}
class
Foo
:
Base
{<
caret
>
val
x
=
1
fun
foo
()
{
}
fun
bar
()
{
}
}
\ No newline at end of file
idea/testData/codeInsight/generate/secondaryConstructors/supersWithVarargs.kt.after
0 → 100644
浏览文件 @
30d69710
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateSecondaryConstructorAction
open class Base {
constructor(a: Int, vararg b: Int)
}
class Foo : Base {
val x = 1
<caret>constructor(a: Int, vararg b: Int) : super(a, *b)
fun foo() {
}
fun bar() {
}
}
\ No newline at end of file
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateActionTest.kt
浏览文件 @
30d69710
...
...
@@ -17,39 +17,37 @@
package
org.jetbrains.kotlin.idea.codeInsight.generate
import
com.intellij.codeInsight.actions.CodeInsightAction
import
com.intellij.openapi.roots.ModuleRootManager
import
com.intellij.openapi.util.io.FileUtil
import
com.intellij.refactoring.util.CommonRefactoringUtil
import
com.intellij.testFramework.PlatformTestUtil
import
junit.framework.TestCase
import
org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import
org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase
import
org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor
import
org.jetbrains.kotlin.idea.util.application.runWriteAction
import
org.jetbrains.kotlin.test.InTextDirectivesUtils
import
org.jetbrains.kotlin.test.JetTestUtils
import
java.io.File
abstract
class
AbstractGenerateActionTest
:
JetLightCodeInsightFixtureTestCase
()
{
private
fun
setUpTestSourceRoot
()
{
val
module
=
myModule
val
model
=
ModuleRootManager
.
getInstance
(
module
).
modifiableModel
val
entry
=
model
.
contentEntries
.
single
()
val
sourceFolderFile
=
entry
.
sourceFolderFiles
.
single
()
entry
.
removeSourceFolder
(
entry
.
sourceFolders
.
single
())
entry
.
addSourceFolder
(
sourceFolderFile
,
true
)
runWriteAction
{
model
.
commit
()
module
.
project
.
save
()
}
}
protected
fun
doTest
(
path
:
String
)
{
setUpTestSourceRoot
()
protected
open
fun
doTest
(
path
:
String
)
{
val
fileText
=
FileUtil
.
loadFile
(
File
(
path
),
true
)
val
conflictFile
=
File
(
"$path.messages"
)
try
{
ConfigLibraryUtil
.
configureLibrariesByDirective
(
myModule
,
PlatformTestUtil
.
getCommunityPath
(),
fileText
)
val
mainFile
=
File
(
path
)
val
mainFileName
=
mainFile
.
name
val
fileNameBase
=
mainFile
.
nameWithoutExtension
val
rootDir
=
mainFile
.
parentFile
rootDir
.
list
{
file
,
name
->
name
.
startsWith
(
fileNameBase
)
&&
name
!=
mainFileName
&&
(
name
.
endsWith
(
".kt"
)
||
name
.
endsWith
(
".java"
))
}
.
forEach
{
myFixture
.
configureByFile
(
File
(
rootDir
,
it
).
path
.
replace
(
File
.
separator
,
"/"
))
}
myFixture
.
configureByFile
(
path
)
val
actionClassName
=
InTextDirectivesUtils
.
findStringWithPrefixes
(
fileText
,
"// ACTION_CLASS: "
)
...
...
@@ -60,12 +58,17 @@ abstract class AbstractGenerateActionTest : JetLightCodeInsightFixtureTestCase()
val
presentation
=
myFixture
.
testAction
(
action
)
TestCase
.
assertEquals
(
isApplicableExpected
,
presentation
.
isEnabled
)
assert
(!
conflictFile
.
exists
())
{
"Conflict file $conflictFile should not exist"
}
if
(
isApplicableExpected
)
{
val
afterFile
=
File
(
path
+
"
.after"
)
val
afterFile
=
File
(
"$path
.after"
)
TestCase
.
assertTrue
(
afterFile
.
exists
())
myFixture
.
checkResult
(
FileUtil
.
loadFile
(
afterFile
,
true
))
}
}
catch
(
e
:
CommonRefactoringUtil
.
RefactoringErrorHintException
)
{
JetTestUtils
.
assertEqualsToFile
(
conflictFile
,
e
.
getMessage
()
!!
)
}
finally
{
ConfigLibraryUtil
.
unconfigureLibrariesByDirective
(
myModule
,
fileText
)
}
...
...
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateTestSupportMethodActionTest.kt
0 → 100644
浏览文件 @
30d69710
/*
* Copyright 2010-2015 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.kotlin.idea.codeInsight.generate
import
com.intellij.openapi.roots.ModuleRootManager
import
org.jetbrains.kotlin.idea.util.application.runWriteAction
abstract
class
AbstractGenerateTestSupportMethodActionTest
:
AbstractGenerateActionTest
()
{
private
fun
setUpTestSourceRoot
()
{
val
module
=
myModule
val
model
=
ModuleRootManager
.
getInstance
(
module
).
modifiableModel
val
entry
=
model
.
contentEntries
.
single
()
val
sourceFolderFile
=
entry
.
sourceFolderFiles
.
single
()
entry
.
removeSourceFolder
(
entry
.
sourceFolders
.
single
())
entry
.
addSourceFolder
(
sourceFolderFile
,
true
)
runWriteAction
{
model
.
commit
()
module
.
project
.
save
()
}
}
override
fun
doTest
(
path
:
String
)
{
setUpTestSourceRoot
()
super
.
doTest
(
path
)
}
}
\ No newline at end of file
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateActionTestGenerated.java
浏览文件 @
30d69710
...
...
@@ -27,161 +27,77 @@ import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings
(
"all"
)
@TestMetadata
(
"idea/testData/codeInsight/generate"
)
@TestMetadata
(
"idea/testData/codeInsight/generate
/secondaryConstructors
"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
class
GenerateActionTestGenerated
extends
AbstractGenerateActionTest
{
public
void
testAllFilesPresentIn
Generate
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
public
void
testAllFilesPresentIn
SecondaryConstructors
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate
/secondaryConstructors
"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
TestFrameworkSupport
extends
AbstractGenerateActionTest
{
public
void
testAllFilesPresentInTestFrameworkSupport
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
JUnit4
extends
AbstractGenerateActionTest
{
public
void
testAllFilesPresentInJUnit4
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"dataMethod.kt"
)
public
void
testDataMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUp.kt"
)
public
void
testSetUp
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpExists.kt"
)
public
void
testSetUpExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpOverrides.kt"
)
public
void
testSetUpOverrides
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown.kt"
)
public
void
testTearDown
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDownExists.kt"
)
public
void
testTearDownExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"testMethod.kt"
)
public
void
testTestMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
Junit3
extends
AbstractGenerateActionTest
{
public
void
testAllFilesPresentInJunit3
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"setUp.kt"
)
public
void
testSetUp
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpExists.kt"
)
public
void
testSetUpExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUpExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown.kt"
)
public
void
testTearDown
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"empty.kt"
)
public
void
testEmpty
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/empty.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown
Exists.kt"
)
public
void
testTearDown
Exists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown
Exists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"empty
Exists.kt"
)
public
void
testEmpty
Exists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/empty
Exists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"testMethod.kt"
)
public
void
testTestMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"javaSupers.kt"
)
public
void
testJavaSupers
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/javaSupers.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
TestNG
extends
AbstractGenerateActionTest
{
public
void
testAllFilesPresentInTestNG
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"properties.kt"
)
public
void
testProperties
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/properties.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"dataMethod
.kt"
)
public
void
testDataMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"propertiesWithSupers
.kt"
)
public
void
testPropertiesWithSupers
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/propertiesWithSupers
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUp
.kt"
)
public
void
testSetUp
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"supers
.kt"
)
public
void
testSupers
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/supers
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpExists
.kt"
)
public
void
testSetUpExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpExists
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"supersAllExist
.kt"
)
public
void
testSupersAllExist
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/supersAllExist
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpOverride
s.kt"
)
public
void
testSetUpOverride
s
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverride
s.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"supersPrimaryExist
s.kt"
)
public
void
testSupersPrimaryExist
s
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/supersPrimaryExist
s.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown
.kt"
)
public
void
testTearDown
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"supersSomeExist
.kt"
)
public
void
testSupersSomeExist
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/supersSomeExist
.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDownExist
s.kt"
)
public
void
testTearDownExist
s
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDownExist
s.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"supersWithGeneric
s.kt"
)
public
void
testSupersWithGeneric
s
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/supersWithGeneric
s.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"testMethod.kt"
)
public
void
testTestMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"supersWithVarargs.kt"
)
public
void
testSupersWithVarargs
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/secondaryConstructors/supersWithVarargs.kt"
);
doTest
(
fileName
);
}
}
idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateTestSupportMethodActionTestGenerated.java
0 → 100644
浏览文件 @
30d69710
/*
* Copyright 2010-2015 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.kotlin.idea.codeInsight.generate
;
import
com.intellij.testFramework.TestDataPath
;
import
org.jetbrains.kotlin.test.JUnit3RunnerWithInners
;
import
org.jetbrains.kotlin.test.JetTestUtils
;
import
org.jetbrains.kotlin.test.TestMetadata
;
import
org.junit.runner.RunWith
;
import
java.io.File
;
import
java.util.regex.Pattern
;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings
(
"all"
)
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
class
GenerateTestSupportMethodActionTestGenerated
extends
AbstractGenerateTestSupportMethodActionTest
{
public
void
testAllFilesPresentInTestFrameworkSupport
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
JUnit4
extends
AbstractGenerateTestSupportMethodActionTest
{
public
void
testAllFilesPresentInJUnit4
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"dataMethod.kt"
)
public
void
testDataMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUp.kt"
)
public
void
testSetUp
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpExists.kt"
)
public
void
testSetUpExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpOverrides.kt"
)
public
void
testSetUpOverrides
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown.kt"
)
public
void
testTearDown
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDownExists.kt"
)
public
void
testTearDownExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"testMethod.kt"
)
public
void
testTestMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
Junit3
extends
AbstractGenerateTestSupportMethodActionTest
{
public
void
testAllFilesPresentInJunit3
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"setUp.kt"
)
public
void
testSetUp
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpExists.kt"
)
public
void
testSetUpExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUpExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown.kt"
)
public
void
testTearDown
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDownExists.kt"
)
public
void
testTearDownExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDownExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"testMethod.kt"
)
public
void
testTestMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG"
)
@TestDataPath
(
"$PROJECT_ROOT"
)
@RunWith
(
JUnit3RunnerWithInners
.
class
)
public
static
class
TestNG
extends
AbstractGenerateTestSupportMethodActionTest
{
public
void
testAllFilesPresentInTestNG
()
throws
Exception
{
JetTestUtils
.
assertAllTestsPresentByMetadata
(
this
.
getClass
(),
new
File
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG"
),
Pattern
.
compile
(
"^(.+)\\.kt$"
),
true
);
}
@TestMetadata
(
"dataMethod.kt"
)
public
void
testDataMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUp.kt"
)
public
void
testSetUp
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpExists.kt"
)
public
void
testSetUpExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"setUpOverrides.kt"
)
public
void
testSetUpOverrides
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDown.kt"
)
public
void
testTearDown
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"tearDownExists.kt"
)
public
void
testTearDownExists
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDownExists.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"testMethod.kt"
)
public
void
testTestMethod
()
throws
Exception
{
String
fileName
=
JetTestUtils
.
navigationMetadata
(
"idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt"
);
doTest
(
fileName
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录