Create from Usage: Support class generation by class literal expression

#KT-16188 Fixed
This commit is contained in:
Alexey Sedunov
2017-02-09 13:06:12 +03:00
parent 505a6bcbf2
commit 834cdd63ab
14 changed files with 120 additions and 0 deletions
@@ -87,6 +87,10 @@ object CreateClassFromReferenceExpressionActionFactory : CreateClassFromUsageFac
}
}
}
val parent = element.parent
if (parent is KtClassLiteralExpression && parent.receiverExpression == element) {
return listOf(ClassKind.PLAIN_CLASS, ClassKind.ENUM_CLASS, ClassKind.INTERFACE, ClassKind.ANNOTATION_CLASS, ClassKind.OBJECT)
}
if (fullCallExpr.getAssignmentByLHS() != null) return Collections.emptyList()
@@ -5,6 +5,10 @@
// ACTION: Create parameter 'CoroutineImpl'
// ACTION: Create property 'CoroutineImpl'
// ACTION: Introduce local variable
// ACTION: Create annotation 'CoroutineImpl'
// ACTION: Create class 'CoroutineImpl'
// ACTION: Create enum 'CoroutineImpl'
// ACTION: Create interface 'CoroutineImpl'
// ACTION: Rename reference
// ERROR: Unresolved reference: CoroutineImpl
@@ -4,6 +4,10 @@
// ACTION: Create object 'FunctionReference'
// ACTION: Create parameter 'FunctionReference'
// ACTION: Create property 'FunctionReference'
// ACTION: Create annotation 'FunctionReference'
// ACTION: Create class 'FunctionReference'
// ACTION: Create enum 'FunctionReference'
// ACTION: Create interface 'FunctionReference'
// ACTION: Introduce local variable
// ACTION: Rename reference
// ERROR: Unresolved reference: FunctionReference
@@ -0,0 +1,6 @@
// "Create annotation 'Foo'" "true"
class Test{
fun doSth(){
<caret>Foo::class.java
}
}
@@ -0,0 +1,8 @@
// "Create annotation 'Foo'" "true"
class Test{
fun doSth(){
Foo::class.java
}
}
<caret>annotation class Foo
@@ -0,0 +1,6 @@
// "Create class 'Foo'" "true"
class Test{
fun doSth(){
<caret>Foo::class.java
}
}
@@ -0,0 +1,10 @@
// "Create class 'Foo'" "true"
class Test{
fun doSth(){
Foo::class.java
}
}
<caret>class Foo {
}
@@ -0,0 +1,6 @@
// "Create enum 'Foo'" "true"
class Test{
fun doSth(){
<caret>Foo::class.java
}
}
@@ -0,0 +1,10 @@
// "Create enum 'Foo'" "true"
class Test{
fun doSth(){
Foo::class.java
}
}
<caret>enum class Foo {
}
@@ -0,0 +1,6 @@
// "Create interface 'Foo'" "true"
class Test{
fun doSth(){
<caret>Foo::class.java
}
}
@@ -0,0 +1,10 @@
// "Create interface 'Foo'" "true"
class Test{
fun doSth(){
Foo::class.java
}
}
<caret>interface Foo {
}
@@ -0,0 +1,6 @@
// "Create object 'Foo'" "true"
class Test{
fun doSth(){
<caret>Foo::class.java
}
}
@@ -0,0 +1,10 @@
// "Create object 'Foo'" "true"
class Test{
fun doSth(){
Foo::class.java
}
}
<caret>object Foo {
}
@@ -1727,12 +1727,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass/referenceExpression"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("annotationByClassLiteral.kt")
public void testAnnotationByClassLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/annotationByClassLiteral.kt");
doTest(fileName);
}
@TestMetadata("annotationNoReceiver.kt")
public void testAnnotationNoReceiver() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/annotationNoReceiver.kt");
doTest(fileName);
}
@TestMetadata("classByClassLiteral.kt")
public void testClassByClassLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/classByClassLiteral.kt");
doTest(fileName);
}
@TestMetadata("classByNestedQualifier.kt")
public void testClassByNestedQualifier() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/classByNestedQualifier.kt");
@@ -1769,6 +1781,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("enumByClassLiteral.kt")
public void testEnumByClassLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumByClassLiteral.kt");
doTest(fileName);
}
@TestMetadata("enumByQualifier.kt")
public void testEnumByQualifier() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumByQualifier.kt");
@@ -1835,6 +1853,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("interfaceByClassLiteral.kt")
public void testInterfaceByClassLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/interfaceByClassLiteral.kt");
doTest(fileName);
}
@TestMetadata("objectByClassLiteral.kt")
public void testObjectByClassLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/objectByClassLiteral.kt");
doTest(fileName);
}
@TestMetadata("objectByQualifier.kt")
public void testObjectByQualifier() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/objectByQualifier.kt");