Renamed firstOrNullIsInstance

This commit is contained in:
Valentin Kipyatkov
2014-11-21 15:22:53 +03:00
parent ddc60ac5dd
commit d334011d5d
6 changed files with 13 additions and 13 deletions
@@ -24,12 +24,12 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.PsiErrorElement
import org.jetbrains.jet.lang.psi.JetCallableDeclaration
import org.jetbrains.jet.utils.addToStdlib.firstOrNullIsInstance
import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull
fun getTypeReference(declaration: JetCallableDeclaration): JetTypeReference? {
return declaration.getFirstChild()!!.siblings(forward = true)
.dropWhile { it.getNode()!!.getElementType() != JetTokens.COLON }
.firstOrNullIsInstance<JetTypeReference>()
.firstIsInstanceOrNull<JetTypeReference>()
}
fun setTypeReference(declaration: JetCallableDeclaration, addAfter: PsiElement?, typeRef: JetTypeReference?): JetTypeReference? {
@@ -34,7 +34,7 @@ import org.jetbrains.jet.storage.StorageManager
import org.jetbrains.jet.context.LazinessToken
import org.jetbrains.jet.lang.resolve.lazy.LazyEntity
import org.jetbrains.jet.lang.resolve.lazy.ForceResolveUtil
import org.jetbrains.jet.utils.addToStdlib.firstOrNullIsInstance
import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull
public class TypeResolver(
private val annotationResolver: AnnotationResolver,
@@ -276,7 +276,7 @@ public class TypeResolver(
public fun resolveClass(scope: JetScope, userType: JetUserType, trace: BindingTrace): ClassifierDescriptor? {
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace)
.firstOrNullIsInstance<ClassifierDescriptor>()
.firstIsInstanceOrNull<ClassifierDescriptor>()
if (classifierDescriptor != null) {
ImportsResolver.reportPlatformClassMappedToKotlin(moduleDescriptor, trace, userType, classifierDescriptor)
}
@@ -36,19 +36,19 @@ public fun <T: Any> T?.singletonOrEmptyList(): List<T> = if (this != null) Colle
public fun <T: Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) Collections.singleton(this) else Collections.emptySet()
[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T : Any> Stream<*>.firstOrNullIsInstance(): T? {
public inline fun <reified T : Any> Stream<*>.firstIsInstanceOrNull(): T? {
for (element in this) if (element is T) return element
return null
}
[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T : Any> Iterable<*>.firstOrNullIsInstance(): T? {
public inline fun <reified T : Any> Iterable<*>.firstIsInstanceOrNull(): T? {
for (element in this) if (element is T) return element
return null
}
[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T : Any> Array<*>.firstOrNullIsInstance(): T? {
public inline fun <reified T : Any> Array<*>.firstIsInstanceOrNull(): T? {
for (element in this) if (element is T) return element
return null
}
@@ -26,7 +26,7 @@ import java.util.HashMap
import com.intellij.psi.PsiElement
import org.jetbrains.jet.JetNodeTypes
import org.jetbrains.jet.lang.psi.psiUtil.isProbablyNothing
import org.jetbrains.jet.utils.addToStdlib.firstOrNullIsInstance
import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
//TODO: do resolve anonymous object's body
@@ -432,7 +432,7 @@ class PartialBodyResolveFilter(
}
private fun JetBlockExpression.lastStatement(): JetExpression?
= getLastChild()?.siblings(forward = false)?.firstOrNullIsInstance<JetExpression>()
= getLastChild()?.siblings(forward = false)?.firstIsInstanceOrNull<JetExpression>()
//TODO: declarations with special names (e.g. "get")
private class NameFilter {
@@ -36,7 +36,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptorKi
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.jet.utils.addToStdlib.firstOrNullIsInstance
import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull
class CompletionSessionConfiguration(
val completeNonImportedDeclarations: Boolean,
@@ -50,7 +50,7 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
protected val parameters: CompletionParameters,
resultSet: CompletionResultSet) {
protected val position: PsiElement = parameters.getPosition()
protected val jetReference: JetSimpleNameReference? = position.getParent()?.getReferences()?.filterIsInstance(javaClass<JetSimpleNameReference>())?.firstOrNull()
protected val jetReference: JetSimpleNameReference? = position.getParent()?.getReferences()?.firstIsInstanceOrNull<JetSimpleNameReference>()
private val file = position.getContainingFile() as JetFile
protected val resolutionFacade: ResolutionFacade = file.getResolutionFacade()
protected val moduleDescriptor: ModuleDescriptor = resolutionFacade.findModuleDescriptor(file)
@@ -13,7 +13,6 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.lang.psi.psiUtil.getQualifiedElement
import org.jetbrains.jet.lang.psi.JetClass
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.guessTypes
import org.jetbrains.jet.plugin.caches.resolve.analyzeFully
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
@@ -41,6 +40,7 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction
import org.jetbrains.jet.lang.psi.psiUtil.getAssignmentByLHS
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.getExpressionForTypeGuess
import org.jetbrains.jet.plugin.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull
object CreateParameterActionFactory: JetSingleIntentionActionFactory() {
private fun JetType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, context: BindingContext): Boolean {
@@ -86,7 +86,7 @@ object CreateParameterActionFactory: JetSingleIntentionActionFactory() {
fun chooseContainingClass(it: PsiElement): JetClass? {
parameterInfo.setValOrVar(if (varExpected) JetValVar.Var else JetValVar.Val)
return it.parents(false).filterIsInstance(javaClass<JetClassOrObject>()).firstOrNull() as? JetClass
return it.parents(false).firstIsInstanceOrNull<JetClassOrObject>() as? JetClass
}
// todo: skip lambdas for now because Change Signature doesn't apply to them yet