Replace more eager asserts in project with lazy
This commit is contained in:
@@ -17,10 +17,12 @@
|
|||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.backend.common.bridges.*
|
import org.jetbrains.kotlin.backend.common.bridges.Bridge
|
||||||
import kotlin.test.assertEquals
|
import org.jetbrains.kotlin.backend.common.bridges.FunctionHandle
|
||||||
import java.util.HashSet
|
import org.jetbrains.kotlin.backend.common.bridges.generateBridges
|
||||||
import org.jetbrains.kotlin.utils.DFS
|
import org.jetbrains.kotlin.utils.DFS
|
||||||
|
import java.util.HashSet
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class BridgeTest : TestCase() {
|
class BridgeTest : TestCase() {
|
||||||
private class Fun(val text: String) : FunctionHandle {
|
private class Fun(val text: String) : FunctionHandle {
|
||||||
@@ -42,11 +44,12 @@ class BridgeTest : TestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun v(text: String): Fun {
|
private fun v(text: String): Fun {
|
||||||
assert(text.length() == 3, "Function vertex representation should consist of 3 characters: $text")
|
assert(text.length() == 3) { "Function vertex representation should consist of 3 characters: $text" }
|
||||||
assert(text[0] in setOf('-', '+'), "First character should be '-' for abstract functions or '+' for concrete ones: $text")
|
assert(text[0] in setOf('-', '+')) { "First character should be '-' for abstract functions or '+' for concrete ones: $text" }
|
||||||
assert(text[1] in setOf('D', 'F'), "Second character should be 'D' for declarations or 'F' for fake overrides: $text")
|
assert(text[1] in setOf('D', 'F')) { "Second character should be 'D' for declarations or 'F' for fake overrides: $text" }
|
||||||
assert(text[2].isDigit(),
|
assert(text[2].isDigit()) {
|
||||||
"Third character should be a number that represents a signature (same numbers mean the same method signatures)")
|
"Third character should be a number that represents a signature (same numbers mean the same method signatures)"
|
||||||
|
}
|
||||||
return Fun(text)
|
return Fun(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,15 +94,16 @@ class BridgeTest : TestCase() {
|
|||||||
|
|
||||||
for (vertex in vertices) {
|
for (vertex in vertices) {
|
||||||
val directConcreteSuperFunctions = vertex.overriddenFunctions.filter { !it.isAbstract }
|
val directConcreteSuperFunctions = vertex.overriddenFunctions.filter { !it.isAbstract }
|
||||||
assert(directConcreteSuperFunctions.size() <= 1,
|
assert(directConcreteSuperFunctions.size() <= 1) {
|
||||||
"Incorrect test data: function $vertex has more than one direct concrete super-function: ${vertex.overriddenFunctions}\n" +
|
"Incorrect test data: function $vertex has more than one direct concrete super-function: ${vertex.overriddenFunctions}\n" +
|
||||||
"This is not allowed because only classes can contain implementations (concrete functions), and having more than one " +
|
"This is not allowed because only classes can contain implementations (concrete functions), and having more than one " +
|
||||||
"concrete super-function means having more than one superclass, which is prohibited in Kotlin")
|
"concrete super-function means having more than one superclass, which is prohibited in Kotlin"
|
||||||
|
}
|
||||||
|
|
||||||
if (vertex.isDeclaration) continue
|
if (vertex.isDeclaration) continue
|
||||||
|
|
||||||
val superDeclarations = findAllReachableDeclarations(vertex)
|
val superDeclarations = findAllReachableDeclarations(vertex)
|
||||||
assert(!superDeclarations.isEmpty(), "Incorrect test data: fake override vertex $vertex has no super-declarations")
|
assert(superDeclarations.isNotEmpty()) { "Incorrect test data: fake override vertex $vertex has no super-declarations" }
|
||||||
|
|
||||||
// Remove all declarations inherited by other declarations
|
// Remove all declarations inherited by other declarations
|
||||||
val toRemove = HashSet<Fun>()
|
val toRemove = HashSet<Fun>()
|
||||||
@@ -110,20 +114,23 @@ class BridgeTest : TestCase() {
|
|||||||
val concreteDeclarations = superDeclarations.filter { !it.isAbstract }
|
val concreteDeclarations = superDeclarations.filter { !it.isAbstract }
|
||||||
|
|
||||||
if (!vertex.isAbstract) {
|
if (!vertex.isAbstract) {
|
||||||
assert(!concreteDeclarations.isEmpty(),
|
assert(concreteDeclarations.isNotEmpty()) {
|
||||||
"Incorrect test data: concrete fake override vertex $vertex has no concrete super-declarations")
|
"Incorrect test data: concrete fake override vertex $vertex has no concrete super-declarations"
|
||||||
assert(concreteDeclarations.size() == 1,
|
}
|
||||||
"Incorrect test data: concrete fake override vertex $vertex has more than one concrete super-declaration: " +
|
assert(concreteDeclarations.size() == 1) {
|
||||||
"$concreteDeclarations")
|
"Incorrect test data: concrete fake override vertex $vertex has more than one concrete super-declaration: " +
|
||||||
|
"$concreteDeclarations"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTest(function: Fun, expectedBridges: Set<Bridge<Meth>>) {
|
private fun doTest(function: Fun, expectedBridges: Set<Bridge<Meth>>) {
|
||||||
val actualBridges = generateBridges(function, ::Meth)
|
val actualBridges = generateBridges(function, ::Meth)
|
||||||
assert(actualBridges.firstOrNull { it.from == it.to } == null,
|
assert(actualBridges.firstOrNull { it.from == it.to } == null) {
|
||||||
"A bridge invoking itself was generated, which makes no sense, since it will result in StackOverflowError once called" +
|
"A bridge invoking itself was generated, which makes no sense, since it will result in StackOverflowError" +
|
||||||
": $actualBridges")
|
" once called: $actualBridges"
|
||||||
|
}
|
||||||
assertEquals(expectedBridges, actualBridges, "Expected and actual bridge sets differ for function $function")
|
assertEquals(expectedBridges, actualBridges, "Expected and actual bridge sets differ for function $function")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -154,7 +154,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkDescriptor(referencedDescriptor: ClassifierDescriptor, context: DeclarationDescriptor) {
|
private fun checkDescriptor(referencedDescriptor: ClassifierDescriptor, context: DeclarationDescriptor) {
|
||||||
assert(!ErrorUtils.isError(referencedDescriptor), "Error descriptor: $referencedDescriptor")
|
assert(!ErrorUtils.isError(referencedDescriptor)) { "Error descriptor: $referencedDescriptor" }
|
||||||
|
|
||||||
val descriptorName = referencedDescriptor.getName().asString()
|
val descriptorName = referencedDescriptor.getName().asString()
|
||||||
val expectedModuleName = "<${descriptorName.toLowerCase().first().toString()}>"
|
val expectedModuleName = "<${descriptorName.toLowerCase().first().toString()}>"
|
||||||
|
|||||||
+22
-17
@@ -18,28 +18,33 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.*
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
|
||||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
|
||||||
import java.util.Collections
|
|
||||||
import org.jetbrains.kotlin.utils.*
|
|
||||||
import java.util.ArrayList
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.*
|
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||||
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
|
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
||||||
|
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||||
|
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||||
import org.jetbrains.kotlin.load.java.lazy.child
|
import org.jetbrains.kotlin.load.java.lazy.child
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.*
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
|
import org.jetbrains.kotlin.types.JetType
|
||||||
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
import org.jetbrains.kotlin.utils.ifEmpty
|
||||||
|
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||||
|
import org.jetbrains.kotlin.utils.valuesToMap
|
||||||
|
import java.util.ArrayList
|
||||||
|
import java.util.Collections
|
||||||
import java.util.LinkedHashSet
|
import java.util.LinkedHashSet
|
||||||
|
|
||||||
public class LazyJavaClassMemberScope(
|
public class LazyJavaClassMemberScope(
|
||||||
@@ -234,7 +239,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
val (methodsNamedValue, otherMethods) = methods.
|
val (methodsNamedValue, otherMethods) = methods.
|
||||||
partition { it.getName() == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
partition { it.getName() == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
||||||
|
|
||||||
assert(methodsNamedValue.size() <= 1, "There can't be to methods named 'value' in annotation class: " + jClass)
|
assert(methodsNamedValue.size() <= 1) { "There can't be more than one method named 'value' in annotation class: $jClass" }
|
||||||
val methodNamedValue = methodsNamedValue.firstOrNull()
|
val methodNamedValue = methodsNamedValue.firstOrNull()
|
||||||
if (methodNamedValue != null) {
|
if (methodNamedValue != null) {
|
||||||
val parameterNamedValueJavaType = methodNamedValue.getAnnotationMethodReturnJavaType()
|
val parameterNamedValueJavaType = methodNamedValue.getAnnotationMethodReturnJavaType()
|
||||||
@@ -258,8 +263,8 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JavaMethod.getAnnotationMethodReturnJavaType(): JavaType {
|
private fun JavaMethod.getAnnotationMethodReturnJavaType(): JavaType {
|
||||||
assert(getValueParameters().isEmpty(), "Annotation method can't have parameters: " + this)
|
assert(getValueParameters().isEmpty()) { "Annotation method can't have parameters: $this" }
|
||||||
return getReturnType() ?: throw AssertionError("Annotation method has no return type: " + this)
|
return getReturnType() ?: throw AssertionError("Annotation method has no return type: $this")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MutableList<ValueParameterDescriptor>.addAnnotationValueParameter(
|
private fun MutableList<ValueParameterDescriptor>.addAnnotationValueParameter(
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ class LazyJavaTypeResolver(
|
|||||||
is JavaPrimitiveType -> {
|
is JavaPrimitiveType -> {
|
||||||
val canonicalText = javaType.getCanonicalText()
|
val canonicalText = javaType.getCanonicalText()
|
||||||
val jetType = JavaToKotlinClassMap.INSTANCE.mapPrimitiveKotlinClass(canonicalText)
|
val jetType = JavaToKotlinClassMap.INSTANCE.mapPrimitiveKotlinClass(canonicalText)
|
||||||
assert(jetType != null, "Primitive type is not found: " + canonicalText)
|
assert(jetType != null) { "Primitive type is not found: $canonicalText" }
|
||||||
jetType!!
|
jetType!!
|
||||||
}
|
}
|
||||||
is JavaClassifierType ->
|
is JavaClassifierType ->
|
||||||
|
|||||||
+17
-13
@@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.impl
|
package org.jetbrains.kotlin.descriptors.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
|
||||||
import java.util.ArrayList
|
|
||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import java.util.ArrayList
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|
||||||
import kotlin.properties.Delegates
|
|
||||||
import java.util.LinkedHashSet
|
import java.util.LinkedHashSet
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
public class ModuleDescriptorImpl(
|
public class ModuleDescriptorImpl(
|
||||||
moduleName: Name,
|
moduleName: Name,
|
||||||
@@ -46,7 +46,7 @@ public class ModuleDescriptorImpl(
|
|||||||
public fun seal() {
|
public fun seal() {
|
||||||
if (isSealed) return
|
if (isSealed) return
|
||||||
|
|
||||||
assert(this in dependencies, "Module $id is not contained in his own dependencies, this is probably a misconfiguration")
|
assert(this in dependencies) { "Module $id is not contained in his own dependencies, this is probably a misconfiguration" }
|
||||||
isSealed = true
|
isSealed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,9 @@ public class ModuleDescriptorImpl(
|
|||||||
seal()
|
seal()
|
||||||
dependencies.forEach {
|
dependencies.forEach {
|
||||||
dependency ->
|
dependency ->
|
||||||
assert(dependency.isInitialized, "Dependency module ${dependency.id} was not initialized by the time contents of dependent module ${this.id} were queried")
|
assert(dependency.isInitialized) {
|
||||||
|
"Dependency module ${dependency.id} was not initialized by the time contents of dependent module ${this.id} were queried"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CompositePackageFragmentProvider(dependencies.map {
|
CompositePackageFragmentProvider(dependencies.map {
|
||||||
it.packageFragmentProviderForModuleContent!!
|
it.packageFragmentProviderForModuleContent!!
|
||||||
@@ -68,8 +70,10 @@ public class ModuleDescriptorImpl(
|
|||||||
get() = packageFragmentProviderForModuleContent != null
|
get() = packageFragmentProviderForModuleContent != null
|
||||||
|
|
||||||
public fun addDependencyOnModule(dependency: ModuleDescriptorImpl) {
|
public fun addDependencyOnModule(dependency: ModuleDescriptorImpl) {
|
||||||
assert(!isSealed, "Can't modify dependencies of sealed module $id")
|
assert(!isSealed) { "Can't modify dependencies of sealed module $id" }
|
||||||
assert(dependency !in dependencies, "Trying to add dependency on module ${dependency.id} a second time for module ${this.id}, this is probably a misconfiguration")
|
assert(dependency !in dependencies) {
|
||||||
|
"Trying to add dependency on module ${dependency.id} a second time for module ${this.id}, this is probably a misconfiguration"
|
||||||
|
}
|
||||||
dependencies.add(dependency)
|
dependencies.add(dependency)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +85,7 @@ public class ModuleDescriptorImpl(
|
|||||||
* Initialize() and seal() can be called in any order.
|
* Initialize() and seal() can be called in any order.
|
||||||
*/
|
*/
|
||||||
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
||||||
assert(!isInitialized, "Attempt to initialize module $id twice")
|
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
||||||
packageFragmentProviderForModuleContent = providerForModuleContent
|
packageFragmentProviderForModuleContent = providerForModuleContent
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +96,8 @@ public class ModuleDescriptorImpl(
|
|||||||
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
||||||
|
|
||||||
public fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
public fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
||||||
assert(friend != this, "Attempt to make module $id a friend to itself")
|
assert(friend != this) { "Attempt to make module $id a friend to itself" }
|
||||||
assert(!isSealed, "Attempt to add friend module ${friend.id} to sealed module $id")
|
assert(!isSealed) { "Attempt to add friend module ${friend.id} to sealed module $id" }
|
||||||
friendModules.add(friend)
|
friendModules.add(friend)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.eval4j
|
package org.jetbrains.eval4j
|
||||||
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.VarInsnNode
|
|
||||||
import org.jetbrains.org.objectweb.asm.util.Printer
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.TryCatchBlockNode
|
|
||||||
import java.util.ArrayList
|
|
||||||
import org.jetbrains.eval4j.ExceptionThrown.ExceptionKind
|
import org.jetbrains.eval4j.ExceptionThrown.ExceptionKind
|
||||||
|
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
import org.jetbrains.org.objectweb.asm.tree.*
|
||||||
|
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||||
|
import org.jetbrains.org.objectweb.asm.util.Printer
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
public trait InterpreterResult {
|
public trait InterpreterResult {
|
||||||
override fun toString(): String
|
override fun toString(): String
|
||||||
@@ -179,7 +175,7 @@ public fun interpreterLoop(
|
|||||||
return ValueReturned(coerced)
|
return ValueReturned(coerced)
|
||||||
}
|
}
|
||||||
if (value.asmType != expectedType) {
|
if (value.asmType != expectedType) {
|
||||||
assert(insnOpcode == IRETURN, "Only ints should be coerced: " + Printer.OPCODES[insnOpcode])
|
assert(insnOpcode == IRETURN) { "Only ints should be coerced: ${Printer.OPCODES[insnOpcode]}" }
|
||||||
|
|
||||||
val coerced = when (expectedType.getSort()) {
|
val coerced = when (expectedType.getSort()) {
|
||||||
Type.BOOLEAN -> boolean(value.boolean)
|
Type.BOOLEAN -> boolean(value.boolean)
|
||||||
|
|||||||
@@ -16,13 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.eval4j.jdi
|
package org.jetbrains.eval4j.jdi
|
||||||
|
|
||||||
import org.jetbrains.eval4j.*
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
|
||||||
import com.sun.jdi
|
import com.sun.jdi
|
||||||
import com.sun.jdi.ClassNotLoadedException
|
import com.sun.jdi.ClassNotLoadedException
|
||||||
import com.sun.tools.jdi.ReferenceTypeImpl
|
|
||||||
import com.sun.jdi.ObjectReference
|
|
||||||
import com.sun.jdi.Method
|
import com.sun.jdi.Method
|
||||||
|
import com.sun.jdi.ObjectReference
|
||||||
|
import org.jetbrains.eval4j.*
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
val CLASS = Type.getType(javaClass<Class<*>>())
|
val CLASS = Type.getType(javaClass<Class<*>>())
|
||||||
val BOOTSTRAP_CLASS_DESCRIPTORS = setOf("Ljava/lang/String;", "Ljava/lang/ClassLoader;", "Ljava/lang/Class;")
|
val BOOTSTRAP_CLASS_DESCRIPTORS = setOf("Ljava/lang/String;", "Ljava/lang/ClassLoader;", "Ljava/lang/Class;")
|
||||||
@@ -88,7 +87,9 @@ public class JDIEval(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isInstanceOf(value: Value, targetType: Type): Boolean {
|
override fun isInstanceOf(value: Value, targetType: Type): Boolean {
|
||||||
assert(targetType.getSort() == Type.OBJECT || targetType.getSort() == Type.ARRAY, "Can't check isInstanceOf() for non-object type $targetType")
|
assert(targetType.getSort() == Type.OBJECT || targetType.getSort() == Type.ARRAY) {
|
||||||
|
"Can't check isInstanceOf() for non-object type $targetType"
|
||||||
|
}
|
||||||
|
|
||||||
val _class = loadClass(targetType)
|
val _class = loadClass(targetType)
|
||||||
return invokeMethod(
|
return invokeMethod(
|
||||||
@@ -112,7 +113,7 @@ public class JDIEval(
|
|||||||
|
|
||||||
private val Type.arrayElementType: Type
|
private val Type.arrayElementType: Type
|
||||||
get(): Type {
|
get(): Type {
|
||||||
assert(getSort() == Type.ARRAY, "Not an array type: $this")
|
assert(getSort() == Type.ARRAY) { "Not an array type: $this" }
|
||||||
return Type.getType(getDescriptor().substring(1))
|
return Type.getType(getDescriptor().substring(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.refactoring.fqName
|
package org.jetbrains.kotlin.idea.refactoring.fqName
|
||||||
|
|
||||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import com.intellij.psi.PsiPackage
|
|
||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiMember
|
import com.intellij.psi.PsiMember
|
||||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
import com.intellij.psi.PsiPackage
|
||||||
|
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.isOneSegmentFQN
|
import org.jetbrains.kotlin.name.isOneSegmentFQN
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
|
||||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetElement
|
|
||||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetUserType
|
|
||||||
import org.jetbrains.kotlin.psi
|
import org.jetbrains.kotlin.psi
|
||||||
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +51,7 @@ public fun PsiElement.getKotlinFqName(): FqName? {
|
|||||||
* Note that FqName may not be empty
|
* Note that FqName may not be empty
|
||||||
*/
|
*/
|
||||||
fun JetSimpleNameExpression.changeQualifiedName(fqName: FqName): JetElement {
|
fun JetSimpleNameExpression.changeQualifiedName(fqName: FqName): JetElement {
|
||||||
assert (!fqName.isRoot(), "Can't set empty FqName for element $this")
|
assert(!fqName.isRoot()) { "Can't set empty FqName for element $this" }
|
||||||
|
|
||||||
val shortName = fqName.shortName().asString()
|
val shortName = fqName.shortName().asString()
|
||||||
val psiFactory = psi.JetPsiFactory(this)
|
val psiFactory = psi.JetPsiFactory(this)
|
||||||
|
|||||||
+3
-2
@@ -70,8 +70,9 @@ public class IfThenToElvisIntention : JetSelfTargetingOffsetIndependentIntention
|
|||||||
val resultingExprString = "${left.getText()} ?: ${right.getText()}"
|
val resultingExprString = "${left.getText()} ?: ${right.getText()}"
|
||||||
val resultingExpression = JetPsiUtil.deparenthesize(element.replace(resultingExprString) as? JetExpression)
|
val resultingExpression = JetPsiUtil.deparenthesize(element.replace(resultingExprString) as? JetExpression)
|
||||||
|
|
||||||
assert(resultingExpression is JetBinaryExpression,
|
assert(resultingExpression is JetBinaryExpression) {
|
||||||
"Unexpected expression type: ${resultingExpression?.javaClass}, expected JetBinaryExpression, element = '${element.getText()}'")
|
"Unexpected expression type: ${resultingExpression?.javaClass}, expected JetBinaryExpression, element = '${element.getText()}'"
|
||||||
|
}
|
||||||
|
|
||||||
return resultingExpression as JetBinaryExpression
|
return resultingExpression as JetBinaryExpression
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -496,12 +496,12 @@ private class MutableParameter(
|
|||||||
var refCount: Int = 0
|
var refCount: Int = 0
|
||||||
|
|
||||||
fun addDefaultType(jetType: JetType) {
|
fun addDefaultType(jetType: JetType) {
|
||||||
assert(writable, "Can't add type to non-writable parameter $currentName")
|
assert(writable) { "Can't add type to non-writable parameter $currentName" }
|
||||||
defaultTypes.add(jetType)
|
defaultTypes.add(jetType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTypePredicate(predicate: TypePredicate) {
|
fun addTypePredicate(predicate: TypePredicate) {
|
||||||
assert(writable, "Can't add type predicate to non-writable parameter $currentName")
|
assert(writable) { "Can't add type predicate to non-writable parameter $currentName" }
|
||||||
typePredicates.add(predicate)
|
typePredicates.add(predicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -49,7 +49,10 @@ import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange
|
|||||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier
|
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier
|
||||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange
|
import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getValueParameterList
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getValueParameters
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
|
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
@@ -250,7 +253,7 @@ public open class KotlinIntroduceParameterHandler(
|
|||||||
if (parameterList == null) {
|
if (parameterList == null) {
|
||||||
val klass = targetParent as? JetClass
|
val klass = targetParent as? JetClass
|
||||||
val anchor = klass?.getTypeParameterList() ?: klass?.getNameIdentifier()
|
val anchor = klass?.getTypeParameterList() ?: klass?.getNameIdentifier()
|
||||||
assert(anchor != null, "Invalid declaration: ${targetParent.getElementTextWithContext()}")
|
assert(anchor != null) { "Invalid declaration: ${targetParent.getElementTextWithContext()}" }
|
||||||
|
|
||||||
val constructor = targetParent.addAfter(psiFactory.createPrimaryConstructor(), anchor) as JetPrimaryConstructor
|
val constructor = targetParent.addAfter(psiFactory.createPrimaryConstructor(), anchor) as JetPrimaryConstructor
|
||||||
constructor.getValueParameterList()!!
|
constructor.getValueParameterList()!!
|
||||||
|
|||||||
+23
-16
@@ -16,22 +16,29 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.refactoring.introduce.introduceProperty
|
package org.jetbrains.kotlin.idea.refactoring.introduce.introduceProperty
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.*
|
import com.intellij.codeInsight.template.TemplateBuilderImpl
|
||||||
import org.jetbrains.kotlin.psi.*
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.project.*
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.*
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.types.*
|
import com.intellij.openapi.util.Pass
|
||||||
import javax.swing.*
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
|
import com.intellij.ui.NonFocusableCheckBox
|
||||||
|
import com.intellij.ui.PopupMenuListenerAdapter
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.ExtractionResult
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.ExtractionTarget
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.generateDeclaration
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.processDuplicatesSilently
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinInplaceVariableIntroducer
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinInplaceVariableIntroducer.ControlWrapper
|
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinInplaceVariableIntroducer.ControlWrapper
|
||||||
import com.intellij.openapi.util.*
|
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||||
import com.intellij.ui.*
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
import javax.swing.event.*
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import com.intellij.openapi.application.*
|
import org.jetbrains.kotlin.psi.JetProperty
|
||||||
import com.intellij.psi.*
|
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||||
import com.intellij.codeInsight.template.*
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.idea.intentions.*
|
import javax.swing.*
|
||||||
|
import javax.swing.event.PopupMenuEvent
|
||||||
|
|
||||||
public class KotlinInplacePropertyIntroducer(
|
public class KotlinInplacePropertyIntroducer(
|
||||||
property: JetProperty,
|
property: JetProperty,
|
||||||
@@ -46,7 +53,7 @@ public class KotlinInplacePropertyIntroducer(
|
|||||||
property, editor, project, title, JetExpression.EMPTY_ARRAY, null, false, property, false, doNotChangeVar, exprType, false
|
property, editor, project, title, JetExpression.EMPTY_ARRAY, null, false, property, false, doNotChangeVar, exprType, false
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
assert(availableTargets.isNotEmpty(), "No targets available: ${property.getElementTextWithContext()}")
|
assert(availableTargets.isNotEmpty()) { "No targets available: ${property.getElementTextWithContext()}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
private var extractionResult = extractionResult
|
private var extractionResult = extractionResult
|
||||||
|
|||||||
+40
-49
@@ -16,61 +16,52 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.refactoring.move.moveTopLevelDeclarations
|
package org.jetbrains.kotlin.idea.refactoring.move.moveTopLevelDeclarations
|
||||||
|
|
||||||
import com.intellij.refactoring.BaseRefactoringProcessor
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.usageView.UsageInfo
|
import com.intellij.openapi.util.Ref
|
||||||
import com.intellij.usageView.UsageViewDescriptor
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.search.searches.ReferencesSearch
|
||||||
|
import com.intellij.refactoring.BaseRefactoringProcessor
|
||||||
import com.intellij.refactoring.move.MoveCallback
|
import com.intellij.refactoring.move.MoveCallback
|
||||||
import com.intellij.refactoring.move.MoveMultipleElementsViewDescriptor
|
import com.intellij.refactoring.move.MoveMultipleElementsViewDescriptor
|
||||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesUtil
|
|
||||||
import com.intellij.usageView.UsageViewUtil
|
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.refactoring.util.NonCodeUsageInfo
|
|
||||||
import com.intellij.util.IncorrectOperationException
|
|
||||||
import com.intellij.refactoring.util.RefactoringUIUtil
|
|
||||||
import org.jetbrains.kotlin.utils.keysToMap
|
|
||||||
import com.intellij.refactoring.rename.RenameUtil
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
|
||||||
import com.intellij.psi.PsiDirectory
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getPackage
|
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.PackageNameInfo
|
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.createKotlinFile
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.getFileNameAfterMove
|
|
||||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
|
||||||
import org.jetbrains.kotlin.asJava.toLightElements
|
|
||||||
import java.util.HashMap
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.HashSet
|
|
||||||
import com.intellij.psi.PsiReference
|
|
||||||
import com.intellij.psi.search.searches.ReferencesSearch
|
|
||||||
import com.intellij.refactoring.util.MoveRenameUsageInfo
|
|
||||||
import com.intellij.refactoring.util.TextOccurrencesUtil
|
|
||||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassHandler
|
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassHandler
|
||||||
|
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesUtil
|
||||||
|
import com.intellij.refactoring.rename.RenameUtil
|
||||||
|
import com.intellij.refactoring.util.MoveRenameUsageInfo
|
||||||
|
import com.intellij.refactoring.util.NonCodeUsageInfo
|
||||||
|
import com.intellij.refactoring.util.RefactoringUIUtil
|
||||||
|
import com.intellij.refactoring.util.TextOccurrencesUtil
|
||||||
|
import com.intellij.usageView.UsageInfo
|
||||||
|
import com.intellij.usageView.UsageViewDescriptor
|
||||||
|
import com.intellij.usageView.UsageViewUtil
|
||||||
|
import com.intellij.util.IncorrectOperationException
|
||||||
|
import com.intellij.util.VisibilityUtil
|
||||||
import com.intellij.util.containers.MultiMap
|
import com.intellij.util.containers.MultiMap
|
||||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isPrivate
|
import org.jetbrains.kotlin.asJava.toLightElements
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.getUsageContext
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isInsideOf
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||||
import org.jetbrains.kotlin.psi.JetModifierListOwner
|
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver
|
||||||
import com.intellij.psi.PsiModifierListOwner
|
import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
||||||
import com.intellij.psi.PsiModifier
|
import org.jetbrains.kotlin.idea.core.refactoring.createKotlinFile
|
||||||
import com.intellij.util.VisibilityUtil
|
import org.jetbrains.kotlin.idea.core.refactoring.getUsageContext
|
||||||
import com.intellij.openapi.util.Ref
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
||||||
import org.jetbrains.kotlin.idea.search.projectScope
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.getInternalReferencesToUpdateOnPackageNameChange
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.createMoveUsageInfoIfPossible
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.postProcessMoveUsages
|
|
||||||
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference.ShorteningMode
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.MoveRenameUsageInfoForExtension
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.move.*
|
||||||
|
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference.ShorteningMode
|
||||||
|
import org.jetbrains.kotlin.idea.search.projectScope
|
||||||
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
|
import org.jetbrains.kotlin.psi.JetModifierListOwner
|
||||||
|
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getPackage
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isInsideOf
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isPrivate
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.utils.keysToMap
|
||||||
|
import java.util.ArrayList
|
||||||
|
import java.util.HashMap
|
||||||
|
import java.util.HashSet
|
||||||
|
|
||||||
trait Mover: (originalElement: JetNamedDeclaration, targetFile: JetFile) -> JetNamedDeclaration {
|
trait Mover: (originalElement: JetNamedDeclaration, targetFile: JetFile) -> JetNamedDeclaration {
|
||||||
object Default: Mover {
|
object Default: Mover {
|
||||||
@@ -240,7 +231,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(
|
|||||||
usagesToProcessAfterMove: MutableList<UsageInfo>
|
usagesToProcessAfterMove: MutableList<UsageInfo>
|
||||||
): JetNamedDeclaration? {
|
): JetNamedDeclaration? {
|
||||||
val file = declaration.getContainingFile() as? JetFile
|
val file = declaration.getContainingFile() as? JetFile
|
||||||
assert (file != null, "${declaration.javaClass}: ${declaration.getText()}")
|
assert(file != null) { "${declaration.javaClass}: ${declaration.getText()}" }
|
||||||
|
|
||||||
val targetPsi = moveTarget.getOrCreateTargetPsi(declaration)
|
val targetPsi = moveTarget.getOrCreateTargetPsi(declaration)
|
||||||
val targetFile =
|
val targetFile =
|
||||||
@@ -250,7 +241,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(
|
|||||||
}
|
}
|
||||||
else targetPsi
|
else targetPsi
|
||||||
|
|
||||||
assert(targetFile is JetFile, "Couldn't create Koltin file for: ${declaration.javaClass}: ${declaration.getText()}")
|
assert(targetFile is JetFile) { "Couldn't create Kotlin file for: ${declaration.javaClass}: ${declaration.getText()}" }
|
||||||
targetFile as JetFile
|
targetFile as JetFile
|
||||||
|
|
||||||
if (options.updateInternalReferences) {
|
if (options.updateInternalReferences) {
|
||||||
|
|||||||
+14
-13
@@ -16,21 +16,21 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.js.translate.callTranslator
|
package org.jetbrains.kotlin.js.translate.callTranslator
|
||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
|
|
||||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
|
||||||
import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator
|
|
||||||
import org.jetbrains.kotlin.js.translate.general.Translation
|
import org.jetbrains.kotlin.js.translate.general.Translation
|
||||||
|
import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||||
|
import org.jetbrains.kotlin.psi.Call.CallType
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.CallResolverUtil
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.NO_EXPLICIT_RECEIVER
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallResolverUtil
|
|
||||||
import org.jetbrains.kotlin.psi.Call.CallType
|
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
object CallTranslator {
|
object CallTranslator {
|
||||||
@@ -120,7 +120,7 @@ fun computeExplicitReceiversForInvoke(
|
|||||||
explicitReceivers: ExplicitReceivers
|
explicitReceivers: ExplicitReceivers
|
||||||
): ExplicitReceivers {
|
): ExplicitReceivers {
|
||||||
val callElement = resolvedCall.getCall().getCallElement()
|
val callElement = resolvedCall.getCall().getCallElement()
|
||||||
assert(explicitReceivers.extensionReceiver == null, "'Invoke' call must have one receiver: $callElement")
|
assert(explicitReceivers.extensionReceiver == null) { "'Invoke' call must have one receiver: $callElement" }
|
||||||
|
|
||||||
fun translateReceiverAsExpression(receiver: ReceiverValue): JsExpression? =
|
fun translateReceiverAsExpression(receiver: ReceiverValue): JsExpression? =
|
||||||
(receiver as? ExpressionReceiver)?.let { Translation.translateAsExpression(it.getExpression(), context) }
|
(receiver as? ExpressionReceiver)?.let { Translation.translateAsExpression(it.getExpression(), context) }
|
||||||
@@ -132,9 +132,10 @@ fun computeExplicitReceiversForInvoke(
|
|||||||
assertNotNull(explicitReceivers.extensionOrDispatchReceiver, "No explicit receiver for 'invoke' resolved call with both receivers: $callElement")
|
assertNotNull(explicitReceivers.extensionOrDispatchReceiver, "No explicit receiver for 'invoke' resolved call with both receivers: $callElement")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(explicitReceivers.extensionOrDispatchReceiver == null,
|
assert(explicitReceivers.extensionOrDispatchReceiver == null) {
|
||||||
"Non trivial explicit receiver ${explicitReceivers.extensionOrDispatchReceiver}\n for 'invoke' resolved call: $callElement\n"
|
"Non trivial explicit receiver ${explicitReceivers.extensionOrDispatchReceiver}\n for 'invoke' resolved call: $callElement\n" +
|
||||||
+ "Dispatch receiver: $dispatchReceiver Extension receiver: $extensionReceiver")
|
"Dispatch receiver: $dispatchReceiver Extension receiver: $extensionReceiver"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val dispatchReceiverExpression = translateReceiverAsExpression(dispatchReceiver)
|
val dispatchReceiverExpression = translateReceiverAsExpression(dispatchReceiver)
|
||||||
|
|||||||
+15
-7
@@ -18,21 +18,29 @@ package org.jetbrains.kotlin.js.translate.expression.loopTranslator
|
|||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*
|
import com.google.dart.compiler.backend.js.ast.*
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.psi.*
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType
|
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
|
||||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator
|
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator
|
||||||
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable
|
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||||
import org.jetbrains.kotlin.js.translate.expression.MultiDeclarationTranslator
|
import org.jetbrains.kotlin.js.translate.expression.MultiDeclarationTranslator
|
||||||
import org.jetbrains.kotlin.js.translate.general.Translation
|
import org.jetbrains.kotlin.js.translate.general.Translation
|
||||||
import org.jetbrains.kotlin.js.translate.intrinsic.functions.factories.CompositeFIF
|
import org.jetbrains.kotlin.js.translate.intrinsic.functions.factories.CompositeFIF
|
||||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.*
|
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getHasNextCallable
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getIteratorFunction
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getNextFunction
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getTypeForExpression
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.*
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.*
|
||||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.*
|
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getLoopBody
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getLoopParameter
|
||||||
|
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getLoopRange
|
||||||
import org.jetbrains.kotlin.js.translate.utils.TemporariesUtils.temporariesInitialization
|
import org.jetbrains.kotlin.js.translate.utils.TemporariesUtils.temporariesInitialization
|
||||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
||||||
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
|
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetForExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetMultiDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.JetWhileExpressionBase
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
|
|
||||||
public fun createWhile(doWhile: Boolean, expression: JetWhileExpressionBase, context: TranslationContext): JsNode {
|
public fun createWhile(doWhile: Boolean, expression: JetWhileExpressionBase, context: TranslationContext): JsNode {
|
||||||
val conditionExpression = expression.getCondition() ?:
|
val conditionExpression = expression.getCondition() ?:
|
||||||
@@ -113,7 +121,7 @@ public fun translateForExpression(expression: JetForExpression, context: Transla
|
|||||||
if (loopParameter != null) {
|
if (loopParameter != null) {
|
||||||
return context.getNameForElement(loopParameter)
|
return context.getNameForElement(loopParameter)
|
||||||
}
|
}
|
||||||
assert(multiParameter != null, "If loopParameter is null, multi parameter must be not null ${expression.getText()}")
|
assert(multiParameter != null) { "If loopParameter is null, multi parameter must be not null ${expression.getText()}" }
|
||||||
return context.scope().declareTemporary()
|
return context.scope().declareTemporary()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ object CallableReferenceTranslator {
|
|||||||
|
|
||||||
private fun translateForTopLevelProperty(descriptor: PropertyDescriptor, context: TranslationContext): JsExpression {
|
private fun translateForTopLevelProperty(descriptor: PropertyDescriptor, context: TranslationContext): JsExpression {
|
||||||
val packageDescriptor = JsDescriptorUtils.getContainingDeclaration(descriptor)
|
val packageDescriptor = JsDescriptorUtils.getContainingDeclaration(descriptor)
|
||||||
assert(packageDescriptor is PackageFragmentDescriptor, "Expected PackageFragmentDescriptor: ${packageDescriptor}")
|
assert(packageDescriptor is PackageFragmentDescriptor) { "Expected PackageFragmentDescriptor: $packageDescriptor" }
|
||||||
|
|
||||||
val jsPackageNameRef = context.getQualifiedReference(packageDescriptor)
|
val jsPackageNameRef = context.getQualifiedReference(packageDescriptor)
|
||||||
val jsPropertyName = context.getNameForDescriptor(descriptor)
|
val jsPropertyName = context.getNameForDescriptor(descriptor)
|
||||||
|
|||||||
Reference in New Issue
Block a user