Skip to content

Commit 1471968

Browse files
committed
fix crash : rename class
1 parent ed88a9f commit 1471968

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main/java/com/tang/intellij/lua/comment/psi/LuaDocPsiImplUtil.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun getName(identifierOwner: PsiNameIdentifierOwner): String? {
5454
fun setName(identifierOwner: PsiNameIdentifierOwner, newName: String): PsiElement {
5555
val oldId = identifierOwner.nameIdentifier
5656
if (oldId != null) {
57-
val newId = LuaElementFactory.createIdentifier(identifierOwner.project, newName)
57+
val newId = LuaElementFactory.createDocIdentifier(identifierOwner.project, newName)
5858
oldId.replace(newId)
5959
return newId
6060
}
@@ -160,13 +160,7 @@ fun getPresentation(classDef: LuaDocClassDef): ItemPresentation {
160160

161161
fun getType(classDef: LuaDocClassDef): ITyClass {
162162
val stub = classDef.stub
163-
val luaType: ITyClass
164-
if (stub != null) {
165-
luaType = stub.classType
166-
} else {
167-
luaType = TyPsiDocClass(classDef)
168-
}
169-
return luaType
163+
return stub?.classType ?: TyPsiDocClass(classDef)
170164
}
171165

172166
/**

src/main/java/com/tang/intellij/lua/psi/LuaElementFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.intellij.psi.PsiElement;
2121
import com.intellij.psi.PsiFileFactory;
2222
import com.intellij.psi.util.PsiTreeUtil;
23+
import com.tang.intellij.lua.comment.psi.LuaDocFieldDef;
2324
import com.tang.intellij.lua.lang.LuaLanguage;
2425
import org.jetbrains.annotations.NotNull;
2526

@@ -65,4 +66,11 @@ public static PsiElement createWith(Project project, String code) {
6566
LuaFile file = createFile(project, code);
6667
return file.getFirstChild();
6768
}
69+
70+
public static PsiElement createDocIdentifier(Project project, String name) {
71+
PsiElement element = createWith(project, "---@field " + name + " string");
72+
LuaDocFieldDef fieldDef = PsiTreeUtil.findChildOfType(element, LuaDocFieldDef.class);
73+
assert fieldDef != null;
74+
return fieldDef.getId();
75+
}
6876
}

0 commit comments

Comments
 (0)