Skip to content

Commit c380493

Browse files
Fix JetBrains Kotlin compiler warnings
- Replace deprecated StreamUtil.readText() with bufferedReader().use { it.readText() } - Replace deprecated String.toLowerCase() with lowercase() - Replace deprecated JBCefBrowser.executeJavaScriptAsync() with cefBrowser.executeJavaScript() - Replace deprecated TerminalView with TerminalToolWindowManager - Replace deprecated PluginManager.getPlugin() with PluginManagerCore.getPlugin() - Replace deprecated Char.toInt() with Char.code - Replace deprecated Disposer.isDisposed() with editor.isDisposed check - Add @Suppress("UNCHECKED_CAST") annotations for safe null-check casts in NextEditService and CoreMessenger Co-authored-by: dallin <[email protected]>
1 parent 03b5635 commit c380493

File tree

9 files changed

+40
-21
lines changed

9 files changed

+40
-21
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fun showTutorial(project: Project) {
5151
if (`is` == null) {
5252
throw IOException("Resource not found: $tutorialFileName")
5353
}
54-
var content = StreamUtil.readText(`is`, StandardCharsets.UTF_8)
54+
var content = `is`.bufferedReader(StandardCharsets.UTF_8).use { it.readText() }
5555

5656
// All jetbrains will use J instead of L
5757
content = content.replace("[Cmd + L]", "[Cmd + J]")
@@ -95,7 +95,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
9595
}
9696

