Skip to content

Commit

Permalink
Fix a bunch of build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nreid260 committed Feb 25, 2022
1 parent ebdebf9 commit e88be9e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
<version>31.0.1-jre</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<artifactId>kotlin-stdlib-jdk7</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
Expand All @@ -165,7 +165,7 @@
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>1.8</version>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
*/
@Throws(FormatterException::class)
internal fun characterRangeToTokenRange(offset: Int, length: Int): Range<Int> {
var length = length
val requiredLength = offset + length
if (requiredLength > text.length) {
throw FormatterException(
Expand All @@ -116,14 +115,15 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
length,
requiredLength))
}
when {
length < 0 -> return EMPTY_RANGE
length == 0 -> // 0 stands for "format the line under the cursor"
length = 1
}
val expandedLength =
when {
length < 0 -> return EMPTY_RANGE
length == 0 -> 1 // 0 stands for "format the line under the cursor"
else -> length
}
val enclosed =
getPositionTokenMap()
.subRangeMap(Range.closedOpen(offset, offset + length))
.subRangeMap(Range.closedOpen(offset, offset + expandedLength))
.asMapOfRanges()
.values
return if (enclosed.isEmpty()) {
Expand All @@ -138,7 +138,7 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
for (tok in toks) {
builder.put(tok.position, tok.column)
}
return builder.build()
return builder.buildOrThrow()
}

private fun buildToks(file: KtFile, fileText: String): ImmutableList<KotlinTok> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,7 @@ class KotlinInputAstVisitor(
builder.open(ZERO)
builder.block(blockIndent) {
builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO)
val (enumEntries, nonEnumEntryStatements) =
body?.children?.partition { it is KtEnumEntry } ?: fail()
val (enumEntries, nonEnumEntryStatements) = body.children.partition { it is KtEnumEntry }
builder.forcedBreak()
visitEnumEntries(enumEntries)

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/facebook/ktfmt/format/Tokenizer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Tokenizer(private val fileText: String, val file: KtFile) : KtTreeVisitorV
}
is LeafPsiElement -> {
val elementText = element.text
val startIndex = element.startOffset
val endIndex = element.endOffset
if (element is PsiWhiteSpace) {
val matcher = WHITESPACE_NEWLINE_REGEX.matcher(elementText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ object TypeNameClassifier {
var hasUppercase = false
var hasLowercase = false
var first = true
for (element in name) {
if (!Character.isAlphabetic(element.toInt())) {
for (char in name) {
if (!Character.isAlphabetic(char.code)) {
continue
}
if (first) {
firstUppercase = Character.isUpperCase(element)
firstUppercase = Character.isUpperCase(char)
first = false
}
hasUppercase = hasUppercase or Character.isUpperCase(element)
hasLowercase = hasLowercase or Character.isLowerCase(element)
hasUppercase = hasUppercase or Character.isUpperCase(char)
hasLowercase = hasLowercase or Character.isLowerCase(char)
}
return if (firstUppercase) {
if (hasLowercase) UPPER_CAMEL else UPPERCASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ class KDocCommentsHelper(private val lineSeparator: String, private val maxLineL

// Wraps and re-indents line comments.
private fun indentLineComments(lines: List<String>, column0: Int): String {
var lines = lines
lines = wrapLineComments(lines, column0)
val wrappedLines = wrapLineComments(lines, column0)
val builder = StringBuilder()
builder.append(lines[0].trim())
builder.append(wrappedLines[0].trim())
val indentString = Strings.repeat(" ", column0)
for (i in 1 until lines.size) {
builder.append(lineSeparator).append(indentString).append(lines[i].trim())
for (i in 1 until wrappedLines.size) {
builder.append(lineSeparator).append(indentString).append(wrappedLines[i].trim())
}
return builder.toString()
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.io.File
import java.io.PrintStream
import java.lang.IllegalStateException
import java.util.concurrent.ForkJoinPool
import kotlin.io.path.createTempDirectory
import org.junit.After
import org.junit.Assert.fail
import org.junit.Test
Expand All @@ -32,7 +33,7 @@ import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class MainTest {

private val root = createTempDir()
private val root = createTempDirectory().toFile()

private val emptyInput = "".byteInputStream()
private val out = ByteArrayOutputStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ class FormatterTest {
deduceMaxWidth = true)

@Test
fun `handle ? for nullalble types`() =
fun `handle qmark for nullalble types`() =
assertFormatted(
"""
|fun doItWithNullReturns(a: String, b: String): Int? {
Expand Down

0 comments on commit e88be9e

Please sign in to comment.