Skip to content

Commit

Permalink
Code cleanups (#4542)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 30, 2022
1 parent a6a2614 commit 10e9e4c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
Expand Up @@ -4,13 +4,12 @@ import java.io.Closeable
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.function.Supplier

typealias Task<T> = CompletableFuture<T>
typealias TaskList<T> = List<CompletableFuture<T>>

fun <T> TaskPool.task(block: () -> T): Task<T> =
CompletableFuture.supplyAsync(Supplier { block() }, this)
CompletableFuture.supplyAsync({ block() }, this)

fun <T> Task<T>.recover(block: (Throwable) -> T?): Task<T?> = this.exceptionally(block)

Expand Down
Expand Up @@ -8,6 +8,7 @@ class Errors {
}

fun javaExit() {
@Suppress("ReplaceJavaStaticMethodWithKotlinAnalog")
System.exit(1)
}
}
Expand Up @@ -15,7 +15,7 @@ open class CustomDetektReport @Inject constructor(objects: ObjectFactory) {
@Deprecated("Use outputLocation.set(value)")
@get:Internal
var destination: File?
get() = outputLocation.asFile.getOrNull()
get() = outputLocation.asFile.orNull
set(value) {
outputLocation.set(value)
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ open class DetektReport @Inject constructor(val type: DetektReportType, objects:

@Deprecated("Use outputLocation.set(value)")
var destination: File?
get() = outputLocation.asFile.getOrNull()
get() = outputLocation.asFile.orNull
set(value) {
outputLocation.set(value)
}
Expand Down
Expand Up @@ -122,7 +122,7 @@ class DslGradleRunner @Suppress("LongParameterList") constructor(

@OptIn(ExperimentalStdlibApi::class)
private fun buildGradleRunner(tasks: List<String>): GradleRunner {
val args = buildList<String> {
val args = buildList {
add("--stacktrace")
add("--info")
add("--build-cache")
Expand Down
Expand Up @@ -62,8 +62,7 @@ class HtmlOutputReport : OutputReport() {

private fun renderDate(): String {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val now = OffsetDateTime.now(ZoneOffset.UTC).format(formatter) + " UTC"
return now
return "${OffsetDateTime.now(ZoneOffset.UTC).format(formatter)} UTC"
}

private fun renderMetrics(metrics: Collection<ProjectMetric>) = createHTML().div {
Expand Down
Expand Up @@ -23,7 +23,6 @@ package io.github.detekt.report.xml

import java.util.ArrayList
import java.util.Arrays
import java.util.Collections

/**
* Adapted from Unbescape - https://github.com/unbescape/unbescape/
Expand All @@ -33,7 +32,7 @@ import java.util.Collections
object XmlEscape {

private val REFERENCE_HEXA_PREFIX = "&#x".toCharArray()
private val REFERENCE_SUFFIX = ';'
private const val REFERENCE_SUFFIX = ';'

/**
* Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) **escape** operation
Expand Down Expand Up @@ -169,7 +168,7 @@ object XmlEscape {
@Suppress("ALL")
private object Xml10EscapeSymbolsInitializer {

internal class XmlCodepointValidator {
class XmlCodepointValidator {

/*
* XML 1.0 does not allow many control characters, nor unpaired surrogate chars
Expand Down Expand Up @@ -221,7 +220,7 @@ private object Xml10EscapeSymbolsInitializer {
/*
* Everything non-ASCII is level 2 unless contrary indication.
*/
for (c in 0x80..XmlEscapeSymbols.LEVELS_LEN - 1) {
for (c in 0x80 until XmlEscapeSymbols.LEVELS_LEN) {
escapeLevels[c] = 2
}

Expand Down Expand Up @@ -376,16 +375,16 @@ private object Xml10EscapeSymbolsInitializer {
SORTED_CODEPOINTS_BY_CER = IntArray(structureLen)

val cersOrdered = ArrayList(cers)
Collections.sort(cersOrdered) { o1, o2 -> String(o1).compareTo(String(o2)) }
cersOrdered.sortWith { o1, o2 -> String(o1).compareTo(String(o2)) }

val codepointsOrdered = ArrayList(codepoints)
Collections.sort(codepointsOrdered)
codepointsOrdered.sort()

// Order the CODEPOINT -> CERs (escape)structures
for (i in 0..structureLen - 1) {
for (i in 0 until structureLen) {
val codepoint = codepointsOrdered[i]
SORTED_CODEPOINTS[i] = codepoint
for (j in 0..structureLen - 1) {
for (j in 0 until structureLen) {
if (codepoint == codepoints[j]) {
SORTED_CERS_BY_CODEPOINT[i] = cers[j]
break
Expand All @@ -394,10 +393,10 @@ private object Xml10EscapeSymbolsInitializer {
}

// Order the CERs -> CODEPOINT (unescape)structures
for (i in 0..structureLen - 1) {
for (i in 0 until structureLen) {
val cer = cersOrdered[i]
SORTED_CERS[i] = cer
for (j in 0..structureLen - 1) {
for (j in 0 until structureLen) {
if (Arrays.equals(cer, cers[j])) {
SORTED_CODEPOINTS_BY_CER[i] = codepoints[j]
break
Expand Down Expand Up @@ -428,7 +427,7 @@ private object Xml10EscapeSymbolsInitializer {
/*
* Size of the array specifying the escape levels.
*/
val LEVELS_LEN = (0x9f + 2)
const val LEVELS_LEN = (0x9f + 2)
}
}
}

0 comments on commit 10e9e4c

Please sign in to comment.