fix some tests for as36

This commit is contained in:
Dmitry Gridin
2020-05-08 19:07:55 +07:00
parent ad09eb5416
commit 50506658c0
22 changed files with 319 additions and 0 deletions
@@ -0,0 +1,45 @@
class A {
fun someOther() = false
private fun formatElement(element: PsiElement): String {
var element = element
element = JetPsiUtil.ascendIfPropertyAccessor(element)
if (element is JetNamedFunction || element is JetProperty) {
val bindingContext =
AnalyzerFacadeWithCache.analyzeFileWithCache(element.getContainingJetFile())
.getBindingContext()
val declarationDescriptor =
bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
if (declarationDescriptor is CallableMemberDescriptor) {
val containingDescriptor = declarationDescriptor.getContainingDeclaration()
if (containingDescriptor is ClassDescriptor) {
return JetBundle.message(
"override.declaration.x.in.y",
DescriptorRenderer.COMPACT.render(declarationDescriptor),
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.render(
containingDescriptor
)
)
}
}
}
assert(element is PsiMethod) { "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found" }
return JetRefactoringUtil.formatPsiMethod(element as PsiMethod, true, false)
}
protected fun getDimensionServiceKey(): String {
return "#org.jetbrains.kotlin.idea.refactoring.safeDelete.KotlinOverridingDialog"
}
fun getSelected(): ArrayList<UsageInfo> {
val result = ArrayList<UsageInfo>()
for (i in 0 until myChecked.length) {
if (myChecked[i]) {
result.add(myOverridingMethods.get(i))
}
}
return result
}
}
@@ -0,0 +1,35 @@
import test.ToBeImportedJava.staticMethod
import test.ToBeImportedJava.TO_BE_IMPORTED_CONST
import test.ToBeImportedJava
import test.ToBeImportedKotlin
import java.util.HashMap
import java.util.ArrayList
class Target {
var listOfPlatformType: List<String> = ArrayList()
var unresolved: UnresolvedInterface<UnresolvedGeneric> =
UnresolvedImplementation() // Should not add import
var hashMapOfNotImported: Map<ToBeImportedJava, ToBeImportedKotlin> = HashMap()
fun acceptKotlinClass(tbi: ToBeImportedKotlin) {
}
fun acceptJavaClass(tbi: ToBeImportedJava) {
}
var ambiguousKotlin: IAmbiguousKotlin =
AmbiguousKotlin() // Should not add import in case of 2 declarations in Kotlin
var ambiguous: IAmbiguous =
Ambiguous() // Should not add import in case of ambiguous declarations in Kotlin and in Java
var ambiguousJava: IAmbiguousJava =
AmbiguousJava() // Should not add import in case of 2 declarations in Java
fun workWithStatics() {
val a = TO_BE_IMPORTED_CONST
staticMethod()
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
val mapIndexedTo: MutableList<Int> = list.asSequence().filter { it > 1 }
.mapIndexedTo(mutableListOf()) { index, i -> i }
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun test() {
val pair: Pair<List<Int>, List<Int>> = listOf(1 to 2, 3 to 4).asSequence().filter { it.first > 1 }
.filter { it.second > 2 }.unzip()
}
@@ -0,0 +1,9 @@
class DefaultValueChain(
val x1: Int,
x2: Int = x1,
val x3: Int = x2,
x4: Int = x3,
val x5: Int = x4
) {
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
// IS_APPLICABLE_2: false
fun getFirstValue() = "value"
fun foo(list: List<String?>): String? {
val value = getFirstValue()
val found: String? =
list.firstOrNull { it != null && !it.startsWith("IMG:") && it.contains(value) }
return found
}
@@ -0,0 +1,21 @@
annotation class Ann1(val i: Int, val j: Int)
@Target(AnnotationTarget.PROPERTY)
annotation class Ann2(val i: Int, val j: Int)
@Target(AnnotationTarget.FIELD)
annotation class Ann3(val i: Int, val j: Int)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
annotation class Ann4(val i: Int, val j: Int)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
annotation class Ann5(val i: Int, val j: Int)
class Test(
@get:Ann1(0, 0) @property:Ann1(1, 11) @Ann2(2, 22) @Ann3(3, 33) @property:Ann4(
4,
44
) @field:Ann5(5, 55) val foo: String = ""
) {
}
@@ -0,0 +1,11 @@
annotation class Annotation1(val a: Int = 0)
annotation class Annotation2(val a: Int = 0)
annotation class Annotation3(val a: Int = 0)
class TestClass(
private @property:Annotation1(42) @field:Annotation2(42) @Annotation1(42) @Annotation3(
42
) val text: String = "LoremIpsum"
) {
}
@@ -0,0 +1,5 @@
// Ann: to be implemented
actual annotation class <caret>Ann actual constructor(
actual val x: Int,
actual val y: String
)
@@ -0,0 +1,10 @@
// "Mark as @Deprecated(..., level = DeprecationLevel.HIDDEN)" "true"
import java.io.File
@Deprecated(
"Is replaced with automatic synthetic extension",
ReplaceWith("name"),
level = DeprecationLevel.HIDDEN
)
val File.<caret>name: String
get() = getName()
@@ -0,0 +1,38 @@
// WITH_RUNTIME
// SUGGESTED_NAMES: triple, getT
// PARAM_TYPES: kotlin.Int
// PARAM_TYPES: kotlin.Int
// PARAM_TYPES: kotlin.Int
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in foo
// PARAM_DESCRIPTOR: var b: kotlin.Int defined in foo
// PARAM_DESCRIPTOR: var c: kotlin.Int defined in foo
// SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
var c: Int = 2
val triple = triple(a, b, c)
b = triple.second
c = triple.third
val t = triple.first
println(b + c)
return t
}
private fun triple(
a: Int,
b: Int,
c: Int
): Triple<Int, Int, Int> {
var b1 = b
var c1 = c
val i = if (a > 0) {
b1 += a
c1 -= b1
b1
} else {
a
}
return Triple(i, b1, c1)
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo(list: List<String>, function: (String) -> Boolean = { it.length > 6 }) = list.filter(
function
)
@@ -0,0 +1,18 @@
internal annotation class Anon(
val stringArray: Array<String>, val intArray: IntArray, // string
val string: String
)
@Anon(string = "a", stringArray = ["a", "b"], intArray = [1, 2])
@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD)
internal annotation class I
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER
)
internal annotation class J
@Target
internal annotation class K
@@ -0,0 +1,8 @@
internal annotation class Anon(
val s: String = "a",
val stringArray: Array<String> = ["a", "b"],
val intArray: IntArray
)
@Anon(intArray = [1, 2])
internal class A
@@ -0,0 +1,6 @@
val constrArgTypes = arrayOf<Class<*>>(
Array<String>::class.java,
String::class.java,
Int::class.java,
Double::class.java
)
@@ -0,0 +1,12 @@
package pack
internal class C @JvmOverloads constructor(
a: Int = 0,
b: Int = 0,
c: Int = 0,
d: Int = 0,
e: Int = 0
) {
constructor(a: Int) : this(a, 0, 0, 0, 1) {}
}
@@ -0,0 +1,14 @@
package pack
internal class C @JvmOverloads constructor(
a: Int = 0,
b: Int = 0,
c: Int = 0,
d: Int = 0,
e: Int = 0
) {
constructor(a1: Int, b1: Int, c1: Int) : this(a1, b1, c1, 0, 0) {}
constructor(b: Byte) : this(b.toInt(), 0, 0, 0, 0) {}
}
@@ -0,0 +1,12 @@
package pack
internal class C @JvmOverloads constructor(
a: Int = 0,
b: Int = 0,
c: Int = 0,
d: Int = 0,
e: Int = 0
) {
constructor(a: Int, b: Int, c: Int) : this(b, a, c, 0, 0) {}
}
@@ -0,0 +1,9 @@
package pack
internal class C @JvmOverloads constructor(
a: Int = 1,
b: Int = 2,
c: Int = 3,
d: Int = 4,
e: Int = 5
)
@@ -0,0 +1,9 @@
package pack
internal class C @JvmOverloads constructor(
a: Int = 1,
b: Int = 2,
c: Int = 3,
d: Int = 4,
e: Int = 5
)
+6
View File
@@ -0,0 +1,6 @@
class AppInfo(
internal var mName: String,
internal var mIcon: String,
internal var mLastUpdateTime: Long
)
@@ -0,0 +1,23 @@
import java.util.*
internal class Iterator {
var mutableMap1: MutableMap<String, String> = HashMap()
var mutableMap2: MutableMap<String, String> = HashMap()
fun testFields() {
mutableMap1.values.add("")
mutableMap2.entries.iterator().remove()
}
fun testFunctionParameters(
immutableCollection: Collection<String>,
mutableList: MutableList<Int>
) {
val it = immutableCollection.iterator()
while (it.hasNext()) {
it.next()
}
mutableList.listIterator().add(2)
}
}