-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bunch of build warnings #283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import com.google.googlejavaformat.Input | |
import com.google.googlejavaformat.Newlines | ||
import com.google.googlejavaformat.java.FormatterException | ||
import com.google.googlejavaformat.java.JavaOutput | ||
import java.util.LinkedHashMap | ||
import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtil | ||
import org.jetbrains.kotlin.lexer.KtTokens | ||
import org.jetbrains.kotlin.psi.KtFile | ||
|
@@ -107,7 +108,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( | ||
|
@@ -116,14 +116,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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should preserve the current behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /facepalm |
||
} | ||
val enclosed = | ||
getPositionTokenMap() | ||
.subRangeMap(Range.closedOpen(offset, offset + length)) | ||
.subRangeMap(Range.closedOpen(offset, offset + expandedLength)) | ||
.asMapOfRanges() | ||
.values | ||
return if (enclosed.isEmpty()) { | ||
|
@@ -134,11 +135,11 @@ class KotlinInput(private val text: String, file: KtFile) : Input() { | |
} | ||
|
||
private fun makePositionToColumnMap(toks: List<KotlinTok>): ImmutableMap<Int, Int> { | ||
val builder = ImmutableMap.builder<Int, Int>() | ||
val builder = LinkedHashMap<Int, Int>() | ||
for (tok in toks) { | ||
builder.put(tok.position, tok.column) | ||
} | ||
return builder.build() | ||
return ImmutableMap.copyOf(builder) | ||
Comment on lines
-137
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the build warning here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I think it's fine this time, but we'll keep running into these problems, since Meta / OSS isn't aware of Guava 31. |
||
} | ||
|
||
private fun buildToks(file: KtFile, fileText: String): ImmutableList<KotlinTok> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
Comment on lines
-127
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're changing this how about using the Kotlin extension methods? |
||
} | ||
return if (firstUppercase) { | ||
if (hasLowercase) UPPER_CAMEL else UPPERCASE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import java.io.PrintStream | |
import java.lang.IllegalStateException | ||
import java.nio.file.Files | ||
import java.util.concurrent.ForkJoinPool | ||
import kotlin.io.path.createTempDirectory | ||
import org.junit.After | ||
import org.junit.Assert.fail | ||
import org.junit.Test | ||
|
@@ -33,7 +34,7 @@ import org.junit.runners.JUnit4 | |
@RunWith(JUnit4::class) | ||
class MainTest { | ||
|
||
private val root = createTempDir() | ||
private val root = createTempDirectory().toFile() | ||
Comment on lines
-36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the issue here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private val emptyInput = "".byteInputStream() | ||
private val out = ByteArrayOutputStream() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2229,7 +2229,7 @@ class FormatterTest { | |
deduceMaxWidth = true) | ||
|
||
@Test | ||
fun `handle ? for nullalble types`() = | ||
fun `handle qmark for nullalble types`() = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "question mark" please Let's avoid abbreviations for easier readability |
||
assertFormatted( | ||
""" | ||
|fun doItWithNullReturns(a: String, b: String): Int? { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the build warning here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is needed for the changes to core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt