Cleanup: apply "lift out..." inspection (+ some others)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0c41ceea9d
commit
9c06739594
@@ -75,7 +75,7 @@ class ConstructorConsistencyChecker private constructor(
|
||||
return true
|
||||
}
|
||||
if (descriptor.containingDeclaration != classDescriptor) return true
|
||||
if (insideLValue(reference)) return descriptor.setter?.isDefault != false else return descriptor.getter?.isDefault != false
|
||||
return if (insideLValue(reference)) descriptor.setter?.isDefault != false else descriptor.getter?.isDefault != false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1119,23 +1119,21 @@ class ControlFlowInformationProvider private constructor(
|
||||
}
|
||||
|
||||
private fun combineKinds(kind: TailRecursionKind, existingKind: TailRecursionKind?): TailRecursionKind {
|
||||
val resultingKind: TailRecursionKind
|
||||
if (existingKind == null || existingKind == kind) {
|
||||
resultingKind = kind
|
||||
return if (existingKind == null || existingKind == kind) {
|
||||
kind
|
||||
}
|
||||
else {
|
||||
if (check(kind, existingKind, IN_TRY, TAIL_CALL)) {
|
||||
resultingKind = IN_TRY
|
||||
IN_TRY
|
||||
}
|
||||
else if (check(kind, existingKind, IN_TRY, NON_TAIL)) {
|
||||
resultingKind = IN_TRY
|
||||
IN_TRY
|
||||
}
|
||||
else {
|
||||
// TAIL_CALL, NON_TAIL
|
||||
resultingKind = NON_TAIL
|
||||
NON_TAIL
|
||||
}
|
||||
}
|
||||
return resultingKind
|
||||
}
|
||||
|
||||
private fun check(a: Any, b: Any, x: Any, y: Any) = a === x && b === y || a === y && b === x
|
||||
|
||||
@@ -518,13 +518,12 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
val incrementOrDecrement = isIncrementOrDecrement(operationType)
|
||||
val resolvedCall = expression.getResolvedCall(trace.bindingContext)
|
||||
|
||||
val rhsValue: PseudoValue?
|
||||
if (resolvedCall != null) {
|
||||
rhsValue = generateCall(resolvedCall).outputValue
|
||||
val rhsValue: PseudoValue? = if (resolvedCall != null) {
|
||||
generateCall(resolvedCall).outputValue
|
||||
}
|
||||
else {
|
||||
generateInstructions(baseExpression)
|
||||
rhsValue = createNonSyntheticValue(expression, MagicKind.UNRESOLVED_CALL, baseExpression)
|
||||
createNonSyntheticValue(expression, MagicKind.UNRESOLVED_CALL, baseExpression)
|
||||
}
|
||||
|
||||
if (incrementOrDecrement) {
|
||||
@@ -866,12 +865,12 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
if (labelName != null) {
|
||||
val targetLabel = expression.getTargetLabel()!!
|
||||
val labeledElement = trace.get(BindingContext.LABEL_TARGET, targetLabel)
|
||||
if (labeledElement is KtLoopExpression) {
|
||||
loop = labeledElement
|
||||
loop = if (labeledElement is KtLoopExpression) {
|
||||
labeledElement
|
||||
}
|
||||
else {
|
||||
trace.report(NOT_A_LOOP_LABEL.on(expression, targetLabel.text))
|
||||
loop = null
|
||||
null
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -946,18 +945,18 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
val labelElement = expression.getTargetLabel()
|
||||
val subroutine: KtElement?
|
||||
val labelName = expression.getLabelName()
|
||||
if (labelElement != null && labelName != null) {
|
||||
subroutine = if (labelElement != null && labelName != null) {
|
||||
val labeledElement = trace.get(BindingContext.LABEL_TARGET, labelElement)
|
||||
if (labeledElement != null) {
|
||||
assert(labeledElement is KtElement)
|
||||
subroutine = labeledElement as KtElement?
|
||||
labeledElement as KtElement?
|
||||
}
|
||||
else {
|
||||
subroutine = null
|
||||
null
|
||||
}
|
||||
}
|
||||
else {
|
||||
subroutine = builder.returnSubroutine
|
||||
builder.returnSubroutine
|
||||
// TODO : a context check
|
||||
}
|
||||
|
||||
@@ -1147,15 +1146,15 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
val resolvedCall = trace.get(BindingContext.COMPONENT_RESOLVED_CALL, entry)
|
||||
|
||||
val writtenValue: PseudoValue?
|
||||
if (resolvedCall != null) {
|
||||
writtenValue = builder.call(
|
||||
writtenValue = if (resolvedCall != null) {
|
||||
builder.call(
|
||||
entry,
|
||||
resolvedCall,
|
||||
getReceiverValues(resolvedCall),
|
||||
emptyMap<PseudoValue, ValueParameterDescriptor>()).outputValue
|
||||
}
|
||||
else {
|
||||
writtenValue = initializer?.let { createSyntheticValue(entry, MagicKind.UNRESOLVED_CALL, it) }
|
||||
initializer?.let { createSyntheticValue(entry, MagicKind.UNRESOLVED_CALL, it) }
|
||||
}
|
||||
|
||||
if (generateWriteForEntries) {
|
||||
|
||||
+7
-10
@@ -56,11 +56,11 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() {
|
||||
|
||||
private fun popBuilder(): ControlFlowInstructionsGeneratorWorker {
|
||||
val worker = builders.pop()
|
||||
if (!builders.isEmpty()) {
|
||||
builder = builders.peek()
|
||||
builder = if (!builders.isEmpty()) {
|
||||
builders.peek()
|
||||
}
|
||||
else {
|
||||
builder = null
|
||||
null
|
||||
}
|
||||
return worker
|
||||
}
|
||||
@@ -400,13 +400,10 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() {
|
||||
return magic(expression, expression, inputValues, getMagicKind(operation))
|
||||
}
|
||||
|
||||
private fun getMagicKind(operation: ControlFlowBuilder.PredefinedOperation): MagicKind {
|
||||
when (operation) {
|
||||
ControlFlowBuilder.PredefinedOperation.AND -> return MagicKind.AND
|
||||
ControlFlowBuilder.PredefinedOperation.OR -> return MagicKind.OR
|
||||
ControlFlowBuilder.PredefinedOperation.NOT_NULL_ASSERTION -> return MagicKind.NOT_NULL_ASSERTION
|
||||
else -> throw IllegalArgumentException("Invalid operation: " + operation)
|
||||
}
|
||||
private fun getMagicKind(operation: ControlFlowBuilder.PredefinedOperation) = when (operation) {
|
||||
ControlFlowBuilder.PredefinedOperation.AND -> MagicKind.AND
|
||||
ControlFlowBuilder.PredefinedOperation.OR -> MagicKind.OR
|
||||
ControlFlowBuilder.PredefinedOperation.NOT_NULL_ASSERTION -> MagicKind.NOT_NULL_ASSERTION
|
||||
}
|
||||
|
||||
override fun read(
|
||||
|
||||
@@ -68,11 +68,7 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType<Psi
|
||||
val project = placeholder.project
|
||||
val codeStyleManager = CodeStyleManager.getInstance(project)
|
||||
|
||||
if (argument.isEmpty) {
|
||||
placeholder.delete()
|
||||
return PsiChildRange.EMPTY
|
||||
}
|
||||
else {
|
||||
return if (!argument.isEmpty) {
|
||||
val first = placeholder.parent.addRangeBefore(argument.first!!, argument.last!!, placeholder)
|
||||
val last = placeholder.prevSibling
|
||||
placeholder.delete()
|
||||
@@ -81,7 +77,11 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType<Psi
|
||||
if (last != first) {
|
||||
codeStyleManager.reformatNewlyAddedElement(last.node.treeParent, last.node)
|
||||
}
|
||||
return PsiChildRange(first, last)
|
||||
PsiChildRange(first, last)
|
||||
}
|
||||
else {
|
||||
placeholder.delete()
|
||||
PsiChildRange.EMPTY
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,8 @@ fun <TElement : KtElement> createByPattern(pattern: String, vararg args: Any, re
|
||||
.sortedByDescending { it.startOffset }
|
||||
|
||||
// reformat whole text except for String arguments (as they can contain user's formatting to be preserved)
|
||||
if (stringPlaceholderRanges.none()) {
|
||||
resultElement = codeStyleManager.reformat(resultElement, true) as TElement
|
||||
resultElement = if (stringPlaceholderRanges.none()) {
|
||||
codeStyleManager.reformat(resultElement, true) as TElement
|
||||
}
|
||||
else {
|
||||
var bound = resultElement.endOffset - 1
|
||||
@@ -165,7 +165,7 @@ fun <TElement : KtElement> createByPattern(pattern: String, vararg args: Any, re
|
||||
resultElement = codeStyleManager.reformatRange(resultElement, range.endOffset + start, bound + 1, true) as TElement
|
||||
bound = range.startOffset + start
|
||||
}
|
||||
resultElement = codeStyleManager.reformatRange(resultElement, start, bound + 1, true) as TElement
|
||||
codeStyleManager.reformatRange(resultElement, start, bound + 1, true) as TElement
|
||||
}
|
||||
|
||||
// do not reformat the whole expression in PostprocessReformattingAspect
|
||||
|
||||
@@ -164,18 +164,17 @@ object CastDiagnosticsUtil {
|
||||
val variables = subtypeWithVariables.constructor.parameters
|
||||
val variableConstructors = variables.map { descriptor -> descriptor.typeConstructor }.toSet()
|
||||
|
||||
val substitution: MutableMap<TypeConstructor, TypeProjection>
|
||||
if (supertypeWithVariables != null) {
|
||||
val substitution: MutableMap<TypeConstructor, TypeProjection> = if (supertypeWithVariables != null) {
|
||||
// Now, let's try to unify Collection<T> and Collection<Foo> solution is a map from T to Foo
|
||||
val solution = TypeUnifier.unify(
|
||||
TypeProjectionImpl(supertype), TypeProjectionImpl(supertypeWithVariables), variableConstructors::contains
|
||||
)
|
||||
substitution = Maps.newHashMap(solution.substitution)
|
||||
Maps.newHashMap(solution.substitution)
|
||||
}
|
||||
else {
|
||||
// If there's no corresponding supertype, no variables are determined
|
||||
// This may be OK, e.g. in case 'Any as List<*>'
|
||||
substitution = Maps.newHashMapWithExpectedSize<TypeConstructor, TypeProjection>(variables.size)
|
||||
Maps.newHashMapWithExpectedSize<TypeConstructor, TypeProjection>(variables.size)
|
||||
}
|
||||
|
||||
// If some of the parameters are not determined by unification, it means that these parameters are lost,
|
||||
|
||||
Reference in New Issue
Block a user