Skip to content

Commit

Permalink
refactor: extract refreshFiles function
Browse files Browse the repository at this point in the history
  • Loading branch information
lppedd committed Nov 16, 2019
1 parent 7ced850 commit de964f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
16 changes: 16 additions & 0 deletions src/main/kotlin/com/github/lppedd/highlighter/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.lppedd.highlighter

import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.openapi.project.ProjectManager

/**
* @author Edoardo Luppi
*/
object Application {
fun refreshFiles() {
ProjectManager.getInstance()
.openProjects
.map { DaemonCodeAnalyzer.getInstance(it) }
.forEach { it.restart() }
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.lppedd.highlighter.java

import com.github.lppedd.highlighter.Application
import com.github.lppedd.highlighter.Constants
import com.github.lppedd.highlighter.ReturnHighlightStrategy
import com.github.lppedd.highlighter.java.JavaReturnHighlighterConfig.JavaConfig
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.project.ProjectManager
import com.intellij.psi.PsiKeyword

/**
Expand All @@ -31,7 +30,7 @@ class JavaReturnHighlighterConfig : PersistentStateComponent<JavaConfig> {
fun setState(state: JavaConfig) {
this.state = state
updateCurrentHighlightStrategy()
refreshFiles()
Application.refreshFiles()
}

fun getHighlightStrategy() = highlightStrategy
Expand All @@ -50,13 +49,6 @@ class JavaReturnHighlighterConfig : PersistentStateComponent<JavaConfig> {
this.highlightStrategy = highlightStrategy
}

private fun refreshFiles() {
ProjectManager.getInstance()
.openProjects
.map { DaemonCodeAnalyzer.getInstance(it) }
.forEach { it.restart() }
}

companion object {
val INSTANCE: JavaReturnHighlighterConfig by lazy {
ApplicationManager.getApplication().getComponent(JavaReturnHighlighterConfig::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.github.lppedd.highlighter.javascript

import com.github.lppedd.highlighter.Application
import com.github.lppedd.highlighter.Constants
import com.github.lppedd.highlighter.ReturnHighlightStrategy
import com.github.lppedd.highlighter.javascript.JavaScriptReturnHighlighterConfig.JavaScriptConfig
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.lang.javascript.psi.JSReturnStatement
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.project.ProjectManager

/**
* @author Edoardo Luppi
Expand All @@ -31,14 +30,14 @@ class JavaScriptReturnHighlighterConfig : PersistentStateComponent<JavaScriptCon
fun setState(state: JavaScriptConfig) {
this.state = state
updateCurrentHighlightStrategy()
refreshFiles()
Application.refreshFiles()
}

fun getHighlightStrategy() = highlightStrategy

private fun updateCurrentHighlightStrategy() {
var highlightStrategy: ReturnHighlightStrategy<JSReturnStatement> =
JavaScriptAlwaysHighlightStrategy
JavaScriptAlwaysHighlightStrategy

if (state.isOnlyTopLevelReturns) {
highlightStrategy = JavaScriptTopLevelHighlightStrategy
Expand All @@ -51,13 +50,6 @@ class JavaScriptReturnHighlighterConfig : PersistentStateComponent<JavaScriptCon
this.highlightStrategy = highlightStrategy
}

private fun refreshFiles() {
ProjectManager.getInstance()
.openProjects
.map { DaemonCodeAnalyzer.getInstance(it) }
.forEach { it.restart() }
}

companion object {
val INSTANCE: JavaScriptReturnHighlighterConfig by lazy {
ApplicationManager.getApplication().getComponent(JavaScriptReturnHighlighterConfig::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.lppedd.highlighter.php

import com.github.lppedd.highlighter.Application
import com.github.lppedd.highlighter.Constants
import com.github.lppedd.highlighter.ReturnHighlightStrategy
import com.github.lppedd.highlighter.php.PhpReturnHighlighterConfig.PhpConfig
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.project.ProjectManager
import com.jetbrains.php.lang.psi.elements.PhpReturn

/**
Expand All @@ -31,7 +30,7 @@ class PhpReturnHighlighterConfig : PersistentStateComponent<PhpConfig> {
fun setState(state: PhpConfig) {
this.state = state
updateCurrentHighlightStrategy()
refreshFiles()
Application.refreshFiles()
}

fun getHighlightStrategy() = highlightStrategy
Expand All @@ -47,13 +46,6 @@ class PhpReturnHighlighterConfig : PersistentStateComponent<PhpConfig> {
this.highlightStrategy = highlightStrategy
}

private fun refreshFiles() {
ProjectManager.getInstance()
.openProjects
.map { DaemonCodeAnalyzer.getInstance(it) }
.forEach { it.restart() }
}

companion object {
val INSTANCE: PhpReturnHighlighterConfig by lazy {
ApplicationManager.getApplication().getComponent(PhpReturnHighlighterConfig::class.java)
Expand Down

0 comments on commit de964f3

Please sign in to comment.