mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
refactor: changed signature of ActionData helper functions
This commit is contained in:
@@ -77,6 +77,9 @@ interface ActionItem {
|
||||
/** Location marker for action items shown in editor activity's toolbar. */
|
||||
EDITOR_TOOLBAR("editor.activity.toolbar"),
|
||||
|
||||
/** Location marker for action items shown in UI Designer activity's toolbar. */
|
||||
UI_DESIGNER_TOOLBAR("editor.activity.toolbar"),
|
||||
|
||||
/** Location marker for action items shown in editor's text action menu. */
|
||||
EDITOR_TEXT_ACTIONS("editor.textActions"),
|
||||
|
||||
|
||||
@@ -24,16 +24,16 @@ import io.github.rosemoe.sora.widget.CodeEditor
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
|
||||
fun requireFile(data: ActionData): File {
|
||||
return data.get(File::class.java) ?: throw IllegalArgumentException("No file instance provided")
|
||||
fun ActionData.requireFile(): File {
|
||||
return get(File::class.java) ?: throw IllegalArgumentException("No file instance provided")
|
||||
}
|
||||
|
||||
fun requirePath(data: ActionData): Path {
|
||||
return requireFile(data).toPath()
|
||||
fun ActionData.requirePath(): Path {
|
||||
return requireFile().toPath()
|
||||
}
|
||||
|
||||
fun requireEditor(data: ActionData): CodeEditor {
|
||||
return data.get(CodeEditor::class.java)
|
||||
fun ActionData.requireEditor(): CodeEditor {
|
||||
return get(CodeEditor::class.java)
|
||||
?: throw IllegalArgumentException("An editor instance is required but none was provided")
|
||||
}
|
||||
|
||||
@@ -45,13 +45,12 @@ fun newDialogBuilder(data: ActionData): MaterialAlertDialogBuilder {
|
||||
/**
|
||||
* Checks if the given [ActionData] has instances of the given [types].
|
||||
*
|
||||
* @param data The data to check.
|
||||
* @param types The type of objects to look for.
|
||||
* @return `true` if the [data] has the given [types], `false` otherwise.
|
||||
* @return `true` if this [ActionData] has the given [types], `false` otherwise.
|
||||
*/
|
||||
fun hasRequiredData(data: ActionData, vararg types: Class<*>): Boolean {
|
||||
fun ActionData.hasRequiredData(vararg types: Class<*>): Boolean {
|
||||
for (type in types) {
|
||||
data.get(type) ?: return false
|
||||
get(type) ?: return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -49,7 +49,7 @@ abstract class BaseJavaCodeAction : EditorActionItem {
|
||||
override fun prepare(data: ActionData) {
|
||||
|
||||
if (
|
||||
!hasRequiredData(data, Context::class.java, JavaLanguageServer::class.java, File::class.java)
|
||||
!data.hasRequiredData(Context::class.java, JavaLanguageServer::class.java, File::class.java)
|
||||
) {
|
||||
markInvisible()
|
||||
return
|
||||
@@ -59,7 +59,7 @@ abstract class BaseJavaCodeAction : EditorActionItem {
|
||||
label = data[Context::class.java]!!.getString(titleTextRes)
|
||||
}
|
||||
|
||||
val file = requireFile(data)
|
||||
val file = data.requireFile()
|
||||
visible = DocumentUtils.isJavaFile(file.toPath())
|
||||
enabled = visible
|
||||
}
|
||||
@@ -67,10 +67,10 @@ abstract class BaseJavaCodeAction : EditorActionItem {
|
||||
fun performCodeAction(data: ActionData, result: Rewrite) {
|
||||
val server = ILanguageServerRegistry.getDefault().getServer(JavaLanguageServer.SERVER_ID)!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return)
|
||||
val client = server.client!!
|
||||
|
||||
val file = requireFile(data)
|
||||
val file = data.requireFile()
|
||||
|
||||
client.performCodeAction(file, result.asCodeActions(compiler, label))
|
||||
}
|
||||
|
||||
@@ -54,8 +54,7 @@ abstract class FieldBasedAction : BaseJavaCodeAction() {
|
||||
|
||||
if (
|
||||
!visible ||
|
||||
!hasRequiredData(
|
||||
data,
|
||||
!data.hasRequiredData(
|
||||
com.itsaky.androidide.models.Range::class.java,
|
||||
CodeEditor::class.java
|
||||
) ||
|
||||
@@ -71,7 +70,7 @@ abstract class FieldBasedAction : BaseJavaCodeAction() {
|
||||
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val range = data[com.itsaky.androidide.models.Range::class.java]!!
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
val module = ProjectManager.findModuleForFile(file) ?: return Any()
|
||||
|
||||
return JavaCompilerProvider.get(module).compile(file).get { task ->
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class CommentAction : BaseJavaCodeAction() {
|
||||
override var requiresUIThread: Boolean = true
|
||||
|
||||
override fun execAction(data: ActionData): Boolean {
|
||||
val editor = requireEditor(data)
|
||||
val editor = data.requireEditor()
|
||||
val text = editor.text
|
||||
val cursor = editor.cursor
|
||||
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ class FindReferencesAction : BaseJavaCodeAction() {
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
if (!visible || !hasRequiredData(data, CodeEditor::class.java, File::class.java)) {
|
||||
if (!visible || !data.hasRequiredData( CodeEditor::class.java, File::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class GoToDefinitionAction : BaseJavaCodeAction() {
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
if (!visible || !hasRequiredData(data, CodeEditor::class.java, File::class.java)) {
|
||||
if (!visible || !data.hasRequiredData( CodeEditor::class.java, File::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ class OrganizeImportsAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasRequiredData(data, CodeEditor::class.java)) {
|
||||
if (!data.hasRequiredData(CodeEditor::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class OrganizeImportsAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val watch = com.itsaky.androidide.utils.StopWatch("Organize imports")
|
||||
return try {
|
||||
val editor = requireEditor(data)
|
||||
val editor = data.requireEditor()
|
||||
val content = editor.text
|
||||
val server = data[JavaLanguageServer::class.java]
|
||||
val settings = server!!.settings as JavaServerSettings
|
||||
@@ -54,7 +54,7 @@ class OrganizeImportsAction : BaseJavaCodeAction() {
|
||||
super.postExec(data, result)
|
||||
if (result is String) {
|
||||
if (result.isNotEmpty()) {
|
||||
val editor = requireEditor(data)
|
||||
val editor = data.requireEditor()
|
||||
editor.setText(result)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ class RemoveUnusedImportsAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasRequiredData(data, CodeEditor::class.java)) {
|
||||
if (!data.hasRequiredData(CodeEditor::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class RemoveUnusedImportsAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val watch = com.itsaky.androidide.utils.StopWatch("Remove unused imports")
|
||||
return try {
|
||||
val editor = requireEditor(data)
|
||||
val editor = data.requireEditor()
|
||||
val content = editor.text
|
||||
val output = RemoveUnusedImports.removeUnusedImports(content.toString())
|
||||
watch.log()
|
||||
@@ -49,7 +49,7 @@ class RemoveUnusedImportsAction : BaseJavaCodeAction() {
|
||||
|
||||
override fun postExec(data: ActionData, result: Any) {
|
||||
if (result is String && result.isNotEmpty()) {
|
||||
val editor = requireEditor(data)
|
||||
val editor = data.requireEditor()
|
||||
editor.setText(result)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class UncommentAction : BaseJavaCodeAction() {
|
||||
override var requiresUIThread: Boolean = true
|
||||
|
||||
override fun execAction(data: ActionData): Boolean {
|
||||
val editor = requireEditor(data)
|
||||
val editor = data.requireEditor()
|
||||
val text = editor.text
|
||||
val cursor = editor.cursor
|
||||
|
||||
|
||||
+6
-6
@@ -27,7 +27,6 @@ import com.itsaky.androidide.javac.services.util.JavaDiagnosticUtils
|
||||
import com.itsaky.androidide.lsp.api.ILanguageServerRegistry
|
||||
import com.itsaky.androidide.lsp.java.JavaCompilerProvider
|
||||
import com.itsaky.androidide.lsp.java.JavaLanguageServer
|
||||
import com.itsaky.androidide.resources.R
|
||||
import com.itsaky.androidide.lsp.java.actions.BaseJavaCodeAction
|
||||
import com.itsaky.androidide.lsp.java.models.DiagnosticCode
|
||||
import com.itsaky.androidide.lsp.java.rewrite.AddImport
|
||||
@@ -35,6 +34,7 @@ import com.itsaky.androidide.lsp.java.rewrite.Rewrite
|
||||
import com.itsaky.androidide.lsp.models.CodeActionItem
|
||||
import com.itsaky.androidide.lsp.models.DiagnosticItem
|
||||
import com.itsaky.androidide.projects.ProjectManager
|
||||
import com.itsaky.androidide.resources.R
|
||||
import com.itsaky.androidide.utils.ILogger
|
||||
import javax.tools.Diagnostic
|
||||
import javax.tools.JavaFileObject
|
||||
@@ -52,7 +52,7 @@ class AddImportAction : BaseJavaCodeAction() {
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
if (!visible || !hasRequiredData(data, DiagnosticItem::class.java)) {
|
||||
if (!visible || !data.hasRequiredData(DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class AddImportAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
val file = requireFile(data)
|
||||
val file = data.requireFile()
|
||||
val module =
|
||||
ProjectManager.findModuleForFile(file)
|
||||
?: run {
|
||||
@@ -108,7 +108,7 @@ class AddImportAction : BaseJavaCodeAction() {
|
||||
JavaDiagnosticUtils.asUnwrapper(
|
||||
data.get(DiagnosticItem::class.java)!!.extra as Diagnostic<out JavaFileObject>
|
||||
)!!
|
||||
val file = requireFile(data)
|
||||
val file = data.requireFile()
|
||||
val module =
|
||||
ProjectManager.findModuleForFile(file)
|
||||
?: run {
|
||||
@@ -132,7 +132,7 @@ class AddImportAction : BaseJavaCodeAction() {
|
||||
}
|
||||
|
||||
titles.add(klass)
|
||||
rewrites.add(AddImport(requirePath(data), klass))
|
||||
rewrites.add(AddImport(data.requirePath(), klass))
|
||||
}
|
||||
|
||||
if (rewrites.isEmpty()) {
|
||||
@@ -149,7 +149,7 @@ class AddImportAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
val file = requireFile(data)
|
||||
val file = data.requireFile()
|
||||
val module =
|
||||
ProjectManager.findModuleForFile(file)
|
||||
?: run {
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ class AddThrowsAction : BaseJavaCodeAction() {
|
||||
|
||||
if (
|
||||
!visible ||
|
||||
!hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
!data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
) {
|
||||
markInvisible()
|
||||
return
|
||||
@@ -60,8 +60,8 @@ class AddThrowsAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
return compiler.compile(file).get { task ->
|
||||
val needsThrow = CodeActionUtils.findMethod(task, diagnostic.range)
|
||||
val exceptionName = CodeActionUtils.extractExceptionName(diagnostic.message)
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ class CreateMissingMethodAction : BaseJavaCodeAction() {
|
||||
|
||||
if (
|
||||
!visible ||
|
||||
!hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
!data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
) {
|
||||
markInvisible()
|
||||
return
|
||||
@@ -60,8 +60,8 @@ class CreateMissingMethodAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
return compiler.compile(file).get {
|
||||
CreateMissingMethod(file, findPosition(it, diagnostic.range.start))
|
||||
}
|
||||
|
||||
+3
-3
@@ -48,7 +48,7 @@ class FieldToBlockAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasRequiredData(data, DiagnosticItem::class.java)) {
|
||||
if (!data.hasRequiredData( DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -62,9 +62,9 @@ class FieldToBlockAction : BaseJavaCodeAction() {
|
||||
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val diagnostic = data[DiagnosticItem::class.java]!!
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
|
||||
return compiler.compile(file).get {
|
||||
ConvertFieldToBlock(file, findPosition(it, diagnostic.range.start))
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class ImplementAbstractMethodsAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
if (!data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
|
||||
+3
-3
@@ -42,7 +42,7 @@ class RemoveClassAction : BaseJavaCodeAction() {
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
if (!visible || !hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
if (!visible || !data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -57,8 +57,8 @@ class RemoveClassAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
|
||||
return compiler.compile(file).get {
|
||||
RemoveClass(file, findPosition(it, diagnostic.range.start))
|
||||
|
||||
+3
-3
@@ -42,7 +42,7 @@ class RemoveMethodAction : BaseJavaCodeAction() {
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
if (!visible || !hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
if (!visible || !data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -57,8 +57,8 @@ class RemoveMethodAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
|
||||
return compiler.compile(file).get {
|
||||
val unusedMethod = findMethod(it, diagnostic.range)
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ class RemoveUnusedThrowsAction : BaseJavaCodeAction() {
|
||||
|
||||
if (
|
||||
!visible ||
|
||||
!hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
!data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
) {
|
||||
markInvisible()
|
||||
return
|
||||
@@ -60,8 +60,8 @@ class RemoveUnusedThrowsAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val d = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
return compiler.compile(file).get { task ->
|
||||
val notThrown = CodeActionUtils.extractNotThrownExceptionName(d.message)
|
||||
val methodWithExtraThrow = CodeActionUtils.findMethod(task, d.range)
|
||||
|
||||
+3
-3
@@ -42,7 +42,7 @@ class SuppressUncheckedWarningAction : BaseJavaCodeAction() {
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
if (!visible || !hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
if (!visible || !data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -57,8 +57,8 @@ class SuppressUncheckedWarningAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
return compiler.compile(file).get { task ->
|
||||
val warnedMethod = CodeActionUtils.findMethod(task, diagnostic.range)
|
||||
return@get AddSuppressWarningAnnotation(
|
||||
|
||||
+3
-3
@@ -47,7 +47,7 @@ class VariableToStatementAction : BaseJavaCodeAction() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
if (!data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
}
|
||||
@@ -65,8 +65,8 @@ class VariableToStatementAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val path = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val path = data.requirePath()
|
||||
|
||||
return compiler.compile(path).get {
|
||||
ConvertVariableToStatement(path, findPosition(it, diagnostic.range.start))
|
||||
|
||||
+2
-2
@@ -72,9 +72,9 @@ class GenerateConstructorAction : FieldBasedAction() {
|
||||
|
||||
private fun generateConstructor(data: ActionData, selected: MutableSet<String>) {
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return)
|
||||
val range = data[com.itsaky.androidide.models.Range::class.java]!!
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
|
||||
compiler.compile(file).run { task ->
|
||||
val triple = findFields(task, file, range)
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ class GenerateMissingConstructorAction : BaseJavaCodeAction() {
|
||||
|
||||
if (
|
||||
!visible ||
|
||||
!hasRequiredData(data, com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
!data.hasRequiredData( com.itsaky.androidide.lsp.models.DiagnosticItem::class.java)
|
||||
) {
|
||||
markInvisible()
|
||||
return
|
||||
@@ -59,8 +59,8 @@ class GenerateMissingConstructorAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val diagnostic = data[com.itsaky.androidide.lsp.models.DiagnosticItem::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
return compiler.compile(file).get { task ->
|
||||
val needsConstructor =
|
||||
CodeActionUtils.findClassNeedingConstructor(task, diagnostic.range) ?: return@get false
|
||||
|
||||
+3
-3
@@ -82,9 +82,9 @@ class GenerateSettersAndGettersAction : FieldBasedAction() {
|
||||
|
||||
private fun generateForFields(data: ActionData, names: MutableSet<String>) {
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return)
|
||||
val range = data[com.itsaky.androidide.models.Range::class.java]!!
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
|
||||
compiler.compile(file).run { task ->
|
||||
val triple = findFields(task, file, range)
|
||||
@@ -106,7 +106,7 @@ class GenerateSettersAndGettersAction : FieldBasedAction() {
|
||||
type: ClassTree,
|
||||
paths: List<TreePath>,
|
||||
) {
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
val editor = data[CodeEditor::class.java]!!
|
||||
val trees = Trees.instance(task.task)
|
||||
val insert = EditHelper.insertAtEndOfClass(task.task, task.root(file), type)
|
||||
|
||||
+3
-3
@@ -80,9 +80,9 @@ class GenerateToStringMethodAction : FieldBasedAction() {
|
||||
|
||||
private fun generateToString(data: ActionData, selected: MutableSet<String>) {
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return)
|
||||
val range = data[com.itsaky.androidide.models.Range::class.java]!!
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
|
||||
compiler.compile(file).run { task ->
|
||||
val triple = findFields(task, file, range)
|
||||
@@ -112,7 +112,7 @@ class GenerateToStringMethodAction : FieldBasedAction() {
|
||||
return
|
||||
}
|
||||
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
val editor = data[CodeEditor::class.java]!!
|
||||
val trees = JavacTrees.instance(task.task)
|
||||
val indent = EditHelper.indent(task.task, task.root(), type) + 4
|
||||
|
||||
+7
-8
@@ -71,8 +71,7 @@ class OverrideSuperclassMethodsAction : BaseJavaCodeAction() {
|
||||
|
||||
if (
|
||||
!visible ||
|
||||
!hasRequiredData(
|
||||
data,
|
||||
!data.hasRequiredData(
|
||||
com.itsaky.androidide.models.Range::class.java,
|
||||
CodeEditor::class.java
|
||||
)
|
||||
@@ -88,8 +87,8 @@ class OverrideSuperclassMethodsAction : BaseJavaCodeAction() {
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val range = data[com.itsaky.androidide.models.Range::class.java]!!
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return Any())
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return Any())
|
||||
val file = data.requirePath()
|
||||
|
||||
return compiler.compile(file).get { task ->
|
||||
// 1-based line and column index
|
||||
@@ -201,8 +200,8 @@ class OverrideSuperclassMethodsAction : BaseJavaCodeAction() {
|
||||
|
||||
private fun overrideMethods(data: ActionData, checkedMethods: MutableList<MethodPtr>) {
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return)
|
||||
val file = requirePath(data)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return)
|
||||
val file = data.requirePath()
|
||||
|
||||
compiler.compile(file).run { task ->
|
||||
val types = task.task.types
|
||||
@@ -267,9 +266,9 @@ class OverrideSuperclassMethodsAction : BaseJavaCodeAction() {
|
||||
position: com.itsaky.androidide.models.Position,
|
||||
) {
|
||||
val compiler =
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(requireFile(data)) ?: return)
|
||||
JavaCompilerProvider.get(ProjectManager.findModuleForFile(data.requireFile()) ?: return)
|
||||
val editor = data[CodeEditor::class.java]!!
|
||||
val file = requirePath(data)
|
||||
val file = data.requirePath()
|
||||
val text = editor.text
|
||||
|
||||
text.beginBatchEdit()
|
||||
|
||||
@@ -44,6 +44,7 @@ dependencies {
|
||||
implementation common.utilcode
|
||||
implementation google.material
|
||||
|
||||
implementation project(path: ':actions')
|
||||
implementation project(path: ':common')
|
||||
implementation project(path: ':logger')
|
||||
implementation project(path: ':lookup')
|
||||
|
||||
Reference in New Issue
Block a user