Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary checks in structure presentation #3824

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading