Skip to content

Commit

Permalink
Merge pull request #3824 from Hannah-Sten/subsection-structure
Browse files Browse the repository at this point in the history
Remove unnecessary checks in structure presentation
  • Loading branch information
PHPirates authored Dec 27, 2024
2 parents 39114a1 + f4b32eb commit 98d723c
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 86 deletions.
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

0 comments on commit 98d723c

Please sign in to comment.