Create from usage: Removed quickfix for NO_CLASS_OBJECT.
This commit is contained in:
@@ -145,7 +145,6 @@ map.platform.class.to.kotlin.advertisement=Choose an appropriate Kotlin class
|
|||||||
map.platform.class.to.kotlin.family=Change to Kotlin class
|
map.platform.class.to.kotlin.family=Change to Kotlin class
|
||||||
create.from.usage.family=Create from usage
|
create.from.usage.family=Create from usage
|
||||||
create.method.from.usage=Create method ''{0}'' from usage
|
create.method.from.usage=Create method ''{0}'' from usage
|
||||||
create.class.object.from.usage=Create class object from usage
|
|
||||||
choose.target.class.or.trait.title=Choose target class or trait
|
choose.target.class.or.trait.title=Choose target class or trait
|
||||||
surround.with=Surround with
|
surround.with=Surround with
|
||||||
surround.with.string.template="${expr}"
|
surround.with.string.template="${expr}"
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.quickfix;
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.intention.IntentionAction;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import com.intellij.psi.PsiReference;
|
|
||||||
import com.intellij.util.IncorrectOperationException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
|
||||||
|
|
||||||
public class CreateClassObjectFromUsageFix extends CreateFromUsageFixBase {
|
|
||||||
private final JetClass klass;
|
|
||||||
|
|
||||||
public CreateClassObjectFromUsageFix(@NotNull PsiElement element, @NotNull JetClass klass) {
|
|
||||||
super(element);
|
|
||||||
this.klass = klass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getText() {
|
|
||||||
return JetBundle.message("create.class.object.from.usage");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
|
||||||
PsiFile containingFile = klass.getContainingFile();
|
|
||||||
VirtualFile virtualFile = containingFile.getVirtualFile();
|
|
||||||
assert virtualFile != null;
|
|
||||||
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
|
|
||||||
fileEditorManager.openFile(virtualFile, true);
|
|
||||||
|
|
||||||
JetClassBody classBody = klass.getBody();
|
|
||||||
if (classBody == null) {
|
|
||||||
classBody = (JetClassBody) klass.add(JetPsiFactory.createEmptyClassBody(project));
|
|
||||||
klass.addBefore(JetPsiFactory.createWhiteSpace(project), classBody);
|
|
||||||
}
|
|
||||||
PsiElement lBrace = classBody.getLBrace();
|
|
||||||
JetClassObject classObject = (JetClassObject) classBody.addAfter(JetPsiFactory.createEmptyClassObject(project), lBrace);
|
|
||||||
classBody.addBefore(JetPsiFactory.createNewLine(project), classObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JetIntentionActionFactory createCreateClassObjectFromUsageFactory() {
|
|
||||||
return new JetIntentionActionFactory() {
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
|
||||||
JetReferenceExpression refExpr = QuickFixUtil.getParentElementOfType(diagnostic, JetReferenceExpression.class);
|
|
||||||
if (refExpr == null) return null;
|
|
||||||
PsiReference reference = refExpr.getReference();
|
|
||||||
if (reference == null) return null;
|
|
||||||
PsiElement resolvedReference = reference.resolve();
|
|
||||||
if (resolvedReference == null || !(resolvedReference instanceof JetClass)) return null;
|
|
||||||
JetClass klass = (JetClass) resolvedReference;
|
|
||||||
if (!klass.isWritable()) return null;
|
|
||||||
return new CreateClassObjectFromUsageFix(refExpr, (JetClass) resolvedReference);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -250,6 +250,5 @@ public class QuickFixes {
|
|||||||
factories.put(NEXT_NONE_APPLICABLE, createNextFromUsageFactory);
|
factories.put(NEXT_NONE_APPLICABLE, createNextFromUsageFactory);
|
||||||
factories.put(ITERATOR_MISSING, CreateMethodFromUsageFix.createCreateIteratorMethodFromUsageFactory());
|
factories.put(ITERATOR_MISSING, CreateMethodFromUsageFix.createCreateIteratorMethodFromUsageFactory());
|
||||||
factories.put(COMPONENT_FUNCTION_MISSING, CreateMethodFromUsageFix.createCreateComponentMethodFromUsageFactory());
|
factories.put(COMPONENT_FUNCTION_MISSING, CreateMethodFromUsageFix.createCreateComponentMethodFromUsageFactory());
|
||||||
factories.put(NO_CLASS_OBJECT, CreateClassObjectFromUsageFix.createCreateClassObjectFromUsageFactory());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
// "Create class object from usage" "true"
|
|
||||||
// ERROR: Expression 'T' of type '<class-object-for-T>' cannot be invoked as a function
|
|
||||||
trait T {
|
|
||||||
class object {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
fun foo() {
|
|
||||||
val x = T()
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// "Create class object from usage" "true"
|
|
||||||
// ERROR: Expression 'T' of type '<class-object-for-T>' cannot be invoked as a function
|
|
||||||
trait T
|
|
||||||
{
|
|
||||||
class object {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fun foo() {
|
|
||||||
val x = T()
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// "Create class object from usage" "true"
|
|
||||||
// ERROR: Expression 'T' of type '<class-object-for-T>' cannot be invoked as a function
|
|
||||||
trait T {
|
|
||||||
|
|
||||||
}
|
|
||||||
fun foo() {
|
|
||||||
val x = T<caret>()
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Create class object from usage" "true"
|
|
||||||
// ERROR: Expression 'T' of type '<class-object-for-T>' cannot be invoked as a function
|
|
||||||
trait T
|
|
||||||
fun foo() {
|
|
||||||
val x = T<caret>()
|
|
||||||
}
|
|
||||||
@@ -430,30 +430,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/createFromUsage")
|
@TestMetadata("idea/testData/quickfix/createFromUsage")
|
||||||
@InnerTestClasses({CreateFromUsage.ClassObject.class, CreateFromUsage.Component.class, CreateFromUsage.Get.class, CreateFromUsage.HasNext.class, CreateFromUsage.Iterator.class, CreateFromUsage.Next.class, CreateFromUsage.Set.class})
|
@InnerTestClasses({CreateFromUsage.Component.class, CreateFromUsage.Get.class, CreateFromUsage.HasNext.class, CreateFromUsage.Iterator.class, CreateFromUsage.Next.class, CreateFromUsage.Set.class})
|
||||||
public static class CreateFromUsage extends AbstractQuickFixTest {
|
public static class CreateFromUsage extends AbstractQuickFixTest {
|
||||||
public void testAllFilesPresentInCreateFromUsage() throws Exception {
|
public void testAllFilesPresentInCreateFromUsage() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/createFromUsage"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/createFromUsage"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/createFromUsage/classObject")
|
|
||||||
public static class ClassObject extends AbstractQuickFixTest {
|
|
||||||
public void testAllFilesPresentInClassObject() throws Exception {
|
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/createFromUsage/classObject"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("beforeCreateClassObject1.kt")
|
|
||||||
public void testCreateClassObject1() throws Exception {
|
|
||||||
doTest("idea/testData/quickfix/createFromUsage/classObject/beforeCreateClassObject1.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("beforeCreateClassObject2.kt")
|
|
||||||
public void testCreateClassObject2() throws Exception {
|
|
||||||
doTest("idea/testData/quickfix/createFromUsage/classObject/beforeCreateClassObject2.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/createFromUsage/component")
|
@TestMetadata("idea/testData/quickfix/createFromUsage/component")
|
||||||
public static class Component extends AbstractQuickFixTest {
|
public static class Component extends AbstractQuickFixTest {
|
||||||
public void testAllFilesPresentInComponent() throws Exception {
|
public void testAllFilesPresentInComponent() throws Exception {
|
||||||
@@ -620,7 +602,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
public static Test innerSuite() {
|
public static Test innerSuite() {
|
||||||
TestSuite suite = new TestSuite("CreateFromUsage");
|
TestSuite suite = new TestSuite("CreateFromUsage");
|
||||||
suite.addTestSuite(CreateFromUsage.class);
|
suite.addTestSuite(CreateFromUsage.class);
|
||||||
suite.addTestSuite(ClassObject.class);
|
|
||||||
suite.addTestSuite(Component.class);
|
suite.addTestSuite(Component.class);
|
||||||
suite.addTestSuite(Get.class);
|
suite.addTestSuite(Get.class);
|
||||||
suite.addTestSuite(HasNext.class);
|
suite.addTestSuite(HasNext.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user