Skip to content

Commit

Permalink
Merge pull request #3169 from Hannah-Sten/qodana-issues-2
Browse files Browse the repository at this point in the history
Convert some services into light services, and rename some variables
  • Loading branch information
PHPirates authored Jul 27, 2023
2 parents c680307 + 0e8ba19 commit b598e2b
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 96 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fun properties(key: String) = project.findProperty(key).toString()
// Supersedes the use of "buildscript" block and "apply plugin:"
plugins {
id("org.jetbrains.intellij") version "1.15.0"
kotlin("jvm") version ("1.8.0")
kotlin("plugin.serialization") version ("1.8.0")
kotlin("jvm") version ("1.9.0")
kotlin("plugin.serialization") version ("1.9.0")

// Plugin which can check for Gradle dependencies, use the help/dependencyUpdates task.
id("com.github.ben-manes.versions") version "0.47.0"
Expand Down Expand Up @@ -270,7 +270,7 @@ tasks.jar {

// https://github.com/ben-manes/gradle-versions-plugin
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
Expand Down
4 changes: 4 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ exclude: # Some of these are valid inspections but not important or accurate eno
- name: LanguageDetectionInspection
- name: GrazieInspection
- name: CheckDependencyLicenses # TeXiFy violates all sorts of licenses, don't care
- name: RetrievingService
paths:
# The class is unused, see TexifyProjectConfigurable
- src/nl/hannahsten/texifyidea/settings/TexifyProjectSettings.kt
# Qodana false positives:
- name: EmptyMethod
- name: SameReturnValue
Expand Down
2 changes: 0 additions & 2 deletions resources/META-INF/extensions/application-settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<applicationService serviceImplementation="nl.hannahsten.texifyidea.settings.TexifySettings"/>
<applicationService
serviceImplementation="nl.hannahsten.texifyidea.settings.conventions.TexifyConventionsGlobalSettingsManager"/>
<projectService
serviceImplementation="nl.hannahsten.texifyidea.settings.conventions.TexifyConventionsProjectSettingsManager"/>
<applicationConfigurable instance="nl.hannahsten.texifyidea.settings.TexifyConfigurable" groupId="language"
id="TexifyConfigurable" displayName="TeXiFy"/>
<projectConfigurable parentId="TexifyConfigurable" id="texify.conventions" displayName="Conventions"
Expand Down
1 change: 0 additions & 1 deletion resources/META-INF/extensions/project-settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<projectService serviceImplementation="nl.hannahsten.texifyidea.run.latex.logtab.ui.LatexErrorTreeViewConfiguration"/>
<sdkType implementation="nl.hannahsten.texifyidea.settings.sdk.TexliveSdk" />
<sdkType implementation="nl.hannahsten.texifyidea.settings.sdk.DockerSdk" />
<sdkType implementation="nl.hannahsten.texifyidea.settings.sdk.MiktexWindowsSdk" />
Expand Down
10 changes: 5 additions & 5 deletions src/nl/hannahsten/texifyidea/action/NewLatexFileAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class NewLatexFileAction : CreateElementActionBase("LaTeX File", "Create a new L

private fun getTemplateNameFromExtension(extensionWithoutDot: String): String {
return when (extensionWithoutDot) {
OPTION_STY_FILE -> LatexTemplatesFactory.fileTemplateSty
OPTION_CLS_FILE -> LatexTemplatesFactory.fileTemplateCls
OPTION_BIB_FILE -> LatexTemplatesFactory.fileTemplateBib
OPTION_TIKZ_FILE -> LatexTemplatesFactory.fileTemplateTikz
else -> LatexTemplatesFactory.fileTemplateTex
OPTION_STY_FILE -> LatexTemplatesFactory.FILE_TEMPLATE_STY
OPTION_CLS_FILE -> LatexTemplatesFactory.FILE_TEMPLATE_CLS
OPTION_BIB_FILE -> LatexTemplatesFactory.FILE_TEMPLATE_BIB
OPTION_TIKZ_FILE -> LatexTemplatesFactory.FILE_TEMPLATE_TIKZ
else -> LatexTemplatesFactory.FILE_TEMPLATE_TEX
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
val source = event.source as? JBCheckBox ?: error("Not a JBCheckBox!")
// Add symbol if selected.
if (source.isSelected && txtPosition.text.contains(location.symbol).not()) {
txtPosition.text = txtPosition.text + location.symbol
txtPosition.text += location.symbol
}
// Remove if deselected.
else {
Expand Down Expand Up @@ -272,7 +272,7 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
}
// When there is something, append width property.
else {
txtCustomOptions.text = txtCustomOptions.text + ",$fieldName=$text"
txtCustomOptions.text += ",$fieldName=$text"
}
}

Expand Down
1 change: 1 addition & 0 deletions src/nl/hannahsten/texifyidea/grammar/BibtexLanguage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.lang.Language
* @author Hannah Schellekens
*/
object BibtexLanguage : Language("Bibtex") {
private fun readResolve(): Any = BibtexLanguage

override fun getDisplayName(): String = "BibTeX"
}
1 change: 1 addition & 0 deletions src/nl/hannahsten/texifyidea/grammar/LatexLanguage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.lang.Language
* @author Sten Wessel
*/
object LatexLanguage : Language("Latex") {
private fun readResolve(): Any = LatexLanguage

override fun getDisplayName(): String {
return "LaTeX"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import nl.hannahsten.texifyidea.psi.LatexNormalText
import nl.hannahsten.texifyidea.util.*
import nl.hannahsten.texifyidea.util.files.document
import nl.hannahsten.texifyidea.util.magic.PatternMagic
import nl.hannahsten.texifyidea.util.magic.PatternMagic.sentenceEndPrefix
import nl.hannahsten.texifyidea.util.magic.PatternMagic.SENTENCE_END_PREFIX
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.inMathContext
import nl.hannahsten.texifyidea.util.parser.isComment
Expand Down Expand Up @@ -63,7 +63,7 @@ open class LatexLineBreakInspection : TexifyInspectionBase() {
// It may be that this inspection is incorrectly triggered on an abbreviation.
// However, that means that the correct user action is to write a normal space after the abbreviation,
// which is what we suggest with this quickfix.
val dotPlusSpace = "^$sentenceEndPrefix(\\.\\s)".toRegex().find(text.text.substring(startOffset, matcher.end()))?.groups?.get(0)?.range?.shiftRight(startOffset + 1)
val dotPlusSpace = "^$SENTENCE_END_PREFIX(\\.\\s)".toRegex().find(text.text.substring(startOffset, matcher.end()))?.groups?.get(0)?.range?.shiftRight(startOffset + 1)
val normalSpaceFix = if (dotPlusSpace != null) LatexSpaceAfterAbbreviationInspection.NormalSpaceFix(dotPlusSpace) else null
val fixes = listOfNotNull(InspectionFix(), normalSpaceFix).toTypedArray()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import com.intellij.psi.PsiElement
import nl.hannahsten.texifyidea.inspections.TexifyRegexInspection
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexNormalText
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.parser.firstParentOfType
import nl.hannahsten.texifyidea.util.parser.inMathContext
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import java.util.regex.Matcher
import java.util.regex.Pattern

Expand All @@ -29,7 +29,6 @@ class LatexEscapeUnderscoreInspection : TexifyRegexInspection(
return super.checkContext(matcher, element)
}

@Suppress("RedundantIf")
private fun PsiElement.isUnderscoreAllowed(): Boolean {
if (this.inMathContext()) return true
if (this.firstParentOfType(LatexNormalText::class) != null) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open class LatexMoveSelectionToFileIntention : TexifyIntentionBase("Move selecti

companion object {

private const val minimumSelectionLength = 24
private const val MINIMUM_SELECTION_LENGTH = 24
}

override fun startInWriteAction() = false
Expand All @@ -31,7 +31,7 @@ open class LatexMoveSelectionToFileIntention : TexifyIntentionBase("Move selecti
}

val selectionSize = selectionOffsets(editor).sumOf { (start, end): Pair<Int, Int> -> end - start }
return selectionSize >= minimumSelectionLength
return selectionSize >= MINIMUM_SELECTION_LENGTH
}

override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
Expand Down
3 changes: 2 additions & 1 deletion src/nl/hannahsten/texifyidea/lang/alias/CommandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package nl.hannahsten.texifyidea.lang.alias

import nl.hannahsten.texifyidea.lang.LabelingCommandInformation
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.containsAny
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.requiredParameter
import nl.hannahsten.texifyidea.util.parser.requiredParameters
import java.io.Serializable
Expand Down Expand Up @@ -35,6 +35,7 @@ import kotlin.collections.set
*/
// Currently it is a singleton, in the future this may be one instance per fileset
object CommandManager : Iterable<String?>, Serializable, AliasManager() {
private fun readResolve(): Any = CommandManager

/**
* Maps an original command to the set of current aliases.
Expand Down
6 changes: 3 additions & 3 deletions src/nl/hannahsten/texifyidea/modules/DefaultFileCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class DefaultFileCreator(

// Apply template.
val template = if (isBibtexEnabled) {
LatexTemplatesFactory.fileTemplateTexWithBib
LatexTemplatesFactory.FILE_TEMPLATE_TEX_WITH_BIB
}
else {
LatexTemplatesFactory.fileTemplateTex
LatexTemplatesFactory.FILE_TEMPLATE_TEX
}
val templateText = LatexTemplatesFactory.getTemplateText(project, template, fileName)

Expand Down Expand Up @@ -69,7 +69,7 @@ class DefaultFileCreator(
}

// Apply template.
val template = LatexTemplatesFactory.fileTemplateBib
val template = LatexTemplatesFactory.FILE_TEMPLATE_BIB
val templateText = LatexTemplatesFactory.getTemplateText(project, template, fileName)

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ object MendeleyAuthenticator {
/**
* The port is fixed by Mendeley, so we choose a port that hopefully no one has anything running on.
*/
private const val port = 59473
private const val PORT = 59473

private const val redirectPath = "/"
private const val REDIRECT_PATH = "/"

private const val redirectUrl = "http://localhost:$port$redirectPath"
private const val REDIRECT_URL = "http://localhost:$PORT$REDIRECT_PATH"

/**
* See [Mendeley documentation](https://dev.mendeley.com/reference/topics/authorization_auth_code.html) for explanations
* about these parameters.
*/
private val authorizationParameters: String = Parameters.build {
append("client_id", MendeleyCredentials.id)
append("redirect_uri", redirectUrl)
append("client_id", MendeleyCredentials.ID)
append("redirect_uri", REDIRECT_URL)
append("response_type", "code")
append("scope", "all")
}.formUrlEncode()
Expand Down Expand Up @@ -80,7 +80,7 @@ object MendeleyAuthenticator {
private fun createAuthenticationServer() {
try {
isUserAuthenticationFinished = false
authenticationServer = embeddedServer(Jetty, port = port) {
authenticationServer = embeddedServer(Jetty, port = PORT) {
routing {
get("/") {
this.call.respondText("You are now logged in to Mendeley. Click OK to continue.")
Expand Down Expand Up @@ -124,10 +124,10 @@ object MendeleyAuthenticator {
formParameters = Parameters.build {
append("grant_type", "authorization_code")
append("code", it)
append("redirect_uri", redirectUrl)
append("redirect_uri", REDIRECT_URL)
}
) {
basicAuth(MendeleyCredentials.id, MendeleyCredentials.secret.decipher())
basicAuth(MendeleyCredentials.ID, MendeleyCredentials.SECRET.decipher())
}.body()

token.getCredentials().first
Expand All @@ -144,10 +144,10 @@ object MendeleyAuthenticator {
formParameters = Parameters.build {
append("grant_type", "refresh_token")
append("refresh_token", refreshToken)
append("redirect_uri", "http://localhost:$port/")
append("redirect_uri", "http://localhost:$PORT/")
}
) {
basicAuth(MendeleyCredentials.id, MendeleyCredentials.secret.decipher())
basicAuth(MendeleyCredentials.ID, MendeleyCredentials.SECRET.decipher())
}.body()

val (tokenCredentials, refreshTokenCredentials) = token.getCredentials()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ object MendeleyCredentials {
/**
* TeXiFy id to communicate with Mendeley.
*/
const val id = "13334"
const val ID = "13334"

/**
* TeXiFy secret to communicate with Mendeley.
*/
const val secret = "xBa\u0083o\u0082VvmSx`qes?"
const val SECRET = "xBa\u0083o\u0082VvmSx`qes?"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LatexConfigurationFactory(type: ConfigurationType) : ConfigurationFactory(

companion object {

private const val factoryName = "LaTeX configuration factory"
private const val FACTORY_NAME = "LaTeX configuration factory"
}

override fun createTemplateConfiguration(project: Project) = when (type) {
Expand All @@ -34,7 +34,7 @@ class LatexConfigurationFactory(type: ConfigurationType) : ConfigurationFactory(
else -> throw IllegalArgumentException("No TeXiFy run configuration type, but ${type.id} was received instead.")
}

override fun getName() = factoryName
override fun getName() = FACTORY_NAME

override fun getId() = factoryName
override fun getId() = FACTORY_NAME
}
14 changes: 7 additions & 7 deletions src/nl/hannahsten/texifyidea/run/latex/LatexOutputPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class LatexOutputPath(private val variant: String, var contentRoot: VirtualFile?

companion object {

const val projectDirString = "{projectDir}"
const val mainFileString = "{mainFileParent}"
const val PROJECT_DIR_STRING = "{projectDir}"
const val MAIN_FILE_STRING = "{mainFileParent}"
}

fun clone(): LatexOutputPath {
Expand All @@ -37,7 +37,7 @@ class LatexOutputPath(private val variant: String, var contentRoot: VirtualFile?
// Acts as a sort of cache
var virtualFile: VirtualFile? = null

var pathString: String = "$projectDirString/$variant"
var pathString: String = "$PROJECT_DIR_STRING/$variant"

/**
* Get the output path based on the values of [virtualFile] and [pathString], create it if it does not exist.
Expand All @@ -50,7 +50,7 @@ class LatexOutputPath(private val variant: String, var contentRoot: VirtualFile?

// Just to be sure, avoid using jetbrains /bin path as output
if (pathString.isBlank()) {
pathString = "$projectDirString/$variant"
pathString = "$PROJECT_DIR_STRING/$variant"
}

// Caching of the result
Expand All @@ -69,13 +69,13 @@ class LatexOutputPath(private val variant: String, var contentRoot: VirtualFile?
return virtualFile!!
}
else {
val pathString = if (pathString.contains(projectDirString)) {
val pathString = if (pathString.contains(PROJECT_DIR_STRING)) {
if (contentRoot == null) return if (mainFile != null) mainFile?.parent else null
pathString.replace(projectDirString, contentRoot?.path ?: return null)
pathString.replace(PROJECT_DIR_STRING, contentRoot?.path ?: return null)
}
else {
if (mainFile == null) return null
pathString.replace(mainFileString, mainFile?.parent?.path ?: return null)
pathString.replace(MAIN_FILE_STRING, mainFile?.parent?.path ?: return null)
}
val path = LocalFileSystem.getInstance().findFileByPath(pathString)
if (path != null && path.isDirectory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ import com.intellij.util.xmlb.XmlSerializerUtil
*/
@State(
name = "LatexErrorTreeViewConfiguration",
storages = [
(
Storage(
StoragePathMacros.WORKSPACE_FILE
)
)
]
storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]
)

@Service(Service.Level.PROJECT)
data class LatexErrorTreeViewConfiguration(
var showKeywordWarnings: MutableMap<LatexKeywordFilter, Boolean> = LatexKeywordFilter.values().associateWith { true }.toMutableMap(),
var showBibtexWarnings: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexR
)
)
)
outputPath = LabeledComponent.create(outputPathField, "Directory for output files, you can use ${LatexOutputPath.mainFileString} or ${LatexOutputPath.projectDirString} as placeholders:")
outputPath = LabeledComponent.create(outputPathField, "Directory for output files, you can use ${LatexOutputPath.MAIN_FILE_STRING} or ${LatexOutputPath.PROJECT_DIR_STRING} as placeholders:")
panel.add(outputPath)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ object EvinceConversation : ViewerConversation() {
* D-Bus object which allows us to execute the FindDocument function, which is exported on the D-Bus
* by Evince.
*/
private const val evinceDaemonPath = "/org/gnome/evince/Daemon"
private const val EVINCE_DAEMON_PATH = "/org/gnome/evince/Daemon"

/**
* Object name of the Evince daemon.
*/
private const val evinceDaemonName = "org.gnome.evince.Daemon"
private const val EVINCE_DAEMON_NAME = "org.gnome.evince.Daemon"

/**
* This variable will hold the latest known Evince process owner. We need to know the owner of the pdf file in order to execute forward search.
Expand Down Expand Up @@ -91,7 +91,7 @@ object EvinceConversation : ViewerConversation() {
val connection = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION)

// Get the Daemon object using its bus name and object path
val daemon = connection.getRemoteObject(evinceDaemonName, evinceDaemonPath, Daemon::class.java)
val daemon = connection.getRemoteObject(EVINCE_DAEMON_NAME, EVINCE_DAEMON_PATH, Daemon::class.java)

// Call the method on the D-Bus by using the function we defined in the Daemon interface
// Catch a NoReply, because it is unknown why Evince cannot start so we don't try to fix that
Expand Down
Loading

0 comments on commit b598e2b

Please sign in to comment.