diff --git a/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/actions/generators/OverrideSuperclassMethodsAction.kt b/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/actions/generators/OverrideSuperclassMethodsAction.kt index f4b8657c59..cd844b8578 100644 --- a/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/actions/generators/OverrideSuperclassMethodsAction.kt +++ b/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/actions/generators/OverrideSuperclassMethodsAction.kt @@ -42,6 +42,7 @@ import com.itsaky.androidide.projects.IProjectManager import com.itsaky.androidide.resources.R import com.itsaky.androidide.utils.flashError import io.github.rosemoe.sora.widget.CodeEditor +import jdkx.lang.model.SourceVersion import jdkx.lang.model.element.ElementKind import jdkx.lang.model.element.ExecutableElement import jdkx.lang.model.element.Modifier @@ -249,7 +250,7 @@ class OverrideSuperclassMethodsAction : BaseJavaCodeAction() { sb.append("\n") newImports.removeIf { - it.startsWith("java.lang.") || it.startsWith(filePackage) || fileImports.contains(it) + it.startsWith("java.lang.") || it.startsWith(filePackage) || SourceVersion.isKeyword(it) || fileImports.contains(it) } imports.addAll(newImports) diff --git a/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/utils/JavaParserUtils.kt b/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/utils/JavaParserUtils.kt index 7f0c5c83fb..454761a661 100644 --- a/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/utils/JavaParserUtils.kt +++ b/java/lsp/src/main/java/com/itsaky/androidide/lsp/java/utils/JavaParserUtils.kt @@ -194,7 +194,11 @@ object JavaParserUtils { methodDeclaration: MethodDeclaration, method: ExecutableElement, ) { - methodDeclaration.addMarkerAnnotation(Override::class.java) + val overrideAnnotation = methodDeclaration.getAnnotationByClass(Override::class.java) + if (!overrideAnnotation.isPresent) { + methodDeclaration.addMarkerAnnotation(Override::class.java) + } + val recentlyNonNull = methodDeclaration.getAnnotationByName("RecentlyNonNull") if (recentlyNonNull.isPresent) { methodDeclaration.remove(recentlyNonNull.get())