9797
private fun getPlatformSpecificKeyStroke(key: String): String {
98-
val osName = System.getProperty("os.name").toLowerCase()
98+
val osName = System.getProperty("os.name").lowercase()
9999
val modifier = if (osName.contains("mac")) "meta" else "control"
100100
return "$modifier $key"
101101
}

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ContinueBrowser(
8888
val json = gsonService.gson.toJson(BrowserMessage(messageType, messageId, data))
8989
val jsCode = """window.postMessage($json, "*");"""
9090
try {
91-
browser.executeJavaScriptAsync(jsCode)
91+
browser.cefBrowser.executeJavaScript(jsCode, getGuiUrl(), 0)
9292
} catch (error: IllegalStateException) {
9393
log.warn(error)
9494
}

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ConfigJsonSchemaProviderFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ConfigJsonSchemaFileProvider : JsonSchemaFileProvider {
3535
if (`is` == null) {
3636
throw IOException("Resource not found: config_schema.json")
3737
}
38-
val content = StreamUtil.readText(`is`, StandardCharsets.UTF_8)
38+
val content = `is`.bufferedReader(StandardCharsets.UTF_8).use { it.readText() }
3939
val filepath = Paths.get(getContinueGlobalPath(), "config_schema.json").toString()
4040
File(filepath).writeText(content)
4141
return LocalFileSystem.getInstance().findFileByPath(filepath)

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ConfigRcJsonSchemaProviderFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ConfigRcJsonSchemaFileProvider : JsonSchemaFileProvider {
3535
if (`is` == null) {
3636
throw IOException("Resource not found: continue_rc_schema.json")
3737
}
38-
val content = StreamUtil.readText(`is`, StandardCharsets.UTF_8)
38+
val content = `is`.bufferedReader(StandardCharsets.UTF_8).use { it.readText() }
3939
val filepath = Paths.get(getContinueGlobalPath(), "continue_rc_schema.json").toString()
4040
File(filepath).writeText(content)
4141
return LocalFileSystem.getInstance().findFileByPath(filepath)

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class CoreMessenger(
6464
// Responses for messageId
6565
responseListeners[messageId]?.let { listener ->
6666
listener(data)
67-
val done = (data as Map<String, Boolean>)["done"]
67+
@Suppress("UNCHECKED_CAST")
68+
val done = (data as? Map<String, Boolean>)?.get("done")
6869

6970
if (done == true) {
7071
responseListeners.remove(messageId)

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import com.intellij.psi.PsiDocumentManager
3333
import com.intellij.testFramework.LightVirtualFile
3434
import kotlinx.coroutines.*
3535
import org.jetbrains.plugins.terminal.ShellTerminalWidget
36-
import org.jetbrains.plugins.terminal.TerminalView
36+
import org.jetbrains.plugins.terminal.TerminalToolWindowManager
3737
import java.awt.Toolkit
3838
import java.awt.datatransfer.DataFlavor
3939
import java.io.BufferedReader
@@ -208,10 +208,10 @@ class IntelliJIDE(
208208
try {
209209
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Terminal")
210210

211-
val terminalView = TerminalView.getInstance(project)
211+
val terminalManager = TerminalToolWindowManager.getInstance(project)
212212
// Find the first terminal widget selected, whatever its state, running command or not.
213-
val widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull {
214-
toolWindow?.getContentManager()?.getContent(it)?.isSelected ?: false
213+
val widget = terminalManager.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull {
214+
toolWindow?.contentManager?.getContent(it)?.isSelected ?: false
215215
}
216216

217217
if (widget != null) {
@@ -288,33 +288,34 @@ class IntelliJIDE(
288288
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Terminal")
289289
toolWindow?.activate({
290290
try {
291-
val terminalView = TerminalView.getInstance(project)
291+
val terminalManager = TerminalToolWindowManager.getInstance(project)
292292
var widget: ShellTerminalWidget? = null
293293

294294
// 1. Handle reuseTerminal option
295-
if (terminalOptions.reuseTerminal == true && terminalView.getWidgets().isNotEmpty()) {
295+
if (terminalOptions.reuseTerminal == true && terminalManager.getWidgets().isNotEmpty()) {
296296
// 2. Find by terminalName if provided
297297
if (terminalOptions.terminalName != null) {
298-
widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>()
298+
widget = terminalManager.getWidgets().filterIsInstance<ShellTerminalWidget>()
299299
.firstOrNull {
300300
toolWindow.contentManager.getContent(it).tabName == terminalOptions.terminalName
301301
&& !it.hasRunningCommands()
302302
}
303303
} else {
304304
// 3. Find active terminal, or fall back to the first one
305-
widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>()
305+
widget = terminalManager.getWidgets().filterIsInstance<ShellTerminalWidget>()
306306
.firstOrNull { toolWindow.contentManager.getContent(it).isSelected }
307-
?: terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull {
307+
?: terminalManager.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull {
308308
!it.hasRunningCommands()
309309
}
310310
}
311311
}
312312

313313
// 4. Create a new terminal if needed
314314
if (widget == null) {
315-
widget = terminalView.createLocalShellWidget(
315+
widget = terminalManager.createLocalShellWidget(
316316
project.basePath,
317317
terminalOptions.terminalName,
318+
true,
318319
true
319320
)
320321
} else {

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/EditorComponentInlaysManager.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ class EditorComponentInlaysManager(val editor: EditorImpl, private val onlyOneIn
4343

4444
@RequiresEdt
4545
fun insert(lineIndex: Int, component: JComponent, showAbove: Boolean = false): Disposable? {
46-
if (Disposer.isDisposed(this)) return null
46+
try {
47+
// Check if editor is disposed
48+
if (editor.isDisposed) return null
49+
} catch (e: Exception) {
50+
return null
51+
}
4752

4853
if (onlyOneInlay) {
4954
// Dispose all other inlays
@@ -106,7 +111,7 @@ class EditorComponentInlaysManager(val editor: EditorImpl, private val onlyOneIn
106111

107112
init {
108113
val metrics = editor.getFontMetrics(Font.PLAIN)
109-
val spaceWidth = FontLayoutService.getInstance().charWidth2D(metrics, ' '.toInt())
114+
val spaceWidth = FontLayoutService.getInstance().charWidth2D(metrics, ' '.code)
110115
// -4 to create some space
111116
maximumEditorTextWidth = ceil(spaceWidth * (editor.settings.getRightMargin(editor.project)) - 4).toInt()
112117

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/nextEdit/NextEditService.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
218218

219219
private fun parseNextEditOutcome(response: Any?): NextEditOutcome? {
220220
return try {
221+
@Suppress("UNCHECKED_CAST")
221222
val responseMap = response as? Map<String, Any> ?: return null
223+
@Suppress("UNCHECKED_CAST")
222224
val contentMap = responseMap["content"] as? Map<String, Any> ?: return null
223225

224226
parseNextEditOutcomeFromMap(contentMap)
@@ -231,6 +233,7 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
231233
private fun parseNextEditOutcomeFromMap(contentMap: Map<String, Any>): NextEditOutcome? {
232234
return try {
233235
// Extract position data
236+
@Suppress("UNCHECKED_CAST")
234237
val cursorPos = contentMap["cursorPosition"] as? Map<String, Any>
235238
val cursorPosition = if (cursorPos != null) {
236239
Position(
@@ -241,6 +244,7 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
241244
Position(0, 0)
242245
}
243246

247+
@Suppress("UNCHECKED_CAST")
244248
val finalCursorPos = contentMap["finalCursorPosition"] as? Map<String, Any>
245249
val finalCursorPosition = if (finalCursorPos != null) {
246250
Position(
@@ -252,6 +256,7 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
252256
}
253257

254258
// Extract diffLines
259+
@Suppress("UNCHECKED_CAST")
255260
val diffLinesRaw = contentMap["diffLines"] as? List<Map<String, Any>> ?: emptyList()
256261
val diffLines = diffLinesRaw.map { diffLineMap ->
257262
DiffLine(
@@ -313,15 +318,21 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
313318

314319
private fun parseProcessedItem(response: Any?): ProcessedItem? {
315320
return try {
321+
@Suppress("UNCHECKED_CAST")
316322
val responseMap = response as? Map<String, Any> ?: return null
317-
val content = responseMap["content"] as Map<String, Any> ?: return null
323+
@Suppress("UNCHECKED_CAST")
324+
val content = responseMap["content"] as? Map<String, Any> ?: return null
318325

319326
// Parse location (RangeInFile)
327+
@Suppress("UNCHECKED_CAST")
320328
val locationMap = content["location"] as? Map<String, Any> ?: return null
321329
val filepath = locationMap["filepath"] as? String ?: return null
322330

331+
@Suppress("UNCHECKED_CAST")
323332
val rangeMap = locationMap["range"] as? Map<String, Any> ?: return null
333+
@Suppress("UNCHECKED_CAST")
324334
val startMap = rangeMap["start"] as? Map<String, Any> ?: return null
335+
@Suppress("UNCHECKED_CAST")
325336
val endMap = rangeMap["end"] as? Map<String, Any> ?: return null
326337

327338
val startPosition = Position(
@@ -338,6 +349,7 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
338349
val location = com.github.continuedev.continueintellijextension.RangeInFile(filepath, range)
339350

340351
// Parse outcome (NextEditOutcome) - reuse existing logic from parseNextEditOutcome
352+
@Suppress("UNCHECKED_CAST")
341353
val outcomeData = content["outcome"] as? Map<String, Any> ?: return null
342354
val outcome = parseNextEditOutcomeFromMap(outcomeData) ?: return null
343355

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/utils/Paths.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.continuedev.continueintellijextension.utils
22

3-
import com.intellij.ide.plugins.PluginManager
3+
import com.intellij.ide.plugins.PluginManagerCore
44
import com.intellij.openapi.extensions.PluginId
55
import com.github.continuedev.continueintellijextension.constants.ContinueConstants
66
import java.nio.file.Path
@@ -14,7 +14,7 @@ import java.nio.file.Paths
1414
*/
1515
fun getContinuePluginPath(): Path {
1616
val pluginDescriptor =
17-
PluginManager.getPlugin(PluginId.getId(ContinueConstants.PLUGIN_ID)) ?: throw Exception("Plugin not found")
17+
PluginManagerCore.getPlugin(PluginId.getId(ContinueConstants.PLUGIN_ID)) ?: throw Exception("Plugin not found")
1818
return pluginDescriptor.pluginPath
1919
}
2020

0 commit comments

Comments
 (0)