From 204d7cee2d5c77d6c42ee12a9e461b4b583c1013 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Sat, 13 Nov 2010 20:47:29 +0300 Subject: [PATCH] change component type fix also handles inner classes correctly (IDEA-46172) --- .../binding/ChangeFormComponentTypeFix.java | 18 +++++++++++------- .../binding/FormReferenceProvider.java | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ChangeFormComponentTypeFix.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ChangeFormComponentTypeFix.java index 52b02added3a..3ddec299894f 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ChangeFormComponentTypeFix.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/ChangeFormComponentTypeFix.java @@ -21,10 +21,8 @@ import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.ReadonlyStatusHandler; -import com.intellij.psi.PsiClassType; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiPlainTextFile; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; +import com.intellij.psi.util.ClassUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -35,16 +33,22 @@ import org.jetbrains.annotations.NotNull; public class ChangeFormComponentTypeFix implements IntentionAction { private final PsiPlainTextFile myFormFile; private final String myFieldName; - private final PsiType myComponentTypeToSet; + private final String myComponentTypeToSet; public ChangeFormComponentTypeFix(PsiPlainTextFile formFile, String fieldName, PsiType componentTypeToSet) { myFormFile = formFile; myFieldName = fieldName; if (componentTypeToSet instanceof PsiClassType) { - myComponentTypeToSet = ((PsiClassType) componentTypeToSet).rawType(); + PsiClass psiClass = ((PsiClassType)componentTypeToSet).resolve(); + if (psiClass != null) { + myComponentTypeToSet = ClassUtil.getJVMClassName(psiClass); + } + else { + myComponentTypeToSet = ((PsiClassType) componentTypeToSet).rawType().getCanonicalText(); + } } else { - myComponentTypeToSet = componentTypeToSet; + myComponentTypeToSet = componentTypeToSet.getCanonicalText(); } } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferenceProvider.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferenceProvider.java index 118ac4da429e..3454ece9d563 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferenceProvider.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferenceProvider.java @@ -102,13 +102,13 @@ public class FormReferenceProvider extends PsiReferenceProvider { return typeRangePair != null? typeRangePair.getFirst() : null; } - public static void setGUIComponentType(PsiPlainTextFile file, String fieldName, PsiType componentTypeToSet) { + public static void setGUIComponentType(PsiPlainTextFile file, String fieldName, String typeText) { final Map> fieldNameToTypeMap = getCachedData(file).myFieldNameToTypeMap; final Pair typeRangePair = fieldNameToTypeMap.get(fieldName); if (typeRangePair != null) { final TextRange range = typeRangePair.getSecond(); if (range != null) { - PsiDocumentManager.getInstance(file.getProject()).getDocument(file).replaceString(range.getStartOffset(), range.getEndOffset(), componentTypeToSet.getCanonicalText()); + PsiDocumentManager.getInstance(file.getProject()).getDocument(file).replaceString(range.getStartOffset(), range.getEndOffset(), typeText); } } }