From 657b346513c84d7591fe5a7c0b6b59eb72aac164 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 10 Nov 2014 17:47:48 +0100 Subject: [PATCH] type migration: normalize declaration so it's possible to migrate separate parts (IDEA-132521) --- .../typeMigration/TypeMigrationProcessor.java | 34 ++++--------------- .../typeMigration/t135/after/Test.items | 5 --- .../typeMigration/t135/after/test.java | 5 +-- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationProcessor.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationProcessor.java index 2998ec6b0f07..fbf9bb509cd8 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationProcessor.java @@ -15,7 +15,6 @@ */ package com.intellij.refactoring.typeMigration; -import com.intellij.lang.ASTNode; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -24,8 +23,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.psi.*; -import com.intellij.psi.impl.PsiImplUtil; -import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.util.PsiUtilCore; import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.refactoring.typeMigration.ui.FailedConversionsDialog; @@ -51,7 +48,7 @@ public class TypeMigrationProcessor extends BaseRefactoringProcessor { private TypeMigrationLabeler myLabeler; public TypeMigrationProcessor(final Project project, final PsiElement root, final TypeMigrationRules rules) { - this(project, getRoots(root), rules); + this(project, new PsiElement[]{root}, rules); } public TypeMigrationProcessor(final Project project, final PsiElement[] roots, final TypeMigrationRules rules) { @@ -60,30 +57,6 @@ public class TypeMigrationProcessor extends BaseRefactoringProcessor { myRules = rules; } - private static PsiElement[] getRoots(PsiElement root) { - if (root instanceof PsiVariable) { - final PsiElement parent = root.getParent(); - if (parent instanceof PsiDeclarationStatement) { - return ((PsiDeclarationStatement)parent).getDeclaredElements(); - } - if (root instanceof PsiField) { - final List fields = new ArrayList(); - PsiField field = (PsiField)root; - fields.add(field); - while (true) { - ASTNode comma = PsiImplUtil.skipWhitespaceAndComments(field.getNode().getTreeNext()); - if (comma == null || comma.getElementType() != JavaTokenType.COMMA) break; - ASTNode nextField = PsiImplUtil.skipWhitespaceAndComments(comma.getTreeNext()); - if (nextField == null || nextField.getElementType() != JavaElementType.FIELD) break; - field = (PsiField)nextField.getPsi(); - fields.add(field); - } - return fields.toArray(new PsiElement[fields.size()]); - } - } - return new PsiElement[]{root}; - } - public static void runHighlightingTypeMigration(final Project project, final Editor editor, final TypeMigrationRules rules, @@ -198,6 +171,11 @@ public class TypeMigrationProcessor extends BaseRefactoringProcessor { @Override public void performRefactoring(UsageInfo[] usages) { + for (PsiElement element : myRoot) { + if (element instanceof PsiVariable) { + ((PsiVariable)element).normalizeDeclaration(); + } + } change(myLabeler, usages); } diff --git a/java/typeMigration/testData/refactoring/typeMigration/t135/after/Test.items b/java/typeMigration/testData/refactoring/typeMigration/t135/after/Test.items index 4e20b05def59..a08bb312435a 100644 --- a/java/typeMigration/testData/refactoring/typeMigration/t135/after/Test.items +++ b/java/typeMigration/testData/refactoring/typeMigration/t135/after/Test.items @@ -1,13 +1,8 @@ Types: -PsiField:bar : int PsiField:foo : int -PsiParameter:bar : int PsiParameter:foo : int -PsiReferenceExpression:bar : int -PsiReferenceExpression:bar : int PsiReferenceExpression:foo : int PsiReferenceExpression:foo : int -PsiReferenceExpression:this.bar : int PsiReferenceExpression:this.foo : int Conversions: diff --git a/java/typeMigration/testData/refactoring/typeMigration/t135/after/test.java b/java/typeMigration/testData/refactoring/typeMigration/t135/after/test.java index c992fd8569bf..dbd11376c10b 100644 --- a/java/typeMigration/testData/refactoring/typeMigration/t135/after/test.java +++ b/java/typeMigration/testData/refactoring/typeMigration/t135/after/test.java @@ -1,5 +1,6 @@ class Test { - private int foo, bar; + private int foo; + private long bar; public long getFoo() { return foo; @@ -13,7 +14,7 @@ class Test { return bar; } - public void setBar(int bar) { + public void setBar(long bar) { this.bar = bar; } } \ No newline at end of file