cleanup, simplify — introduce Logger.debug(lazyMessage: () -> String)

This commit is contained in:
Vladimir Krivosheev
2015-10-07 14:07:40 +02:00
parent f4d3a723a2
commit 4cf9eced4d
9 changed files with 50 additions and 56 deletions
@@ -27,6 +27,7 @@ import com.intellij.openapi.components.StoragePathMacros
import com.intellij.openapi.components.TrackingPathMacroSubstitutor
import com.intellij.openapi.components.impl.stores.StorageUtil
import com.intellij.openapi.components.store.ReadOnlyModificationException
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream
@@ -113,9 +114,7 @@ open class FileBasedStorage(file: File,
try {
val file = getVirtualFile()
if (file == null || file.isDirectory || !file.isValid) {
if (LOG.isDebugEnabled) {
LOG.debug("Document was not loaded for $fileSpec file is ${if (file == null) "null" else "directory"}")
}
LOG.debug { "Document was not loaded for $fileSpec file is ${if (file == null) "null" else "directory"}" }
}
else if (file.length == 0L) {
processReadException(null)
@@ -194,10 +193,7 @@ private fun isEqualContent(result: VirtualFile, lineSeparator: LineSeparator, co
}
private fun doWrite(requestor: Any, file: VirtualFile, content: Any, lineSeparator: LineSeparator, prependXmlProlog: Boolean) {
if (LOG.isDebugEnabled) {
LOG.debug("Save ${file.presentableUrl}")
}
LOG.debug { "Save ${file.presentableUrl}" }
val token = WriteAction.start()
try {
val out = file.getOutputStream(requestor)
@@ -24,6 +24,7 @@ import com.intellij.openapi.components.ComponentManager
import com.intellij.openapi.components.StateStorage
import com.intellij.openapi.components.impl.stores.*
import com.intellij.openapi.components.stateStore
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.module.Module
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.Project
@@ -117,9 +118,7 @@ class StoreAwareProjectManager(virtualFileManager: VirtualFileManager, progressM
private fun isReloadUnblocked(): Boolean {
val count = reloadBlockCount.get()
if (LOG.isDebugEnabled) {
LOG.debug("[RELOAD] myReloadBlockCount = $count")
}
LOG.debug { "[RELOAD] myReloadBlockCount = $count" }
return count == 0
}
@@ -19,13 +19,13 @@ import com.intellij.openapi.components.RoamingType
import com.intellij.openapi.components.StateStorage
import com.intellij.openapi.components.TrackingPathMacroSubstitutor
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.util.JDOMUtil
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.containers.SmartHashSet
import gnu.trove.THashMap
import org.jdom.Attribute
import org.jdom.Element
import java.io.IOException
abstract class XmlElementStorage protected constructor(protected val fileSpec: String,
protected val rootElementName: String,
@@ -87,16 +87,12 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
val oldData = storageDataRef.get()
val newData = getStorageData(true)
if (oldData == null) {
if (LOG.isDebugEnabled) {
LOG.debug("analyzeExternalChangesAndUpdateIfNeed: old data null, load new for ${toString()}")
}
LOG.debug { "analyzeExternalChangesAndUpdateIfNeed: old data null, load new for ${toString()}" }
componentNames.addAll(newData.keys())
}
else {
val changedComponentNames = oldData.getChangedComponentNames(newData)
if (LOG.isDebugEnabled) {
LOG.debug("analyzeExternalChangesAndUpdateIfNeed: changedComponentNames $changedComponentNames for ${toString()}")
}
LOG debug { "analyzeExternalChangesAndUpdateIfNeed: changedComponentNames $changedComponentNames for ${toString()}" }
if (!ContainerUtil.isEmpty(changedComponentNames)) {
componentNames.addAll(changedComponentNames)
}
@@ -17,14 +17,13 @@ package com.intellij.openapi.components.impl.stores
import com.intellij.openapi.components.StateStorage
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.debug
import org.jdom.Element
import java.util.concurrent.atomic.AtomicReference
abstract class StateStorageBase<T : Any> : StateStorage {
companion object {
private val LOG: Logger = Logger.getInstance(StateStorageBase::class.java)
}
private val LOG: Logger = Logger.getInstance(StateStorageBase::class.java)
abstract class StateStorageBase<T : Any> : StateStorage {
private var mySavingDisabled = false
protected val storageDataRef: AtomicReference<T> = AtomicReference()
@@ -45,13 +44,11 @@ abstract class StateStorageBase<T : Any> : StateStorage {
protected abstract fun hasState(storageData: T, componentName: String): Boolean
override fun hasState(componentName: String, reloadData: Boolean): Boolean {
override final fun hasState(componentName: String, reloadData: Boolean): Boolean {
return hasState(getStorageData(reloadData), componentName)
}
public fun getStorageData(): T = getStorageData(false)
protected fun getStorageData(reload: Boolean): T {
protected fun getStorageData(reload: Boolean = false): T {
val storageData = storageDataRef.get()
if (storageData != null && !reload) {
return storageData
@@ -69,23 +66,17 @@ abstract class StateStorageBase<T : Any> : StateStorage {
protected abstract fun loadData(): T
public fun disableSaving() {
if (LOG.isDebugEnabled()) {
LOG.debug("Disabled saving for " + toString())
}
LOG.debug { "Disabled saving for ${toString()}" }
mySavingDisabled = true
}
public fun enableSaving() {
if (LOG.isDebugEnabled()) {
LOG.debug("Enabled saving " + toString())
}
LOG.debug { "Enabled saving ${toString()}" }
mySavingDisabled = false
}
protected fun checkIsSavingDisabled(): Boolean {
if (mySavingDisabled && LOG.isDebugEnabled()) {
LOG.debug("Saving disabled for " + toString())
}
LOG.debug { "Saving disabled for ${toString()}" }
return mySavingDisabled
}
}
@@ -0,0 +1,22 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.diagnostic
inline fun Logger.debug(lazyMessage: () -> String) {
if (isDebugEnabled) {
debug(lazyMessage())
}
}
@@ -17,6 +17,7 @@ package org.jetbrains.settingsRepository
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeAndWaitIfNeed
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.fileTypes.StdFileTypes
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vcs.merge.MergeDialogCustomizer
@@ -80,9 +81,7 @@ public abstract class BaseRepositoryManager(protected val dir: File) : Repositor
override fun read(path: String): InputStream? {
if (isPathIgnored(path)) {
if (LOG.isDebugEnabled) {
LOG.debug("$path is ignored")
}
LOG.debug { "$path is ignored" }
return null
}
@@ -114,15 +113,11 @@ public abstract class BaseRepositoryManager(protected val dir: File) : Repositor
override fun write(path: String, content: ByteArray, size: Int): Boolean {
if (isPathIgnored(path)) {
if (LOG.isDebugEnabled) {
LOG.debug("$path is ignored")
}
LOG.debug { "$path is ignored" }
return false
}
if (LOG.isDebugEnabled) {
LOG.debug("Write $path")
}
LOG.debug { "Write $path" }
try {
lock.write {
@@ -145,9 +140,7 @@ public abstract class BaseRepositoryManager(protected val dir: File) : Repositor
protected abstract fun addToIndex(file: File, path: String, content: ByteArray, size: Int)
override fun delete(path: String) {
if (LOG.isDebugEnabled) {
LOG.debug("Remove $path")
}
LOG.debug { "Remove $path"}
lock.write {
val file = File(dir, path)
@@ -212,7 +205,7 @@ class RepositoryVirtualFile(private val path: String) : LightVirtualFile(PathUti
override fun getPath() = path
override fun setBinaryContent(content: ByteArray, newModificationStamp: Long, newTimeStamp: Long, requestor: Any?) {
$content = content
this.content = content
}
override fun getOutputStream(requestor: Any?, newModificationStamp: Long, newTimeStamp: Long): OutputStream {
@@ -15,6 +15,7 @@
*/
package org.jetbrains.settingsRepository.git
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.util.PathUtilRt
import com.intellij.util.SmartList
@@ -54,9 +55,7 @@ fun commit(repository: Repository, indicator: ProgressIndicator?, commitMessageF
}
}
if (LOG.isDebugEnabled) {
LOG.debug(indexDiffToString(diff))
}
LOG.debug { indexDiffToString(diff) }
indicator?.checkCanceled()
+2 -3
View File
@@ -15,6 +15,7 @@
*/
package org.jetbrains.settingsRepository.git
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.SmartList
@@ -64,9 +65,7 @@ open internal class Pull(val manager: GitRepositoryManager, val indicator: Progr
var refToMerge = prefetchedRefToMerge ?: fetch() ?: return null
val mergeResult = merge(refToMerge, mergeStrategy, commitMessage = commitMessage)
val mergeStatus = mergeResult.status
if (LOG.isDebugEnabled) {
LOG.debug(mergeStatus.toString())
}
LOG.debug { mergeStatus.toString() }
if (mergeStatus == MergeStatus.CONFLICTING) {
return resolveConflicts(mergeResult, repository)
+2 -3
View File
@@ -15,6 +15,7 @@
*/
package org.jetbrains.settingsRepository.git
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.progress.ProgressIndicator
import org.eclipse.jgit.api.MergeResult
import org.eclipse.jgit.merge.MergeStrategy
@@ -26,9 +27,7 @@ import org.jetbrains.settingsRepository.UpdateResult
internal class Reset(manager: GitRepositoryManager, indicator: ProgressIndicator) : Pull(manager, indicator) {
fun reset(toTheirs: Boolean, localRepositoryInitializer: (() -> Unit)? = null): UpdateResult {
val message = if (toTheirs) "Overwrite local to ${manager.getUpstream()}" else "Overwrite remote ${manager.getUpstream()} to local"
if (LOG.isDebugEnabled) {
LOG.debug(message)
}
LOG.debug { message }
val resetResult = repository.resetHard()
val result = MutableUpdateResult(resetResult.updated.keySet(), resetResult.removed)