Skip to content

Commit

Permalink
Fix a few kotlinc / compileKotlin warnings (cashapp#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob authored May 4, 2024
1 parent aba7b36 commit de66f62
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
1 change: 1 addition & 0 deletions paparazzi/src/main/java/app/cash/paparazzi/internal/Gc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal object Gc {
var obj: Any? = Any()
val ref = WeakReference<Any>(obj)

@Suppress("UNUSED_VALUE") // The null is unused, but it's important that the obj local variable loses the reference.
obj = null
while (ref.get() != null) {
System.gc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ internal abstract class InMemoryParser : KXmlParser() {

private fun onNextFromStartDocument() {
val rootTag = rootTag()
parsingState = if (rootTag != null) {
push(rootTag)
START_TAG
} else {
END_DOCUMENT
}
push(rootTag)
parsingState = START_TAG
}

private fun onNextFromStartTag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal class LayoutPullParser : InMemoryParser, AaptAttrParser, ILayoutPullPar
val count = attributeCount
for (i in 0 until count) {
val namespace = getAttributeNamespace(i)
if (namespace != null && namespace == TOOLS_URI) {
if (namespace == TOOLS_URI) {
val attribute = getAttributeName(i)!!
if (attribute == ATTR_IGNORE) {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,39 +122,39 @@ internal abstract class MultiResourceRepository internal constructor(displayName

override fun getMap(
namespace: ResourceNamespace,
type: ResourceType
resourceType: ResourceType
): ListMultimap<String, ResourceItem>? {
val repositoriesForNamespace = leafsByNamespace[namespace]
if (repositoriesForNamespace.size == 1) {
val repository = repositoriesForNamespace[0]
return getResources(repository, namespace, type)
return getResources(repository, namespace, resourceType)
}

var map = cachedMaps[namespace, type]
var map = cachedMaps[namespace, resourceType]
if (map != null) {
return map
}

// Merge all items of the given type.
for (repository in repositoriesForNamespace) {
val items = getResources(repository, namespace, type)
val items = getResources(repository, namespace, resourceType)
if (!items.isEmpty) {
if (map == null) {
// Create a new map.
// We only add a duplicate item if there isn't an item with the same qualifiers, and it
// is not a styleable or an id. Styleables and ids are allowed to be defined in multiple
// places even with the same qualifiers.
map =
if (type === ResourceType.STYLEABLE || type === ResourceType.ID) {
if (resourceType === ResourceType.STYLEABLE || resourceType === ResourceType.ID) {
ArrayListMultimap.create<String, ResourceItem>()
} else {
PerConfigResourceMap(resourceComparator)
}
cachedMaps.put(namespace, type, map)
cachedMaps.put(namespace, resourceType, map)
}
map!!.putAll(items)
if (repository is LocalResourceRepository) {
resourceNames.put(repository, type, items.keySet().toSet())
resourceNames.put(repository, resourceType, items.keySet().toSet())
}
}
}
Expand Down Expand Up @@ -332,19 +332,19 @@ internal abstract class MultiResourceRepository internal constructor(displayName

override fun get(index: Int): ResourceItem = resourceItems[index][0]

override fun add(item: ResourceItem): Boolean {
add(item, 0)
override fun add(element: ResourceItem): Boolean {
add(element, 0)
return true
}

override fun addAll(items: Collection<ResourceItem>): Boolean {
if (items.isEmpty()) {
override fun addAll(elements: Collection<ResourceItem>): Boolean {
if (elements.isEmpty()) {
return false
}
if (items.size == 1) {
return add(items.iterator().next())
if (elements.size == 1) {
return add(elements.iterator().next())
}
val sortedItems: List<ResourceItem> = sortedItems(items)
val sortedItems: List<ResourceItem> = sortedItems(elements)
var start = 0
for (item in sortedItems) {
start = add(item, start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ internal object PseudoMethodBidi : PseudoMethodImpl() {
override fun text(originalText: String): String {
val result = StringBuilder()
var lastSpace = true
var space = true
var escape = false

for (i in originalText.indices) {
Expand All @@ -137,8 +136,7 @@ internal object PseudoMethodBidi : PseudoMethodImpl() {
escape = true
continue
}

space = (!escape && currentChar.isWhitespace()) ||
val space = (!escape && currentChar.isWhitespace()) ||
(escape && (currentChar == 'n' || currentChar == 't'))
if (lastSpace && !space) {
// Word start.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ internal abstract class RepositoryLoader<T : LoadableResourceRepository>(
return repositoryConfiguration
}

repositoryConfiguration = RepositoryConfiguration(repository, folderConfiguration!!)
repositoryConfiguration = RepositoryConfiguration(repository, folderConfiguration)
configCache[folderConfiguration] = repositoryConfiguration
return repositoryConfiguration
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import app.cash.paparazzi.sample.databinding.KeypadBinding
import com.android.resources.ScreenOrientation.LANDSCAPE
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.google.testing.junit.testparameterinjector.TestParameterValuesProvider
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -28,8 +29,8 @@ class TestParameterInjectorTest(
LIGHT_NO_ACTION_BAR("android:Theme.Material.Light.NoActionBar")
}

object AmountProvider : TestParameter.TestParameterValuesProvider {
override fun provideValues(): List<String> = listOf("\$1.00", "\$2.00", "\$5.00", "\$10.00")
object AmountProvider : TestParameterValuesProvider() {
override fun provideValues(context: Context): List<String> = listOf("\$1.00", "\$2.00", "\$5.00", "\$10.00")
}

@get:Rule
Expand Down

0 comments on commit de66f62

Please sign in to comment.