mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
change component type fix also handles inner classes correctly (IDEA-46172)
This commit is contained in:
+11
-7
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String, Pair<PsiType, TextRange>> fieldNameToTypeMap = getCachedData(file).myFieldNameToTypeMap;
|
||||
final Pair<PsiType, TextRange> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user