1
0
mirror of https://github.com/chylex/IntelliJ-Rainbow-Brackets.git synced 2025-05-13 00:34:03 +02:00

Address several deprecation warnings

This commit is contained in:
chylex 2024-12-09 13:19:38 +01:00
parent 93f5911faf
commit b732020017
Signed by: chylex
SSH Key Fingerprint: SHA256:WqM8X/1DDn11LbYM0H5wsqZUjbcKxVsic37L+ERcF4o
2 changed files with 32 additions and 52 deletions
src/main/kotlin/com/chylex/intellij/coloredbrackets

View File

@ -9,21 +9,27 @@ import com.intellij.icons.AllIcons
import com.intellij.ide.actions.ShowSettingsUtilImpl
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.Ref
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotificationProvider
import com.intellij.ui.EditorNotifications
import com.intellij.ui.HyperlinkLabel
import java.util.function.Function
import javax.swing.JComponent
class RainbowifyBanner : EditorNotifications.Provider<EditorNotificationPanel>() {
override fun getKey(): Key<EditorNotificationPanel> = KEY
class RainbowifyBanner : EditorNotificationProvider {
override fun collectNotificationData(project: Project, file: VirtualFile): Function<in FileEditor, out JComponent?> {
return Function { createNotificationPanel(project, file) }
}
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor, project: Project): EditorNotificationPanel? {
private fun createNotificationPanel(project: Project, file: VirtualFile): EditorNotificationPanel? {
val settings = RainbowSettings.instance
if (!settings.isRainbowEnabled) {
if (settings.suppressDisabledCheck) return null
if (settings.suppressDisabledCheck) {
return null
}
return EditorNotificationPanel().apply {
text("Colored Brackets is now disabled")
icon(AllIcons.General.GearPlain)
@ -41,7 +47,9 @@ class RainbowifyBanner : EditorNotifications.Provider<EditorNotificationPanel>()
val psiFile = file.toPsiFile(project)
if (psiFile != null && !checkForBigFile(psiFile)) {
if (settings.suppressBigFileCheck) return null
if (settings.suppressBigFileCheck) {
return null
}
return EditorNotificationPanel().apply {
text("Rainbowify is disabled for files > " + settings.bigFilesLinesThreshold + " lines")
icon(AllIcons.General.InspectionsEye)
@ -61,7 +69,9 @@ class RainbowifyBanner : EditorNotifications.Provider<EditorNotificationPanel>()
settings.languageBlacklist.contains(file.fileType.name) ||
settings.languageBlacklist.contains(memoizedFileExtension(file.name))
) {
if (settings.suppressBlackListCheck) return null
if (settings.suppressBlackListCheck) {
return null
}
return EditorNotificationPanel().apply {
text("Rainbowify is disabled because the language/file extension is in the black list")
icon(AllIcons.General.InspectionsEye)
@ -81,14 +91,10 @@ class RainbowifyBanner : EditorNotifications.Provider<EditorNotificationPanel>()
return null
}
companion object {
private val KEY = Key.create<EditorNotificationPanel>("RainbowifyBanner")
fun EditorNotificationPanel.createComponentActionLabel(labelText: String, callback: (HyperlinkLabel) -> Unit) {
val label: Ref<HyperlinkLabel> = Ref.create()
label.set(createActionLabel(labelText) {
callback(label.get())
})
}
private fun EditorNotificationPanel.createComponentActionLabel(labelText: String, callback: (HyperlinkLabel) -> Unit) {
val label: Ref<HyperlinkLabel> = Ref.create()
label.set(createActionLabel(labelText) {
callback(label.get())
})
}
}

View File

@ -22,8 +22,8 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiFile
import com.intellij.psi.tree.TokenSet
import com.intellij.util.DocumentUtil
import com.intellij.util.containers.IntStack
import com.intellij.util.text.CharArrayUtil
import it.unimi.dsi.fastutil.ints.IntArrayList
import java.lang.StrictMath.abs
import java.lang.StrictMath.min
import java.util.Collections
@ -148,8 +148,8 @@ class RainbowIndentsPass internal constructor(
calculator.calculate()
val lineIndents = calculator.lineIndents
val lines = IntStack()
val indents = IntStack()
val lines = IntArrayList()
val indents = IntArrayList()
lines.push(0)
indents.push(0)
@ -158,10 +158,10 @@ class RainbowIndentsPass internal constructor(
ProgressManager.checkCanceled()
val curIndent = abs(lineIndents[line])
while (!indents.empty() && curIndent <= indents.peek()) {
while (!indents.isEmpty && curIndent <= indents.peekInt(0)) {
ProgressManager.checkCanceled()
val level = indents.pop()
val startLine = lines.pop()
val level = indents.popInt()
val startLine = lines.popInt()
if (level > 0) {
for (i in startLine until line) {
if (level != abs(lineIndents[i])) {
@ -181,10 +181,10 @@ class RainbowIndentsPass internal constructor(
}
}
while (!indents.empty()) {
while (!indents.isEmpty) {
ProgressManager.checkCanceled()
val level = indents.pop()
val startLine = lines.pop()
val level = indents.popInt()
val startLine = lines.popInt()
if (level > 0) {
descriptors.add(createDescriptor(level, startLine, document.lineCount, lineIndents))
}
@ -204,38 +204,12 @@ class RainbowIndentsPass internal constructor(
return IndentGuideDescriptor(level, sLine, endLine)
}
/*
private fun findCodeConstructStart(startLine: Int): Int? {
val document = myEditor.document
val text = document.immutableCharSequence
val lineStartOffset = document.getLineStartOffset(startLine)
val firstNonWsOffset = CharArrayUtil.shiftForward(text, lineStartOffset, " \t")
val type = PsiUtilBase.getPsiFileAtOffset(myFile, firstNonWsOffset).fileType
val language = PsiUtilCore.getLanguageAtOffset(myFile, firstNonWsOffset)
val braceMatcher = BraceMatchingUtil.getBraceMatcher(type, language)
val iterator = myEditor.highlighter.createIterator(firstNonWsOffset)
return if (braceMatcher.isLBraceToken(iterator, text, type)) {
braceMatcher.getCodeConstructStart(myFile, firstNonWsOffset)
} else null
}
private fun findCodeConstructStartLine(startLine: Int): Int {
val codeConstructStart = findCodeConstructStart(startLine)
return if (codeConstructStart != null) myEditor.document.getLineNumber(codeConstructStart) else startLine
}
*/
private inner class IndentsCalculator {
val myComments: MutableMap<String, TokenSet> = HashMap()
val lineIndents = IntArray(document.lineCount) // negative value means the line is empty (or contains a comment) and indent
// (denoted by absolute value) was deduced from enclosing non-empty lines
val myChars: CharSequence
init {
myChars = document.charsSequence
}
val myChars = document.charsSequence
/**
* Calculates line indents for the [target document][.myDocument].