Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

fix(java/lsp): fix bugs when overriding methods #1917

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down