Moves and renames

This commit is contained in:
Valentin Kipyatkov
2015-01-28 21:12:31 +03:00
parent a32029f1fc
commit fb7cd623ae
2 changed files with 19 additions and 17 deletions
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
import org.jetbrains.kotlin.idea.util.IterableTypesDetector
import org.jetbrains.kotlin.idea.util.nullability
import org.jetbrains.kotlin.idea.util.TypeNullability
import org.jetbrains.kotlin.idea.util.SmartCastCalculator
trait InheritanceItemsSearcher {
fun search(nameFilter: (String) -> Boolean, consumer: (LookupElement) -> Unit)
@@ -126,7 +127,7 @@ class SmartCompletion(
else
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)
@@ -374,7 +375,7 @@ class SmartCompletion(
?.getParent() as? JetForExpression ?: 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)
@@ -14,27 +14,28 @@
* 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.types.JetType
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.DataFlowValue
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import java.util.HashMap
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import com.google.common.collect.SetMultimap
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 org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.idea.util.makeNotNullable
import com.intellij.openapi.util.Pair
class TypesWithSmartCasts(val bindingContext: BindingContext) {
public fun calculate(expression: JetExpression, receiver: JetExpression?): (VariableDescriptor) -> Collection<JetType> {
val dataFlowInfo = bindingContext.getDataFlowInfo(expression)
class SmartCastCalculator(val bindingContext: BindingContext) {
public fun calculate(position: JetExpression, receiver: JetExpression?): (VariableDescriptor) -> Collection<JetType> {
val dataFlowInfo = bindingContext.getDataFlowInfo(position)
val (variableToTypes, notNullVariables) = processDataFlowInfo(dataFlowInfo, receiver)
fun typesOf(descriptor: VariableDescriptor): Collection<JetType> {
@@ -65,7 +66,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
val receiverId = DataFlowValueFactory.createDataFlowValue(receiver, receiverType, bindingContext).getId()
dataFlowValueToVariable = {(value) ->
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 {
@@ -73,7 +74,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
val id = value.getId()
when {
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
}
}
@@ -96,4 +97,4 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
return ProcessDataFlowInfoResult(variableToType, notNullVariables)
}
}
}