Create from Usage: Support class generation by class literal expression
#KT-16188 Fixed
This commit is contained in:
+4
@@ -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
|
||||
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// "Create annotation 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
<caret>Foo::class.java
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Create annotation 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
Foo::class.java
|
||||
}
|
||||
}
|
||||
|
||||
<caret>annotation class Foo
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// "Create class 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
<caret>Foo::class.java
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// "Create class 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
Foo::class.java
|
||||
}
|
||||
}
|
||||
|
||||
<caret>class Foo {
|
||||
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// "Create enum 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
<caret>Foo::class.java
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// "Create enum 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
Foo::class.java
|
||||
}
|
||||
}
|
||||
|
||||
<caret>enum class Foo {
|
||||
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// "Create interface 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
<caret>Foo::class.java
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Create interface 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
Foo::class.java
|
||||
}
|
||||
}
|
||||
|
||||
<caret>interface Foo {
|
||||
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// "Create object 'Foo'" "true"
|
||||
class Test{
|
||||
fun doSth(){
|
||||
<caret>Foo::class.java
|
||||
}
|
||||
}
|
||||
idea/testData/quickfix/createFromUsage/createClass/referenceExpression/objectByClassLiteral.kt.after
Vendored
+10
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user