diff --git a/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt index fa43a3184..341b2f19b 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/BibitemPresentation.kt @@ -10,16 +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 { - if (labelCommand.commandToken.text != "\\bibitem") { - throw IllegalArgumentException("command is no \\bibitem-command") - } - - // 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 940e89bb7..e99d8500e 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexChapterPresentation.kt @@ -1,27 +1,17 @@ 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 */ class LatexChapterPresentation(chapterCommand: LatexCommands) : EditableHintPresentation { - private val chapterName: String + private val chapterName = chapterCommand.getRequiredParameters().getOrElse(0) { "No chapter name" } 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" } - } - 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 c3bcadd1d..a4e86e88d 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexIncludePresentation.kt @@ -4,22 +4,13 @@ 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 */ 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 } - } + private val fileName = labelCommand.getIncludedFiles(true).joinToString { it.name } override fun getPresentableText() = fileName diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexLabelPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexLabelPresentation.kt index 8572f1697..c8cbe42f5 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 9f9c584c2..8014bc8bb 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 a765f7b3a..3fdc77c55 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexPartPresentation.kt @@ -9,17 +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 { - if (partCommand.commandToken.text != "\\part") { - throw IllegalArgumentException("command is no \\part-command") - } - - 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 9c98a8f8d..8b4e59759 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSectionPresentation.kt @@ -9,17 +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 { - if (sectionCommand.commandToken.text != "\\section") { - throw IllegalArgumentException("command is no \\section-command") - } - - this.sectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed section" - } - override fun getPresentableText() = sectionName override fun getLocationString() = hint diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewCommandElement.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewCommandElement.kt index c57555299..ea8a605fd 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 1dec33498..bed653afd 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubParagraphPresentation.kt @@ -9,17 +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 { - if (subParagraphCommand.name != "\\subparagraph") { - throw IllegalArgumentException("command is no \\subparagraph-command") - } - - 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 d78628c96..e3b47f34c 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSectionPresentation.kt @@ -9,17 +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 { - if (sectionCommand.commandToken.text != "\\subsection") { - throw IllegalArgumentException("command is no \\subsection-command") - } - - 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 64d647858..101587980 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexSubSubSectionPresentation.kt @@ -9,17 +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 { - if (sectionCommand.commandToken.text != "\\subsubsection") { - throw IllegalArgumentException("command is no \\subsubsection-command") - } - - this.subSubSectionName = sectionCommand.getRequiredParameters().firstOrNull() ?: "Unnamed subsubsection" - } - override fun getPresentableText() = subSubSectionName override fun getLocationString() = hint