Moves and renames
This commit is contained in:
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
|||||||
import org.jetbrains.kotlin.idea.util.IterableTypesDetector
|
import org.jetbrains.kotlin.idea.util.IterableTypesDetector
|
||||||
import org.jetbrains.kotlin.idea.util.nullability
|
import org.jetbrains.kotlin.idea.util.nullability
|
||||||
import org.jetbrains.kotlin.idea.util.TypeNullability
|
import org.jetbrains.kotlin.idea.util.TypeNullability
|
||||||
|
import org.jetbrains.kotlin.idea.util.SmartCastCalculator
|
||||||
|
|
||||||
trait InheritanceItemsSearcher {
|
trait InheritanceItemsSearcher {
|
||||||
fun search(nameFilter: (String) -> Boolean, consumer: (LookupElement) -> Unit)
|
fun search(nameFilter: (String) -> Boolean, consumer: (LookupElement) -> Unit)
|
||||||
@@ -126,7 +127,7 @@ class SmartCompletion(
|
|||||||
else
|
else
|
||||||
filteredExpectedInfos
|
filteredExpectedInfos
|
||||||
|
|
||||||
val smartCastTypes: (VariableDescriptor) -> Collection<JetType> = TypesWithSmartCasts(bindingContext).calculate(expressionWithType, receiver)
|
val smartCastTypes: (VariableDescriptor) -> Collection<JetType> = SmartCastCalculator(bindingContext).calculate(expressionWithType, receiver)
|
||||||
|
|
||||||
val itemsToSkip = calcItemsToSkip(expressionWithType)
|
val itemsToSkip = calcItemsToSkip(expressionWithType)
|
||||||
|
|
||||||
@@ -374,7 +375,7 @@ class SmartCompletion(
|
|||||||
?.getParent() as? JetForExpression ?: return null
|
?.getParent() as? JetForExpression ?: return null
|
||||||
if (expressionWithType != forExpression.getLoopRange()) return null
|
if (expressionWithType != forExpression.getLoopRange()) return null
|
||||||
|
|
||||||
val smartCastTypes: (VariableDescriptor) -> Collection<JetType> = TypesWithSmartCasts(bindingContext).calculate(expressionWithType, receiver)
|
val smartCastTypes: (VariableDescriptor) -> Collection<JetType> = SmartCastCalculator(bindingContext).calculate(expressionWithType, receiver)
|
||||||
|
|
||||||
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)
|
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)
|
||||||
|
|
||||||
|
|||||||
+16
-15
@@ -14,27 +14,28 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.completion.smart
|
package org.jetbrains.kotlin.idea.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||||
|
import org.jetbrains.kotlin.idea.completion.smart.toList
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
import org.jetbrains.kotlin.types.JetType
|
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import java.util.Collections
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||||
import java.util.HashMap
|
|
||||||
import com.google.common.collect.SetMultimap
|
import com.google.common.collect.SetMultimap
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability
|
||||||
|
import java.util.Collections
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||||
|
import java.util.HashMap
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import com.intellij.openapi.util.Pair
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
|
||||||
import org.jetbrains.kotlin.idea.util.makeNotNullable
|
|
||||||
|
|
||||||
class TypesWithSmartCasts(val bindingContext: BindingContext) {
|
class SmartCastCalculator(val bindingContext: BindingContext) {
|
||||||
public fun calculate(expression: JetExpression, receiver: JetExpression?): (VariableDescriptor) -> Collection<JetType> {
|
public fun calculate(position: JetExpression, receiver: JetExpression?): (VariableDescriptor) -> Collection<JetType> {
|
||||||
val dataFlowInfo = bindingContext.getDataFlowInfo(expression)
|
val dataFlowInfo = bindingContext.getDataFlowInfo(position)
|
||||||
val (variableToTypes, notNullVariables) = processDataFlowInfo(dataFlowInfo, receiver)
|
val (variableToTypes, notNullVariables) = processDataFlowInfo(dataFlowInfo, receiver)
|
||||||
|
|
||||||
fun typesOf(descriptor: VariableDescriptor): Collection<JetType> {
|
fun typesOf(descriptor: VariableDescriptor): Collection<JetType> {
|
||||||
@@ -65,7 +66,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
|
|||||||
val receiverId = DataFlowValueFactory.createDataFlowValue(receiver, receiverType, bindingContext).getId()
|
val receiverId = DataFlowValueFactory.createDataFlowValue(receiver, receiverType, bindingContext).getId()
|
||||||
dataFlowValueToVariable = {(value) ->
|
dataFlowValueToVariable = {(value) ->
|
||||||
val id = value.getId()
|
val id = value.getId()
|
||||||
if (id is com.intellij.openapi.util.Pair<*, *> && id.first == receiverId) id.second as? VariableDescriptor else null
|
if (id is Pair<*, *> && id.first == receiverId) id.second as? VariableDescriptor else null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -73,7 +74,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
|
|||||||
val id = value.getId()
|
val id = value.getId()
|
||||||
when {
|
when {
|
||||||
id is VariableDescriptor -> id
|
id is VariableDescriptor -> id
|
||||||
id is com.intellij.openapi.util.Pair<*, *> && id.first is ThisReceiver -> id.second as? VariableDescriptor
|
id is Pair<*, *> && id.first is ThisReceiver -> id.second as? VariableDescriptor
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,4 +97,4 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
|
|||||||
|
|
||||||
return ProcessDataFlowInfoResult(variableToType, notNullVariables)
|
return ProcessDataFlowInfoResult(variableToType, notNullVariables)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user