From 36f04432557668c276b9238ad599659c8bbaa2c7 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Thu, 26 Dec 2024 16:31:37 +0100 Subject: [PATCH 1/2] Remove unnecessary checks in structure presentation --- .../texifyidea/structure/latex/BibitemPresentation.kt | 4 ---- .../texifyidea/structure/latex/LatexChapterPresentation.kt | 6 ------ .../texifyidea/structure/latex/LatexIncludePresentation.kt | 5 ----- .../texifyidea/structure/latex/LatexLabelPresentation.kt | 7 ------- .../structure/latex/LatexParagraphPresentation.kt | 4 ---- .../texifyidea/structure/latex/LatexPartPresentation.kt | 4 ---- .../texifyidea/structure/latex/LatexSectionPresentation.kt | 4 ---- .../structure/latex/LatexStructureViewCommandElement.kt | 5 +++-- .../structure/latex/LatexSubParagraphPresentation.kt | 4 ---- .../structure/latex/LatexSubSectionPresentation.kt | 4 ---- .../structure/latex/LatexSubSubSectionPresentation.kt | 4 ---- 11 files changed, 3 insertions(+), 48 deletions(-) diff --git a/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt index fa43a31848..041bd3862c 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt @@ -14,10 +14,6 @@ class BibitemPresentation(labelCommand: LatexCommands) : ItemPresentation { private val locationString: String init { - if (labelCommand.commandToken.text != "\\bibitem") { - throw IllegalArgumentException("command is no \\bibitem-command") - } - // Get label name. this.bibitemName = labelCommand.getRequiredParameters().firstOrNull() ?: "" diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt index 940e89bb70..ba84b36147 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt @@ -1,10 +1,8 @@ package nl.hannahsten.texifyidea.structure.latex import nl.hannahsten.texifyidea.TexifyIcons -import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand import nl.hannahsten.texifyidea.psi.LatexCommands import nl.hannahsten.texifyidea.structure.EditableHintPresentation -import nl.hannahsten.texifyidea.util.magic.cmd /** * @author Hannah Schellekens @@ -15,10 +13,6 @@ class LatexChapterPresentation(chapterCommand: LatexCommands) : EditableHintPres private var hint = "" init { - if (chapterCommand.name != LatexGenericRegularCommand.CHAPTER.cmd) { - throw IllegalArgumentException("command is no \\chapter-command") - } - this.chapterName = chapterCommand.getRequiredParameters().getOrElse(0) { "No chapter name" } } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt index c3bcadd1dd..bc053bdea1 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt @@ -4,7 +4,6 @@ import com.intellij.navigation.ItemPresentation import nl.hannahsten.texifyidea.TexifyIcons import nl.hannahsten.texifyidea.psi.LatexCommands import nl.hannahsten.texifyidea.util.parser.getIncludedFiles -import nl.hannahsten.texifyidea.util.updateAndGetIncludeCommands /** * @author Hannah Schellekens @@ -14,10 +13,6 @@ class LatexIncludePresentation(labelCommand: LatexCommands) : ItemPresentation { private val fileName: String init { - if (labelCommand.name !in updateAndGetIncludeCommands(labelCommand.project)) { - throw IllegalArgumentException("Command $labelCommand is no include command") - } - this.fileName = labelCommand.getIncludedFiles(true).joinToString { it.name } } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexLabelPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexLabelPresentation.kt index 8572f16974..c8cbe42f5e 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexLabelPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexLabelPresentation.kt @@ -5,7 +5,6 @@ import com.intellij.openapi.fileEditor.FileDocumentManager import nl.hannahsten.texifyidea.TexifyIcons import nl.hannahsten.texifyidea.lang.alias.CommandManager import nl.hannahsten.texifyidea.psi.LatexCommands -import nl.hannahsten.texifyidea.util.labels.getLabelDefinitionCommandsNoUpdate import nl.hannahsten.texifyidea.util.parser.requiredParameter /** @@ -17,12 +16,6 @@ class LatexLabelPresentation(labelCommand: LatexCommands) : ItemPresentation { private val presentableText: String init { - val labelingCommands = getLabelDefinitionCommandsNoUpdate() - if (!labelingCommands.contains(labelCommand.commandToken.text)) { - val token = labelCommand.commandToken.text - throw IllegalArgumentException("command '$token' is no \\label-command") - } - val position = CommandManager.labelAliasesInfo.getOrDefault(labelCommand.commandToken.text, null)?.positions?.firstOrNull() ?: 0 diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt index 9f9c584c24..8014bc8bbd 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexParagraphPresentation.kt @@ -13,10 +13,6 @@ class LatexParagraphPresentation(paragraphCommand: LatexCommands) : EditableHint private var hint = "" init { - if (paragraphCommand.commandToken.text != "\\paragraph") { - throw IllegalArgumentException("command is no \\paragraph-command") - } - if (paragraphCommand.getRequiredParameters().isEmpty()) { this.paragraphName = "" } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt index a765f7b3a0..ca716577d8 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt @@ -13,10 +13,6 @@ class LatexPartPresentation(partCommand: LatexCommands) : EditableHintPresentati private var hint = "" init { - if (partCommand.commandToken.text != "\\part") { - throw IllegalArgumentException("command is no \\part-command") - } - this.partName = partCommand.getRequiredParameters().firstOrNull() ?: "Unnamed part" } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt index 9c98a8f8da..67325c6930 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt @@ -13,10 +13,6 @@ class LatexSectionPresentation(sectionCommand: LatexCommands) : EditableHintPres private var hint = "" init { - if (sectionCommand.commandToken.text != "\\section") { - throw IllegalArgumentException("command is no \\section-command") - } - this.sectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed section" } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewCommandElement.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewCommandElement.kt index c575552994..ea8a605fd0 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewCommandElement.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewCommandElement.kt @@ -4,10 +4,11 @@ import com.intellij.ide.structureView.StructureViewTreeElement import com.intellij.ide.util.treeView.smartTree.SortableTreeElement import com.intellij.ide.util.treeView.smartTree.TreeElement import com.intellij.navigation.NavigationItem +import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand import nl.hannahsten.texifyidea.psi.LatexCommands import nl.hannahsten.texifyidea.structure.EditableHintPresentation +import nl.hannahsten.texifyidea.util.magic.cmd import nl.hannahsten.texifyidea.util.parser.nextCommand -import java.util.* /** * @author Hannah Schellekens @@ -18,7 +19,7 @@ class LatexStructureViewCommandElement private constructor(private val element: @JvmStatic fun newCommand(commands: LatexCommands): LatexStructureViewCommandElement? { - if ("\\let" == commands.commandToken.text || "\\def" == commands.commandToken.text) { + if (LatexGenericRegularCommand.LET.cmd == commands.name || LatexGenericRegularCommand.DEF.cmd == commands.commandToken.text) { val sibling = commands.nextCommand() ?: return null return LatexStructureViewCommandElement(sibling) diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt index 1dec33498c..6fa4fb43bc 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt @@ -13,10 +13,6 @@ class LatexSubParagraphPresentation(subParagraphCommand: LatexCommands) : Editab private var hint = "" init { - if (subParagraphCommand.name != "\\subparagraph") { - throw IllegalArgumentException("command is no \\subparagraph-command") - } - this.subParagraphName = subParagraphCommand.getRequiredParameters().firstOrNull() ?: "Unknown subparagraph" } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt index d78628c966..dbb8b5ef21 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt @@ -13,10 +13,6 @@ class LatexSubSectionPresentation(sectionCommand: LatexCommands) : EditableHintP private var hint = "" init { - if (sectionCommand.commandToken.text != "\\subsection") { - throw IllegalArgumentException("command is no \\subsection-command") - } - this.subSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsection" } diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt index 64d647858f..3f4e3d332f 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt @@ -13,10 +13,6 @@ class LatexSubSubSectionPresentation(sectionCommand: LatexCommands) : EditableHi private var hint = "" init { - if (sectionCommand.commandToken.text != "\\subsubsection") { - throw IllegalArgumentException("command is no \\subsubsection-command") - } - this.subSubSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsubsection" } From f4b32eb05734cba105633eeb84e56653519ec281 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Fri, 27 Dec 2024 12:11:20 +0100 Subject: [PATCH 2/2] Formatting --- .../texifyidea/structure/latex/BibitemPresentation.kt | 5 ++--- .../texifyidea/structure/latex/LatexChapterPresentation.kt | 6 +----- .../texifyidea/structure/latex/LatexIncludePresentation.kt | 6 +----- .../texifyidea/structure/latex/LatexPartPresentation.kt | 6 +----- .../texifyidea/structure/latex/LatexSectionPresentation.kt | 6 +----- .../structure/latex/LatexSubParagraphPresentation.kt | 6 +----- .../structure/latex/LatexSubSectionPresentation.kt | 6 +----- .../structure/latex/LatexSubSubSectionPresentation.kt | 6 +----- 8 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt index 041bd3862c..341b2f19b8 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt @@ -10,12 +10,11 @@ import nl.hannahsten.texifyidea.psi.LatexCommands */ class BibitemPresentation(labelCommand: LatexCommands) : ItemPresentation { - private val bibitemName: String + // Get label name. + private val bibitemName = labelCommand.getRequiredParameters().firstOrNull() ?: "" private val locationString: String init { - // Get label name. - this.bibitemName = labelCommand.getRequiredParameters().firstOrNull() ?: "" // Location string. val manager = FileDocumentManager.getInstance() diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt index ba84b36147..e99d8500ee 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt @@ -9,13 +9,9 @@ import nl.hannahsten.texifyidea.structure.EditableHintPresentation */ class LatexChapterPresentation(chapterCommand: LatexCommands) : EditableHintPresentation { - private val chapterName: String + private val chapterName = chapterCommand.getRequiredParameters().getOrElse(0) { "No chapter name" } private var hint = "" - init { - this.chapterName = chapterCommand.getRequiredParameters().getOrElse(0) { "No chapter name" } - } - override fun getPresentableText() = chapterName override fun getLocationString() = hint diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt index bc053bdea1..a4e86e88d6 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt @@ -10,11 +10,7 @@ import nl.hannahsten.texifyidea.util.parser.getIncludedFiles */ class LatexIncludePresentation(labelCommand: LatexCommands) : ItemPresentation { - private val fileName: String - - init { - this.fileName = labelCommand.getIncludedFiles(true).joinToString { it.name } - } + private val fileName = labelCommand.getIncludedFiles(true).joinToString { it.name } override fun getPresentableText() = fileName diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt index ca716577d8..3fdc77c558 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt @@ -9,13 +9,9 @@ import nl.hannahsten.texifyidea.structure.EditableHintPresentation */ class LatexPartPresentation(partCommand: LatexCommands) : EditableHintPresentation { - private val partName: String + private val partName = partCommand.getRequiredParameters().firstOrNull() ?: "Unnamed part" private var hint = "" - init { - this.partName = partCommand.getRequiredParameters().firstOrNull() ?: "Unnamed part" - } - override fun getPresentableText() = partName override fun getLocationString() = hint diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt index 67325c6930..8b4e59759d 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt @@ -9,13 +9,9 @@ import nl.hannahsten.texifyidea.structure.EditableHintPresentation */ class LatexSectionPresentation(sectionCommand: LatexCommands) : EditableHintPresentation { - private val sectionName: String + private val sectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed section" private var hint = "" - init { - this.sectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed section" - } - override fun getPresentableText() = sectionName override fun getLocationString() = hint diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt index 6fa4fb43bc..bed653afdc 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt @@ -9,13 +9,9 @@ import nl.hannahsten.texifyidea.structure.EditableHintPresentation */ class LatexSubParagraphPresentation(subParagraphCommand: LatexCommands) : EditableHintPresentation { - private val subParagraphName: String + private val subParagraphName = subParagraphCommand.getRequiredParameters().firstOrNull() ?: "Unknown subparagraph" private var hint = "" - init { - this.subParagraphName = subParagraphCommand.getRequiredParameters().firstOrNull() ?: "Unknown subparagraph" - } - override fun getPresentableText() = subParagraphName override fun getLocationString() = hint diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt index dbb8b5ef21..e3b47f34c8 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt @@ -9,13 +9,9 @@ import nl.hannahsten.texifyidea.structure.EditableHintPresentation */ class LatexSubSectionPresentation(sectionCommand: LatexCommands) : EditableHintPresentation { - private val subSectionName: String + private val subSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsection" private var hint = "" - init { - this.subSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsection" - } - override fun getPresentableText() = subSectionName override fun getLocationString() = hint diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt index 3f4e3d332f..101587980e 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt @@ -9,13 +9,9 @@ import nl.hannahsten.texifyidea.structure.EditableHintPresentation */ class LatexSubSubSectionPresentation(sectionCommand: LatexCommands) : EditableHintPresentation { - private val subSubSectionName: String + private val subSubSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsubsection" private var hint = "" - init { - this.subSubSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsubsection" - } - override fun getPresentableText() = subSubSectionName override fun getLocationString() = hint