Code cleanup: get rid of unnecessary !! / ?. / as

This commit is contained in:
Mikhail Glukhikh
2015-11-11 15:50:24 +03:00
parent 7e8e4e9e1b
commit 2f4dbd2084
21 changed files with 33 additions and 33 deletions
@@ -309,7 +309,7 @@ public class KotlinCoreEnvironment private constructor(
if (ourApplicationEnvironment == null) return
val environment = ourApplicationEnvironment
ourApplicationEnvironment = null
Disposer.dispose(environment!!.getParentDisposable())
Disposer.dispose(environment.getParentDisposable())
}
}
@@ -359,7 +359,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
}
val classParametersSubstitutor = TypeSubstitutor.create(substitutionMap)
descriptor.getMethod = getMethod.substitute(classParametersSubstitutor)!!
descriptor.getMethod = getMethod.substitute(classParametersSubstitutor)
descriptor.setMethod = setMethod?.substitute(classParametersSubstitutor)
return descriptor
}
@@ -199,7 +199,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
}
val sourceFunctionSubstitutor = TypeSubstitutor.create(substitutionMap)
descriptor.sourceFunction = original.sourceFunction.substitute(sourceFunctionSubstitutor)!!
descriptor.sourceFunction = original.sourceFunction.substitute(sourceFunctionSubstitutor)
return descriptor
}
@@ -98,12 +98,12 @@ public fun PsiElement.getParentOfTypesAndPredicate<T : PsiElement>(
while (element != null) {
@Suppress("UNCHECKED_CAST")
when {
(parentClasses.isEmpty() || parentClasses.any { parentClass -> parentClass.isInstance(element) }) && predicate(element!! as T) ->
return element as T
(parentClasses.isEmpty() || parentClasses.any { parentClass -> parentClass.isInstance(element) }) && predicate(element as T) ->
return element
element is PsiFile ->
return null
else ->
element = element!!.getParent()
element = element.getParent()
}
}
@@ -52,7 +52,7 @@ fun createSynthesizedInvokes(functions: Collection<FunctionDescriptor>): Collect
fakeOverride
}
result.add(synthesized.substitute(TypeSubstitutor.create(invoke.getDispatchReceiverParameter()!!.getType()))!!)
result.add(synthesized.substitute(TypeSubstitutor.create(invoke.getDispatchReceiverParameter()!!.getType())))
}
return result
@@ -189,7 +189,7 @@ class LazyOperationsLog(
}.appendQuoted()
}
o is ResolutionCandidate<*> -> DescriptorRenderer.COMPACT.render(o.getDescriptor()).appendQuoted()
o is ResolutionTaskHolder<*, *> -> o.field<BasicCallResolutionContext>("basicCallResolutionContext").call.getCallElement().getDebugText()?.appendQuoted()
o is ResolutionTaskHolder<*, *> -> o.field<BasicCallResolutionContext>("basicCallResolutionContext").call.getCallElement().getDebugText().appendQuoted()
}
return sb.toString()
}
@@ -54,10 +54,10 @@ public abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCom
catch (e: Throwable) {
var result = ""
if (factory1 != null) {
result += "FIRST: \n\n" + factory1!!.createText()
result += "FIRST: \n\n" + factory1.createText()
}
if (factory2 != null) {
result += "\n\nSECOND: \n\n" + factory2!!.createText()
result += "\n\nSECOND: \n\n" + factory2.createText()
}
System.out.println(result)
throw e
@@ -73,7 +73,7 @@ public abstract class SelfTargetingIntention<TElement : KtElement>(
for (element in elementsToCheck) {
@Suppress("UNCHECKED_CAST")
if (elementType.isInstance(element) && isApplicableTo(element as TElement, offset)) {
return element as TElement
return element
}
if (!allowCaretInsideElement(element) && element.getTextRange().containsInside(offset)) break
}
@@ -342,7 +342,7 @@ class ExpectedInfos(
val alreadyHasStar = argument.getSpreadElement() != null
val varargElementType = parameter!!.varargElementType
val varargElementType = parameter.varargElementType
if (varargElementType != null) {
if (isFunctionLiteralArgument) return
@@ -356,16 +356,16 @@ class ExpectedInfos(
}
val starOptions = if (!alreadyHasStar) ItemOptions.STAR_PREFIX else ItemOptions.DEFAULT
add(ExpectedInfo.createForArgument(parameter!!.getType(), expectedName, varargTail, argumentPositionData, starOptions))
add(ExpectedInfo.createForArgument(parameter.getType(), expectedName, varargTail, argumentPositionData, starOptions))
}
else {
if (alreadyHasStar) return
val parameterType = if (useHeuristicSignatures)
resolutionFacade.ideService<HeuristicSignatures>().
correctedParameterType(descriptor, parameter!!) ?: parameter!!.getType()
correctedParameterType(descriptor, parameter) ?: parameter.getType()
else
parameter!!.getType()
parameter.getType()
if (isFunctionLiteralArgument) {
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(parameterType)) {
@@ -154,7 +154,7 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() {
}
if (insertLambda && lambdaInfo!!.explicitParameters) {
insertLambdaTemplate(context, TextRange(openingBracketOffset, closeBracketOffset!! + 1), lambdaInfo!!.lambdaType)
insertLambdaTemplate(context, TextRange(openingBracketOffset, closeBracketOffset!! + 1), lambdaInfo.lambdaType)
return
}
@@ -170,7 +170,7 @@ public abstract class KotlinFindMemberUsagesHandler<T : KtNamedDeclaration>
return if (baseDeclarations.isNotEmpty()) {
baseDeclarations.flatMap {
val handler = (FindManager.getInstance(project) as FindManagerImpl).findUsagesManager.getFindUsagesHandler(it!!, true)
handler?.findReferencesToHighlight(it!!, searchScope) ?: emptyList()
handler?.findReferencesToHighlight(it, searchScope) ?: emptyList()
}
}
else {
@@ -91,7 +91,7 @@ private fun KtExpression.getRelevantFunction(): KtFunction? {
}
for (parent in parents) {
if (InlineUtil.canBeInlineArgument(parent) && !InlineUtil.isInlinedArgument(parent as KtFunction, parent.analyze(), false)) {
return parent as KtFunction
return parent
}
}
return null
@@ -61,7 +61,7 @@ internal fun getTargetParentByQualifier(
if (qualifierDescriptor.fqName != file.getPackageFqName()) {
JavaPsiFacade.getInstance(project).findPackage(qualifierDescriptor.fqName.asString())
}
else file as PsiElement
else file as PsiElement // KT-9972
else ->
null
} ?: return null
@@ -144,7 +144,7 @@ fun KotlinType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, co
is FunctionDescriptor -> {
val function = functionDescriptor.source.getPsi() as? KtFunction
function?.bodyExpression?.getResolutionScope(context, function!!.getResolutionFacade())
function?.bodyExpression?.getResolutionScope(context, function.getResolutionFacade())
}
else -> null
@@ -553,7 +553,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
if (!generatorOptions.inTempFile && defaultValue != null && descriptor.controlFlow.outputValueBoxer.boxingRequired && lastExpression!!.isMultiLine()) {
val varNameValidator = NewDeclarationNameValidator(body, lastExpression, NewDeclarationNameValidator.Target.VARIABLES)
val resultVal = KotlinNameSuggester.suggestNamesByType(defaultValue.valueType, varNameValidator, null).first()
val newDecl = body.addBefore(psiFactory.createDeclaration("val $resultVal = ${lastExpression!!.text}"), lastExpression) as KtProperty
val newDecl = body.addBefore(psiFactory.createDeclaration("val $resultVal = ${lastExpression.text}"), lastExpression) as KtProperty
body.addBefore(psiFactory.createNewLine(), lastExpression)
psiFactory.createExpression(resultVal) to newDecl.initializer!!
}
@@ -68,7 +68,7 @@ public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMe
data.getParametersToRemove().toNativeArray().sortedDescending().forEach { changeInfo.removeParameter(it) }
// Temporarily assume that the new parameter is of Any type. Actual type is substituted during the signature update phase
val defaultValueForCall = (data.getParameterInitializer().getExpression()!! as? PsiExpression)?.let { it.j2k() }
val defaultValueForCall = (data.getParameterInitializer().getExpression() as? PsiExpression)?.let { it.j2k() }
changeInfo.addParameter(KotlinParameterInfo(callableDescriptor = psiMethodDescriptor,
name = data.getParameterName(),
type = psiMethodDescriptor.builtIns.anyType,
@@ -146,13 +146,13 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
}
protected fun SuspendContextImpl.doStepOut() {
val stepOutCommand = runReadAction { KotlinSteppingCommandProvider().getStepOutCommand(this, debuggerContext!!) }
val stepOutCommand = runReadAction { KotlinSteppingCommandProvider().getStepOutCommand(this, debuggerContext) }
?: dp.createStepOutCommand(this)
dp.managerThread.schedule(stepOutCommand)
}
protected fun SuspendContextImpl.doStepOver() {
val stepOverCommand = runReadAction { KotlinSteppingCommandProvider().getStepOverCommand(this, false, debuggerContext!!) }
val stepOverCommand = runReadAction { KotlinSteppingCommandProvider().getStepOverCommand(this, false, debuggerContext) }
?: dp.createStepOverCommand(this, false)
dp.managerThread.schedule(stepOverCommand)
}
@@ -223,7 +223,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
}
fun getExtraVars(): Set<TextWithImports> {
return KotlinFrameExtraVariablesProvider().collectVariables(debuggerContext!!.getSourcePosition(), evaluationContext!!, hashSetOf())!!
return KotlinFrameExtraVariablesProvider().collectVariables(debuggerContext.getSourcePosition(), evaluationContext, hashSetOf())
}
private inner class Printer() {
@@ -264,11 +264,11 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
is StackFrameDescriptor -> logDescriptor(descriptor, "$curIndent frame = $label\n")
is WatchItemDescriptor -> logDescriptor(descriptor, "$curIndent extra = ${descriptor.calcValueName()}\n")
is LocalVariableDescriptor -> logDescriptor(descriptor, "$curIndent local = $label"
+ " (sp = ${render(SourcePositionProvider.getSourcePosition(descriptor, myProject, debuggerContext!!))})\n")
+ " (sp = ${render(SourcePositionProvider.getSourcePosition(descriptor, myProject, debuggerContext))})\n")
is StaticDescriptor -> logDescriptor(descriptor, "$curIndent static = $label\n")
is ThisDescriptorImpl -> logDescriptor(descriptor, "$curIndent this = $label\n")
is FieldDescriptor -> logDescriptor(descriptor, "$curIndent field = $label"
+ " (sp = ${render(SourcePositionProvider.getSourcePosition(descriptor, myProject, debuggerContext!!))})\n")
+ " (sp = ${render(SourcePositionProvider.getSourcePosition(descriptor, myProject, debuggerContext))})\n")
is MessageDescriptor -> logDescriptor(descriptor, "$curIndent - $label\n")
else -> logDescriptor(descriptor, "$curIndent unknown = $label\n")
}
@@ -352,7 +352,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
val sourcePosition = ContextUtil.getSourcePosition(this)
val contextElement = createContextElement(this)
contextElement.putCopyableUserData(KotlinCodeFragmentFactory.DEBUG_FRAME_FOR_TESTS, evaluationContext?.frameProxy)
contextElement.putCopyableUserData(KotlinCodeFragmentFactory.DEBUG_FRAME_FOR_TESTS, evaluationContext.frameProxy)
try {
@@ -199,7 +199,7 @@ class RunConfigurationTest: KotlinCodeInsightTestCase() {
val dataContext = MapDataContext()
dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), declaration))
val context = ConfigurationContext.getFromContext(dataContext)
val actualClass = (context?.getConfiguration()?.getConfiguration() as? JetRunConfiguration)?.getRunClass()
val actualClass = (context.getConfiguration()?.getConfiguration() as? JetRunConfiguration)?.getRunClass()
if (actualClass != null) {
actualClasses.add(actualClass)
}
@@ -229,7 +229,7 @@ class RunConfigurationTest: KotlinCodeInsightTestCase() {
val dataContext = MapDataContext()
dataContext.put(Location.DATA_KEY, PsiLocation(getTestProject(), element))
val runnerAndConfigurationSettings = ConfigurationContext.getFromContext(dataContext)!!.getConfiguration()
val runnerAndConfigurationSettings = ConfigurationContext.getFromContext(dataContext).getConfiguration()
if (save) {
RunManagerEx.getInstanceEx(myProject).setTemporaryConfiguration(runnerAndConfigurationSettings)
}
@@ -35,7 +35,7 @@ class AndroidXmlHandler(private val elementCallback: (String, String) -> Unit) :
val attributesMap = attributes.toMap()
val idAttribute = attributesMap[AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE]
val widgetType = attributesMap[AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE] ?: localName
val name = idAttribute?.let { idToName(idAttribute!!) }
val name = idAttribute?.let { idToName(idAttribute) }
if (name != null) elementCallback(name, widgetType)
}
@@ -132,8 +132,8 @@ public class AndroidRenameProcessor : RenamePsiElementProcessor() {
oldPropName: String,
processor: SyntheticFileGenerator
) {
val props = processor.getSyntheticFiles()?.flatMap { it.findChildrenByClass(javaClass<KtProperty>()).toList() }
val matchedProps = props?.filter { it.getName() == oldPropName } ?: listOf()
val props = processor.getSyntheticFiles().flatMap { it.findChildrenByClass(javaClass<KtProperty>()).toList() }
val matchedProps = props.filter { it.getName() == oldPropName } ?: listOf()
for (prop in matchedProps) {
allRenames[prop] = newPropName
}