diff --git a/plugins/ByteCodeViewer/resources/messages/BytecodeViewerBundle.properties b/plugins/ByteCodeViewer/resources/messages/BytecodeViewerBundle.properties index 681a351cd16f..f37bef5a820a 100644 --- a/plugins/ByteCodeViewer/resources/messages/BytecodeViewerBundle.properties +++ b/plugins/ByteCodeViewer/resources/messages/BytecodeViewerBundle.properties @@ -1,6 +1,5 @@ action.BytecodeViewer.text=Show Bytecode class.file.may.be.out.of.date=Class File May Be Outdated loading.bytecode=Loading bytecode\u2026 -checking.if.bytecode.is.up.to.date=Checking if bytecode is up to date bytecode.for.class=Bytecode for class ''{0}'' open.java.file.to.see.bytecode=Open a Java source file or class file to see the corresponding bytecode. diff --git a/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/BytecodeToolWindowPanel.kt b/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/BytecodeToolWindowPanel.kt index 22069e360ecd..a65ae1266e87 100644 --- a/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/BytecodeToolWindowPanel.kt +++ b/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/BytecodeToolWindowPanel.kt @@ -22,7 +22,6 @@ import com.intellij.openapi.fileEditor.TextEditor import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.Task import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.util.Key import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.text.StringUtil @@ -30,13 +29,10 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.wm.ToolWindow import com.intellij.psi.PsiClass import com.intellij.psi.util.PsiUtilBase -import com.intellij.ui.JBColor import com.intellij.util.ThrowableRunnable import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.concurrency.annotations.RequiresWriteLock -import com.intellij.util.progress.sleepCancellable -import org.jetbrains.annotations.Nls import java.awt.BorderLayout import java.awt.FlowLayout import java.util.function.Consumer @@ -57,16 +53,12 @@ internal class BytecodeToolWindowPanel( private val classNameLabel: JLabel = JLabel() - private val errorLabel: JLabel = JLabel() - private var currentlyDisplayedClassFQN: String? = null private var currentlyFocusedSourceFile: VirtualFile? private var existingLoadBytecodeTask: LoadBytecodeTask? = null - private var existingUpdateBytecodeStatusTask: UpdateBytecodeStatusTask? = null - init { currentlyFocusedSourceFile = initialSourceEditor.virtualFile @@ -82,10 +74,9 @@ internal class BytecodeToolWindowPanel( private fun setUpContent() { bytecodeEditor.setBorder(null) add(bytecodeEditor.getComponent()) - val optionPanel = JPanel(FlowLayout(FlowLayout.LEFT, 12, 8)) - optionPanel.add(classNameLabel) - errorLabel.setForeground(JBColor.YELLOW) - optionPanel.add(errorLabel) + val optionPanel = JPanel(FlowLayout(FlowLayout.LEFT, 12, 8)).apply { + add(classNameLabel) + } add(optionPanel, BorderLayout.NORTH) } @@ -146,7 +137,6 @@ internal class BytecodeToolWindowPanel( } currentlyDisplayedClassFQN = containingClass.getQualifiedName() - queueUpdateBytecodeStatusTask() val sourceStartOffset = sourceEditor.getCaretModel().getCurrentCaret().getSelectionStart() val sourceEndOffset = sourceEditor.getCaretModel().getCurrentCaret().getSelectionEnd() @@ -190,24 +180,6 @@ internal class BytecodeToolWindowPanel( bytecodeEditor.getSelectionModel().setSelection(startOffset, endOffset) } - private fun queueUpdateBytecodeStatusTask() { - if (currentlyFocusedSourceFile == null) return - - // If a new task was scheduled, we want to cancel the previous one. - if (existingUpdateBytecodeStatusTask != null) { - if (existingUpdateBytecodeStatusTask?.isRunning == true) { - existingUpdateBytecodeStatusTask?.cancel() - } - existingUpdateBytecodeStatusTask = null - } - existingUpdateBytecodeStatusTask = UpdateBytecodeStatusTask(project, currentlyFocusedSourceFile!!) { isUpToDate -> - ApplicationManager.getApplication().invokeLater { - if (isUpToDate == true) setErrorText(null) else setErrorText(message("class.file.may.be.out.of.date")) - } - } - existingUpdateBytecodeStatusTask?.queue() - } - /** Update the contents of the whole editor in the tool window, including reading bytecode again from the currently opened file. */ @RequiresEdt private fun queueLoadBytecodeTask(@RequiresWriteLock @RequiresEdt onAfterBytecodeLoaded: Runnable?) { @@ -245,12 +217,6 @@ internal class BytecodeToolWindowPanel( bytecodeEditor.getDocument().setText(StringUtil.convertLineSeparators(bytecodeWithoutDebugInfo)) } - @RequiresEdt - private fun setErrorText(errorText: @Nls String?) { - errorLabel.setText(errorText) - errorLabel.isVisible = errorText != null - } - @RequiresEdt private fun setClassName(className: @NlsSafe String) { classNameLabel.setText(message("bytecode.for.class", className)) @@ -313,38 +279,6 @@ internal class BytecodeToolWindowPanel( } } - private class UpdateBytecodeStatusTask( - project: Project, - private val myVirtualFile: VirtualFile, - private val onUpToDateCheckDone: Consumer - ) : Task.Backgroundable(project, message( - "checking.if.bytecode.is.up.to.date"), true) { - private var myProgressIndicator: ProgressIndicator? = null - - fun cancel() { - myProgressIndicator?.cancel() - } - - val isRunning: Boolean get() = myProgressIndicator != null && myProgressIndicator!!.isRunning() - - @RequiresBackgroundThread - override fun run(indicator: ProgressIndicator) { - if (myProject == null) return - if (!myVirtualFile.isValid()) return - myProgressIndicator = indicator - - sleepCancellable(1000) // Poor man's event debouncing - - val isInContent = ReadAction.computeCancellable { - ProjectRootManager.getInstance(myProject!!).getFileIndex().isInContent(myVirtualFile) - } - if (!isInContent) return - - val isUpToDate = !isMarkedForCompilation(myProject!!, myVirtualFile) - onUpToDateCheckDone.accept(isUpToDate) - } - } - companion object { const val TOOL_WINDOW_ID: String = "Java Bytecode" diff --git a/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeViewerUtil.kt b/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeViewerUtil.kt index 759da5f35430..04e53ef61e95 100644 --- a/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeViewerUtil.kt +++ b/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeViewerUtil.kt @@ -29,9 +29,9 @@ internal fun isValidFileType(fileType: FileType?): Boolean { return fileType === JavaClassFileType.INSTANCE || fileType === JavaFileType.INSTANCE } -internal fun isMarkedForCompilation(project: Project, virtualFile: VirtualFile?): Boolean { +internal fun isMarkedForCompilation(project: Project, virtualFile: VirtualFile): Boolean { val compilerManager = CompilerManager.getInstance(project) - val compileScope = compilerManager.createFilesCompileScope(arrayOf(virtualFile)) + val compileScope = compilerManager.createFilesCompileScope(arrayOf(virtualFile)) return !compilerManager.isUpToDate(compileScope) }