Changed RemovePartsFromPropertyFix so it uses SpecifyTypeExplicitlyAction.addTypeAnnotation() instead of AddReturnTypeFix.addPropertyType().

This commit is contained in:
Evgeny Gerashchenko
2012-05-03 16:04:57 +04:00
parent c80ac15b8a
commit 22010a5ae0
9 changed files with 25 additions and 17 deletions
@@ -142,15 +142,24 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
PsiElement anchor = property.getNameIdentifier();
if (anchor == null) return;
anchor = anchor.getNextSibling();
if (anchor == null || !(anchor instanceof PsiWhiteSpace)) return;
if (anchor != null) {
if (!(anchor instanceof PsiWhiteSpace)) {
return;
}
}
JetTypeReference typeReference = JetPsiFactory.createType(project, DescriptorRenderer.TEXT.renderType(exprType));
ASTNode colon = JetPsiFactory.createColonNode(project);
ASTNode anchorNode = anchor.getNode().getTreeNext();
ASTNode anchorNode = anchor == null ? null : anchor.getNode().getTreeNext();
if (anchor == null) {
property.getNode().addChild(JetPsiFactory.createWhiteSpace(project).getNode(), anchorNode);
}
property.getNode().addChild(colon, anchorNode);
property.getNode().addChild(JetPsiFactory.createWhiteSpace(project).getNode(), anchorNode);
property.getNode().addChild(typeReference.getNode(), anchorNode);
property.getNode().addChild(JetPsiFactory.createWhiteSpace(project).getNode(), anchorNode);
anchor.delete();
if (anchor != null) {
anchor.delete();
}
ReferenceToClassesShortening.compactReferenceToClasses(Collections.singletonList(property));
}
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction;
/**
* @author svtk
@@ -105,7 +106,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
newElement.deleteChildInternal(setter.getNode());
}
JetExpression initializer = newElement.getInitializer();
boolean needImport = false;
JetType typeToAdd = null;
if (removeInitializer && initializer != null) {
PsiElement nameIdentifier = newElement.getNameIdentifier();
assert nameIdentifier != null;
@@ -114,14 +115,13 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
newElement.deleteChildRange(nextSibling, initializer);
if (newElement.getPropertyTypeRef() == null && type != null) {
newElement = AddReturnTypeFix.addPropertyType(project, newElement, type);
needImport = true;
typeToAdd = type;
}
}
if (needImport) {
ImportInsertHelper.addImportDirectivesIfNeeded(type, (JetFile)file);
element = (JetProperty) element.replace(newElement);
if (typeToAdd != null) {
SpecifyTypeExplicitlyAction.addTypeAnnotation(project, element, typeToAdd);
}
element.replace(newElement);
}
public static JetIntentionActionFactory createFactory() {
@@ -1,4 +1,4 @@
// "Remove initializer from property" "true"
abstract class A {
abstract var i : Int<caret>
abstract var i<caret> : Int
}
@@ -1,4 +1,4 @@
// "Remove initializer from property" "true"
abstract class A {
abstract var i : Int<caret>
abstract var i<caret> : Int
}
@@ -1,5 +1,4 @@
// "Remove getter and initializer from property" "true"
abstract class B {
abstract val i : <caret>Int
abstract val i<caret> : Int
}
@@ -9,7 +9,7 @@ import java.util.List
class M {
trait A {
val l : <caret>List<Int>?
val l<caret> : List<Int>?
}
}
}
@@ -3,6 +3,6 @@ package a
class M {
trait A {
abstract val e : <caret>Exception
abstract val e<caret> : Exception
}
}
@@ -3,6 +3,6 @@ package a
class M {
trait A {
abstract val i : <caret>Int
abstract val i<caret> : Int
}
}
@@ -6,6 +6,6 @@ import java.util.List
class M {
trait A {
abstract val l : <caret>List<Int>?
abstract val l<caret> : List<Int>?
}
}