Compare commits

...

1 Commits

Author SHA1 Message Date
Ilya Gorbunov
550d963057 Rename check to satisfying.
#KT-7858
2016-02-01 18:37:55 +03:00
34 changed files with 91 additions and 99 deletions

View File

@@ -21,7 +21,7 @@ import net.rubygrapefruit.platform.ProcessLauncher
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.io.File
import java.io.OutputStream
import java.io.PrintStream
@@ -61,9 +61,9 @@ object KotlinCompilerClient {
val flagFile = System.getProperty(COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY)
?.let { it.trimQuotes() }
?.check { !it.isBlank() }
?.satisfying { !it.isBlank() }
?.let { File(it) }
?.check { it.exists() }
?.satisfying { it.exists() }
?: newFlagFile()
return connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, reportingTargets, autostart)
}
@@ -262,7 +262,7 @@ object KotlinCompilerClient {
.sortedWith(compareBy(DaemonJVMOptionsMemoryComparator().reversed(), { it.second.get() }))
val optsCopy = daemonJVMOptions.copy()
// if required options fit into fattest running daemon - return the daemon and required options with memory params set to actual ones in the daemon
return aliveWithOpts.firstOrNull()?.check { daemonJVMOptions memorywiseFitsInto it.second.get() }?.let {
return aliveWithOpts.firstOrNull()?.satisfying { daemonJVMOptions memorywiseFitsInto it.second.get() }?.let {
Pair(it.first, optsCopy.updateMemoryUpperBounds(it.second.get()))
}
// else combine all options from running daemon to get fattest option for a new daemon to run

View File

@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.io.BufferedOutputStream
import java.io.File
import java.io.PrintStream
@@ -347,7 +347,7 @@ class CompileServiceImpl(
if (fattestOpts memorywiseFitsInto daemonJVMOptions && !(daemonJVMOptions memorywiseFitsInto fattestOpts)) {
// all others are smaller that me, take overs' clients and shut them down
aliveWithOpts.forEach {
it.first.getClients().check { it.isGood }?.let {
it.first.getClients().satisfying { it.isGood }?.let {
it.get().forEach { registerClient(it) }
}
it.first.scheduleShutdown(true)
@@ -357,7 +357,7 @@ class CompileServiceImpl(
// there is at least one bigger, handover my clients to it and shutdown
scheduleShutdown(true)
aliveWithOpts.first().first.let { fattest ->
getClients().check { it.isGood }?.let {
getClients().satisfying { it.isGood }?.let {
it.get().forEach { fattest.registerClient(it) }
}
}

View File

@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.replace
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
// If type 'samType' contains no projection, then it's non-projection parametrization is 'samType' itself
// Else each projection type argument 'out/in A_i' (but star projections) is replaced with it's bound 'A_i'
@@ -43,7 +43,7 @@ internal fun nonProjectionParametrization(samType: KotlinType): KotlinType? {
projection.projectionKind == Variance.INVARIANT -> projection
projection.isStarProjection ->
parameter.upperBounds.first().check {
parameter.upperBounds.first().satisfying {
t -> !t.contains { it.constructor.declarationDescriptor in parametersSet }
}?.asTypeProjection() ?: return@nonProjectionParametrization null

View File

@@ -26,7 +26,7 @@ import com.intellij.psi.tree.IElementType
import com.intellij.testFramework.LightVirtualFile
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
abstract class KtCodeFragment(
@@ -146,7 +146,7 @@ abstract class KtCodeFragment(
private fun initImports(imports: String?) {
if (imports != null && !imports.isEmpty()) {
this.imports.addAll(imports.split(IMPORT_SEPARATOR).map { it.check { it.startsWith("import ") } ?: "import $it" })
this.imports.addAll(imports.split(IMPORT_SEPARATOR).map { it.satisfying { it.startsWith("import ") } ?: "import $it" })
}
}

View File

@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator) {
@@ -90,7 +90,7 @@ class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator
val qualifier = resolveToPackageOrClass(
qualifierPartList.subList(0, qualifierPartList.size - 1), module,
trace, scope.ownerDescriptor, scope.check { !userType.startWithPackage }, position = QualifierPosition.TYPE
trace, scope.ownerDescriptor, scope.satisfying { !userType.startWithPackage }, position = QualifierPosition.TYPE
) ?: return TypeQualifierResolutionResult(qualifierPartList, null)
val lastPart = qualifierPartList.last()
@@ -194,7 +194,7 @@ class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator
}
val importedDescriptors = candidates.filter { isVisible(it, packageFragmentForVisibilityCheck, position = QualifierPosition.IMPORT) }.
check { it.isNotEmpty() } ?: candidates
satisfying { it.isNotEmpty() } ?: candidates
return SingleImportScope(aliasName, importedDescriptors)
}
@@ -410,14 +410,14 @@ class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator
val qualifierDescriptor = when {
receiver is PackageQualifier -> {
val childPackageFQN = receiver.packageView.fqName.child(name)
receiver.packageView.module.getPackage(childPackageFQN).check { !it.isEmpty() } ?:
receiver.packageView.module.getPackage(childPackageFQN).satisfying { !it.isEmpty() } ?:
receiver.packageView.memberScope.getContributedClassifier(name, KotlinLookupLocation(expression))
}
receiver is ClassQualifier ->
receiver.scope.getContributedClassifier(name, KotlinLookupLocation(expression))
receiver == null ->
context.scope.findClassifier(name, KotlinLookupLocation(expression)) ?:
context.scope.ownerDescriptor.module.getPackage(FqName.ROOT.child(name)).check { !it.isEmpty() }
context.scope.ownerDescriptor.module.getPackage(FqName.ROOT.child(name)).satisfying { !it.isEmpty() }
receiver is ReceiverValue ->
receiver.type.memberScope.memberScopeAsImportingScope().findClassifier(name, KotlinLookupLocation(expression))
else -> null

View File

@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionMutableResolve
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class OverloadingConflictResolver(private val builtIns: KotlinBuiltIns) {
@@ -89,7 +89,7 @@ class OverloadingConflictResolver(private val builtIns: KotlinBuiltIns) {
val bestCandidatesByParameterTypes = conflictingCandidates.mapNotNull {
candidate ->
candidate.check {
candidate.satisfying {
isMostSpecific(candidate, conflictingCandidates) {
call1, call2 ->
isNotLessSpecificCallWithArgumentMapping(call1, call2, discriminateGenerics)

View File

@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.types.DeferredType
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.isDynamic
import org.jetbrains.kotlin.util.OperatorNameConventions
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.kotlin.utils.sure
class NewResolveOldInference(
@@ -290,7 +290,7 @@ class NewResolveOldInference(
tracing.bindReference(variable.resolvedCall.trace, variable.resolvedCall)
// todo hacks
val functionCall = CallTransformer.CallForImplicitInvoke(
basicCallContext.call.explicitReceiver?.check { useExplicitReceiver },
basicCallContext.call.explicitReceiver?.satisfying { useExplicitReceiver },
variableReceiver, basicCallContext.call)
val tracingForInvoke = TracingStrategyForInvoke(calleeExpression, functionCall, variableReceiver.type)
val basicCallResolutionContext = basicCallContext.replaceBindingTrace(variable.resolvedCall.trace)

View File

@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.containsError
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
@@ -50,7 +50,7 @@ internal class ScopeTowerImpl(
override val lexicalScope: LexicalScope = resolutionContext.scope
override val implicitReceivers = resolutionContext.scope.getImplicitReceiversHierarchy().
mapNotNull { it.value.check { !it.type.containsError() } }
mapNotNull { it.value.satisfying { !it.type.containsError() } }
}
private class DataFlowDecoratorImpl(private val resolutionContext: ResolutionContext<*>): DataFlowDecorator {

View File

@@ -22,14 +22,14 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
internal class KnownResultProcessor<C>(
val result: Collection<C>
): ScopeTowerProcessor<C> {
override fun process(data: TowerData)
= if (data == TowerData.Empty) listOfNotNull(result.check { it.isNotEmpty() }) else emptyList()
= if (data == TowerData.Empty) listOfNotNull(result.satisfying { it.isNotEmpty() }) else emptyList()
}
internal class CompositeScopeTowerProcessor<C>(
@@ -45,7 +45,7 @@ internal abstract class AbstractSimpleScopeTowerProcessor<C>(
protected abstract fun simpleProcess(data: TowerData): Collection<C>
override fun process(data: TowerData): List<Collection<C>> = listOfNotNull(simpleProcess(data).check { it.isNotEmpty() })
override fun process(data: TowerData): List<Collection<C>> = listOfNotNull(simpleProcess(data).satisfying { it.isNotEmpty() })
}
internal class ExplicitReceiverScopeTowerProcessor<C>(

View File

@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
interface TowerContext<C> {
@@ -221,13 +221,13 @@ class TowerResolver {
override fun getSuccessfulCandidates(): Collection<C>? = getResolved() ?: getResolvedSynthetic()
fun getResolved() = currentCandidates.check { currentLevel == ResolutionCandidateApplicability.RESOLVED }
fun getResolved() = currentCandidates.satisfying { currentLevel == ResolutionCandidateApplicability.RESOLVED }
fun getResolvedSynthetic() = currentCandidates.check { currentLevel == ResolutionCandidateApplicability.RESOLVED_SYNTHESIZED }
fun getResolvedSynthetic() = currentCandidates.satisfying { currentLevel == ResolutionCandidateApplicability.RESOLVED_SYNTHESIZED }
fun getResolvedLowPriority() = currentCandidates.check { currentLevel == ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY }
fun getResolvedLowPriority() = currentCandidates.satisfying { currentLevel == ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY }
fun getErrors() = currentCandidates.check {
fun getErrors() = currentCandidates.satisfying {
currentLevel == null || currentLevel!! > ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY
}

View File

@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
open class FileScopeProviderImpl(
private val topLevelDescriptorProvider: TopLevelDescriptorProvider,
@@ -159,7 +159,7 @@ open class FileScopeProviderImpl(
if (name in excludedNames) return null
val classifier = scope.getContributedClassifier(name, location) ?: return null
val visible = Visibilities.isVisibleWithIrrelevantReceiver(classifier as ClassDescriptor, fromDescriptor)
return classifier.check { filteringKind == if (visible) FilteringKind.VISIBLE_CLASSES else FilteringKind.INVISIBLE_CLASSES }
return classifier.satisfying { filteringKind == if (visible) FilteringKind.VISIBLE_CLASSES else FilteringKind.INVISIBLE_CLASSES }
}
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {

View File

@@ -56,7 +56,7 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.utils.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
import java.util.*
@@ -180,7 +180,7 @@ class LazyJavaClassMemberScope(
descriptor ->
if (descriptor.valueParameters.size != 0) return@factory null
descriptor.check { KotlinTypeChecker.DEFAULT.isSubtypeOf(descriptor.returnType ?: return@check false, type) }
descriptor.satisfying { KotlinTypeChecker.DEFAULT.isSubtypeOf(descriptor.returnType ?: return@check false, type) }
}
}
@@ -192,7 +192,7 @@ class LazyJavaClassMemberScope(
if (descriptor.valueParameters.size != 1) return@factory null
if (!KotlinBuiltIns.isUnit(descriptor.returnType ?: return@factory null)) return@factory null
descriptor.check { KotlinTypeChecker.DEFAULT.equalTypes(descriptor.valueParameters.single().type, type) }
descriptor.satisfying { KotlinTypeChecker.DEFAULT.equalTypes(descriptor.valueParameters.single().type, type) }
}
}

View File

@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.DFS
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = companionObjectDescriptor ?: this
@@ -200,7 +200,7 @@ val DeclarationDescriptor.parents: Sequence<DeclarationDescriptor>
val CallableMemberDescriptor.propertyIfAccessor: CallableMemberDescriptor
get() = if (this is PropertyAccessorDescriptor) correspondingProperty else this
fun CallableDescriptor.fqNameOrNull(): FqName? = fqNameUnsafe.check { it.isSafe }?.toSafe()
fun CallableDescriptor.fqNameOrNull(): FqName? = fqNameUnsafe.satisfying { it.isSafe }?.toSafe()
fun CallableMemberDescriptor.firstOverridden(
predicate: (CallableMemberDescriptor) -> Boolean

View File

@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
data class ApproximationBounds<T>(

View File

@@ -76,7 +76,7 @@ fun <T> sequenceOfLazyValues(vararg elements: () -> T): Sequence<T> = elements.a
fun <T1, T2> Pair<T1, T2>.swap(): Pair<T2, T1> = Pair(second, first)
fun <T: Any> T.check(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null
fun <T: Any> T.satisfying(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null
fun <T : Any> constant(calculator: () -> T): T {
val cached = constantMap[calculator]

View File

@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.lazy.*
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyScriptDescriptor
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class ResolveElementCache(
private val resolveSession: ResolveSession,
@@ -147,7 +147,7 @@ class ResolveElementCache(
val statementToResolve = PartialBodyResolveFilter.findStatementToResolve(contextElement, resolveElement)
val partialResolveMap = partialBodyResolveCache.value
partialResolveMap[statementToResolve ?: resolveElement]
?.check { it.isUpToDate(file) }
?.satisfying { it.isUpToDate(file) }
?.let { return it.bindingContext } // partial resolve is already cached for this statement
val (bindingContext, statementFilter) = performElementAdditionalResolve(resolveElement, contextElement, BodyResolveMode.PARTIAL)

View File

@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.util.supertypesWithAny
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import java.util.*
@@ -295,8 +295,8 @@ class BasicCompletionSession(
if (userType != typeRef.typeElement) return null
val parent = typeRef.parent
return when (parent) {
is KtNamedFunction -> parent.check { typeRef == it.receiverTypeReference }
is KtProperty -> parent.check { typeRef == it.receiverTypeReference }
is KtNamedFunction -> parent.satisfying { typeRef == it.receiverTypeReference }
is KtProperty -> parent.satisfying { typeRef == it.receiverTypeReference }
else -> null
}
}

View File

@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptySet
import java.util.*
@@ -88,7 +88,7 @@ class SmartCompletion(
val descriptorFilter: ((DeclarationDescriptor, AbstractLookupElementFactory) -> Collection<LookupElement>)? =
{ descriptor: DeclarationDescriptor, factory: AbstractLookupElementFactory ->
filterDescriptor(descriptor, factory).map { postProcess(it) }
}.check { expectedInfos.isNotEmpty() }
}.satisfying { expectedInfos.isNotEmpty() }
fun additionalItems(lookupElementFactory: LookupElementFactory): Pair<Collection<LookupElement>, InheritanceItemsSearcher?> {
val (items, inheritanceSearcher) = additionalItemsNoPostProcess(lookupElementFactory)

View File

@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.util.*
@@ -555,7 +555,7 @@ class ExpectedInfos(
val loopVar = forExpression.loopParameter
val loopVarType = if (loopVar != null && loopVar.typeReference != null)
(resolutionFacade.resolveToDescriptor(loopVar) as VariableDescriptor).type.check { !it.isError }
(resolutionFacade.resolveToDescriptor(loopVar) as VariableDescriptor).type.satisfying { !it.isError }
else
null

View File

@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.idea.refactoring.getLineStartOffset
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
class KotlinFrameExtraVariablesProvider : FrameExtraVariablesProvider {
@@ -64,7 +64,7 @@ private fun findAdditionalExpressions(position: SourcePosition): Set<TextWithImp
return emptySet()
}
val offset = file.getLineStartOffset(line)?.check { it > 0 } ?: return emptySet()
val offset = file.getLineStartOffset(line)?.satisfying { it > 0 } ?: return emptySet()
val elem = file.findElementAt(offset)
val containingElement = getContainingElement(elem!!) ?: elem ?: return emptySet()

View File

@@ -259,7 +259,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
private fun classNamesForPositionAndInlinedOnes(sourcePosition: SourcePosition): List<String> {
val result = hashSetOf<String>()
val names = classNamesForPosition(sourcePosition, true)
val names = classNamesForPosition(sourcePosition)
result.addAll(names)
val lambdas = findLambdas(sourcePosition)
@@ -280,12 +280,12 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
}
}
fun classNamesForPosition(sourcePosition: SourcePosition, withInlines: Boolean): Collection<String> {
fun classNamesForPosition(sourcePosition: SourcePosition): Collection<String> {
val psiElement = runReadAction { sourcePosition.elementAt } ?: return emptyList()
return classNamesForPosition(psiElement, withInlines)
return classNamesForPosition(psiElement)
}
private fun classNamesForPosition(element: PsiElement, withInlines: Boolean): Collection<String> {
private fun classNamesForPosition(element: PsiElement): Collection<String> {
return runReadAction {
if (DumbService.getInstance(element.project).isDumb) {
emptySet()
@@ -294,7 +294,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
val file = element.containingFile as KtFile
val isInLibrary = LibraryUtil.findLibraryEntry(file.virtualFile, file.project) != null
val typeMapper = if (!isInLibrary) prepareTypeMapper(file) else createTypeMapperForLibraryFile(element, file)
getInternalClassNameForElement(element, typeMapper, file, isInLibrary, withInlines)
getInternalClassNameForElement(element, typeMapper, file, isInLibrary)
}
}
}
@@ -356,13 +356,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
myTypeMappers.put(key, value)
}
private fun getInternalClassNameForElement(
notPositionedElement: PsiElement?,
typeMapper: JetTypeMapper,
file: KtFile,
isInLibrary: Boolean,
withInlines: Boolean = true
): Collection<String> {
private fun getInternalClassNameForElement(notPositionedElement: PsiElement?, typeMapper: JetTypeMapper, file: KtFile, isInLibrary: Boolean): Collection<String> {
val element = getElementToCalculateClassName(notPositionedElement)
when (element) {
@@ -370,7 +364,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
is KtFunction -> {
val descriptor = InlineUtil.getInlineArgumentDescriptor(element, typeMapper.bindingContext)
if (descriptor != null) {
val classNamesForParent = getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary, withInlines)
val classNamesForParent = getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
if (descriptor.isCrossinline) {
return findCrossInlineArguments(element, descriptor, typeMapper.bindingContext) + classNamesForParent
}
@@ -393,9 +387,9 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
val parent = getElementToCalculateClassName(element.parent)
// Class-object initializer
if (parent is KtObjectDeclaration && parent.isCompanion()) {
return getInternalClassNameForElement(parent.parent, typeMapper, file, isInLibrary, withInlines)
return getInternalClassNameForElement(parent.parent, typeMapper, file, isInLibrary)
}
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary, withInlines)
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
}
element is KtProperty && (!element.isTopLevel || !isInLibrary) -> {
if (isInPropertyAccessor(notPositionedElement)) {
@@ -407,7 +401,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
val descriptor = typeMapper.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
if (descriptor !is PropertyDescriptor) {
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary, withInlines)
return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary)
}
return getJvmInternalNameForPropertyOwner(typeMapper, descriptor).toSet()
@@ -425,8 +419,6 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
NoResolveFileClassesProvider.getFileClassInternalName(file)
}
if (!withInlines) return parentInternalName.toSet()
val inlinedCalls = findInlinedCalls(element, typeMapper.bindingContext)
return inlinedCalls + parentInternalName.toSet()
}
@@ -497,7 +489,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
val usage = it.element
if (usage is KtElement) {
//TODO recursive search
val names = classNamesForPosition(usage, false)
val names = classNamesForPosition(usage)
result.addAll(names)
}
}

View File

@@ -49,7 +49,7 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
import java.util.concurrent.atomic.AtomicReference
@@ -171,7 +171,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
return containingFile
}
private fun KtElement?.check(): Boolean = this != null && this.check { KotlinEditorTextProvider.isAcceptedAsCodeFragmentContext(it) } != null
private fun KtElement?.check(): Boolean = this != null && this.satisfying { KotlinEditorTextProvider.isAcceptedAsCodeFragmentContext(it) } != null
//internal for tests
fun createCodeFragmentForLabeledObjects(project: Project, markupMap: Map<*, ValueMarkup>): Pair<String, Map<String, Value>> {

View File

@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.tail
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.org.objectweb.asm.ClassReader
import org.jetbrains.org.objectweb.asm.ClassVisitor
import java.io.File
@@ -98,7 +98,7 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter
}
private fun findClassFileByPath(packageName: String, className: String, outputDir: VirtualFile): File? {
val outDirFile = File(outputDir.path).check { it.exists() } ?: return null
val outDirFile = File(outputDir.path).satisfying { it.exists() } ?: return null
val parentDirectory = File(outDirFile, packageName.replace(".", File.separator))
if (!parentDirectory.exists()) return null

View File

@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.resolve.scopes.collectSyntheticExtensionFunctions
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
class RedundantSamConstructorInspection : AbstractKotlinInspection() {
@@ -178,7 +178,7 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
for (staticFunWithSameName in containingClass.staticScope.getContributedFunctions(functionResolvedCall.resultingDescriptor.name, NoLookupLocation.FROM_IDE)) {
if (staticFunWithSameName is SamAdapterDescriptor<*>) {
if (isSamAdapterSuitableForCall(staticFunWithSameName, originalFunctionDescriptor, samConstructorCallArguments.size)) {
return samConstructorCallArguments.check { canBeReplaced(functionCall, it) } ?: emptyList()
return samConstructorCallArguments.satisfying { canBeReplaced(functionCall, it) } ?: emptyList()
}
}
}
@@ -192,7 +192,7 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
for (syntheticExtension in syntheticExtensions) {
val samAdapter = syntheticExtension as? SamAdapterExtensionFunctionDescriptor ?: continue
if (isSamAdapterSuitableForCall(samAdapter, originalFunctionDescriptor, samConstructorCallArguments.size)) {
return samConstructorCallArguments.check { canBeReplaced(functionCall, it) } ?: emptyList()
return samConstructorCallArguments.satisfying { canBeReplaced(functionCall, it) } ?: emptyList()
}
}
@@ -203,7 +203,7 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
= argument.toCallExpression()?.samConstructorValueArgument() != null
private fun KtCallExpression.samConstructorValueArgument(): KtValueArgument? {
return valueArguments.singleOrNull()?.check { it.getArgumentExpression() is KtLambdaExpression }
return valueArguments.singleOrNull()?.satisfying { it.getArgumentExpression() is KtLambdaExpression }
}
private fun ValueArgument.toCallExpression(): KtCallExpression? {

View File

@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCallExpression>(KtCallExpression::class.java, "Replace 'assert' with 'if' statement"), LowPriorityAction {
override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean {
@@ -95,7 +95,7 @@ class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCallExpress
private fun extractMessageSingleExpression(functionLiteral: KtLambdaExpression, bindingContext: BindingContext): KtExpression? {
return functionLiteral.bodyExpression?.statements?.singleOrNull()?.let { singleStatement ->
singleStatement.check { it.isUsedAsExpression(bindingContext) }
singleStatement.satisfying { it.isUsedAsExpression(bindingContext) }
}
}

View File

@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class ConvertToExpressionBodyIntention : SelfTargetingOffsetIndependentIntention<KtDeclarationWithBody>(
KtDeclarationWithBody::class.java, "Convert to expression body"
@@ -57,7 +57,7 @@ class ConvertToExpressionBodyIntention : SelfTargetingOffsetIndependentIntention
val deleteTypeHandler: (KtCallableDeclaration) -> Unit = {
it.deleteChildRange(it.colon!!, it.typeReference!!)
}
applyTo(declaration, deleteTypeHandler.check { canDeleteTypeRef })
applyTo(declaration, deleteTypeHandler.satisfying { canDeleteTypeRef })
}
private fun applyTo(declaration: KtDeclarationWithBody, deleteTypeHandler: ((KtCallableDeclaration) -> Unit)?) {

View File

@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
object BranchedFoldingUtils {
fun getFoldableBranchedAssignment(branch: KtExpression?): KtBinaryExpression? {
@@ -36,11 +36,11 @@ object BranchedFoldingUtils {
return true
}
return (branch?.lastBlockStatementOrThis() as? KtBinaryExpression)?.check(::checkAssignment)
return (branch?.lastBlockStatementOrThis() as? KtBinaryExpression)?.satisfying(::checkAssignment)
}
fun getFoldableBranchedReturn(branch: KtExpression?): KtReturnExpression? {
return (branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.check { it.returnedExpression != null }
return (branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.satisfying { it.returnedExpression != null }
}
fun checkAssignmentsMatch(a1: KtBinaryExpression, a2: KtBinaryExpression): Boolean {

View File

@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.findMemberWithMaxVisibility
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.supertypes
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
/**
@@ -211,7 +211,7 @@ class ChangeMemberFunctionSignatureFix private constructor(
object MatchNames : ParameterChooser {
override fun choose(parameter: ValueParameterDescriptor, superParameter: ValueParameterDescriptor): ValueParameterDescriptor? {
return superParameter.check { parameter.name == superParameter.name }
return superParameter.satisfying { parameter.name == superParameter.name }
}
}

View File

@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.util.ShortenReferences
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class ClassUsageReplacementStrategy(
typeReplacement: KtUserType?,
@@ -31,7 +31,7 @@ class ClassUsageReplacementStrategy(
private val factory = KtPsiFactory(project)
private val typeReplacement = typeReplacement?.check { it.referenceExpression != null }
private val typeReplacement = typeReplacement?.satisfying { it.referenceExpression != null }
private val typeReplacementQualifierAsExpression = typeReplacement?.qualifier?.let { factory.createExpression(it.text) }
private val constructorReplacementStrategy = constructorReplacement?.let { CallableUsageReplacementStrategy(it) }

View File

@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
object DebuggerUtils {
@@ -51,7 +51,7 @@ object DebuggerUtils {
if (!KOTLIN_EXTENSIONS.contains(extension)) return null
if (DumbService.getInstance(project).isDumb) return null
val filesWithExactName = findFilesByNameInPackage(className, fileName, project, searchScope).check { it.isNotEmpty() }
val filesWithExactName = findFilesByNameInPackage(className, fileName, project, searchScope).satisfying { it.isNotEmpty() }
// Source files for libraries aren't included into ModuleWithDependencies scope
?: findFilesByNameInPackage(
className, fileName, project,

View File

@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.j2k
import com.intellij.psi.*
import com.intellij.psi.CommonClassNames.*
import org.jetbrains.kotlin.j2k.ast.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
class CodeConverter(
val converter: Converter,
@@ -78,7 +78,7 @@ class CodeConverter(
variable.initializer == null/* we do not know actually and prefer val until we have better analysis*/ ||
!variable.hasWriteAccesses(converter.referenceSearcher, variable.getContainingMethod())
val type = typeConverter.convertVariableType(variable)
val explicitType = type.check { settings.specifyLocalVariableTypeByDefault || converter.shouldDeclareVariableType(variable, type, isVal) }
val explicitType = type.satisfying { settings.specifyLocalVariableTypeByDefault || converter.shouldDeclareVariableType(variable, type, isVal) }
return LocalVariable(variable.declarationIdentifier(),
converter.convertAnnotations(variable),
converter.convertModifiers(variable, false),

View File

@@ -21,7 +21,7 @@ import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
import com.intellij.psi.CommonClassNames.JAVA_LANG_STRING
import com.intellij.psi.impl.PsiExpressionEvaluator
import org.jetbrains.kotlin.j2k.ast.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.io.PrintStream
import java.util.*
@@ -338,7 +338,7 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
STRING_GET_BYTES(JAVA_LANG_STRING, "getBytes", null) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter): MethodCallExpression {
val charsetArg = arguments.lastOrNull()?.check { it.type?.canonicalText == JAVA_LANG_STRING }
val charsetArg = arguments.lastOrNull()?.satisfying { it.type?.canonicalText == JAVA_LANG_STRING }
val convertedArguments = codeConverter.convertExpressions(arguments).map {
if (charsetArg != null && it.prototypes?.singleOrNull()?.element == charsetArg)
MethodCallExpression.buildNotNull(null, "charset", listOf(it)).assignNoPrototype()
@@ -466,7 +466,7 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
val candidates = valuesByName[method.name] ?: return null
return candidates
.firstOrNull { it.matches(method, services.superMethodsSearcher) }
?.check { it.parameterCount == null || it.parameterCount == argumentCount } // if parameterCount is specified we should make sure that argument count is correct
?.satisfying { it.parameterCount == null || it.parameterCount == argumentCount } // if parameterCount is specified we should make sure that argument count is correct
}
}
}

View File

@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
import java.util.*
class PropertyInfo(
@@ -162,7 +162,7 @@ private class PropertyDetector(
converter.convertModifiers(field, false).accessModifier()
else
propertyAccess
val specialSetterAccess = setterAccess?.check { it != propertyAccess }
val specialSetterAccess = setterAccess?.satisfying { it != propertyAccess }
val propertyInfo = PropertyInfo(Identifier(propertyName).assignNoPrototype(),
isVar,

View File

@@ -24,12 +24,12 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.satisfying
val KotlinType.nameIfStandardType: Name?
get() {
return constructor.declarationDescriptor
?.check { descriptor ->
?.satisfying { descriptor ->
descriptor.builtIns.isBuiltInPackageFragment(descriptor.containingDeclaration as? PackageFragmentDescriptor)
}
?.name