If then to elvis: applied in IDEA, front-end & J2K modules
This commit is contained in:
@@ -369,11 +369,8 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
startLabel: Label?, finishLabel: Label?,
|
||||
labelCountArg: Int): Int {
|
||||
var labelCount = labelCountArg
|
||||
val startIndex = if (startLabel != null) startLabel.targetInstructionIndex else 0
|
||||
val finishIndex = if (finishLabel != null)
|
||||
finishLabel.targetInstructionIndex
|
||||
else
|
||||
originalPseudocode.mutableInstructionList.size
|
||||
val startIndex = startLabel?.targetInstructionIndex ?: 0
|
||||
val finishIndex = finishLabel?.targetInstructionIndex ?: originalPseudocode.mutableInstructionList.size
|
||||
|
||||
val originalToCopy = Maps.newLinkedHashMap<Label, PseudocodeLabel>()
|
||||
val originalLabelsForInstruction = HashMultimap.create<Instruction, Label>()
|
||||
|
||||
@@ -196,7 +196,7 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
|
||||
override fun visitPropertyAccessor(accessor: KtPropertyAccessor, data: Unit?): String? {
|
||||
val containingProperty = KtStubbedPsiUtil.getContainingDeclaration(accessor, KtProperty::class.java)
|
||||
val what = (if (accessor.isGetter()) "getter" else "setter")
|
||||
return what + " for " + (if (containingProperty != null) containingProperty.getDebugText() else "...")
|
||||
return what + " for " + (containingProperty?.getDebugText() ?: "...")
|
||||
}
|
||||
|
||||
override fun visitClass(klass: KtClass, data: Unit?): String? {
|
||||
|
||||
@@ -225,7 +225,7 @@ private fun processPattern(pattern: String, args: List<Any>): PatternData {
|
||||
|
||||
val arg: Any? = if (n < args.size) args[n] else null /* report wrong number of arguments later */
|
||||
val placeholderText = if (charOrNull(i) != ':' || charOrNull(i + 1) != '\'') {
|
||||
if (arg is String) arg else "xyz"
|
||||
arg as? String ?: "xyz"
|
||||
}
|
||||
else {
|
||||
check(arg !is String, "do not specify placeholder text for $$n - plain text argument passed")
|
||||
|
||||
+10
-10
@@ -109,11 +109,11 @@ object AnnotationUseSiteTargetChecker {
|
||||
private fun BindingTrace.checkIfMutableProperty(annotated: KtAnnotated, annotation: KtAnnotationEntry) {
|
||||
if (!checkIfProperty(annotated, annotation)) return
|
||||
|
||||
val isMutable = if (annotated is KtProperty)
|
||||
annotated.isVar
|
||||
else if (annotated is KtParameter)
|
||||
annotated.isMutable
|
||||
else false
|
||||
val isMutable = when (annotated) {
|
||||
is KtProperty -> annotated.isVar
|
||||
is KtParameter -> annotated.isMutable
|
||||
else -> false
|
||||
}
|
||||
|
||||
if (!isMutable) {
|
||||
report(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE.on(annotation, annotation.useSiteDescription()))
|
||||
@@ -121,11 +121,11 @@ object AnnotationUseSiteTargetChecker {
|
||||
}
|
||||
|
||||
private fun BindingTrace.checkIfProperty(annotated: KtAnnotated, annotation: KtAnnotationEntry): Boolean {
|
||||
val isProperty = if (annotated is KtProperty)
|
||||
!annotated.isLocal
|
||||
else if (annotated is KtParameter)
|
||||
annotated.hasValOrVar()
|
||||
else false
|
||||
val isProperty = when (annotated) {
|
||||
is KtProperty -> !annotated.isLocal
|
||||
is KtParameter -> annotated.hasValOrVar()
|
||||
else -> false
|
||||
}
|
||||
|
||||
if (!isProperty) report(INAPPLICABLE_TARGET_ON_PROPERTY.on(annotation, annotation.useSiteDescription()))
|
||||
return isProperty
|
||||
|
||||
@@ -64,10 +64,7 @@ object OperatorModifierChecker {
|
||||
return
|
||||
}
|
||||
|
||||
val errorDescription = if (checkResult is CheckResult.IllegalSignature)
|
||||
checkResult.error
|
||||
else
|
||||
"illegal function name"
|
||||
val errorDescription = (checkResult as? CheckResult.IllegalSignature)?.error ?: "illegal function name"
|
||||
|
||||
diagnosticHolder.report(Errors.INAPPLICABLE_OPERATOR_MODIFIER.on(modifier, errorDescription))
|
||||
}
|
||||
|
||||
@@ -100,10 +100,8 @@ class TypeAliasExpander(
|
||||
val originalVariance =
|
||||
if (originalProjection.projectionKind != Variance.INVARIANT)
|
||||
originalProjection.projectionKind
|
||||
else if (typeParameterDescriptor != null)
|
||||
typeParameterDescriptor.variance
|
||||
else
|
||||
Variance.INVARIANT
|
||||
typeParameterDescriptor?.variance ?: Variance.INVARIANT
|
||||
|
||||
val argumentVariance = typeAliasArgument.projectionKind
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.types.expressions.CaptureKind
|
||||
|
||||
class CapturingInClosureChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val variableResolvedCall = if (resolvedCall is VariableAsFunctionResolvedCall) resolvedCall.variableCall else resolvedCall
|
||||
val variableResolvedCall = (resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall ?: resolvedCall
|
||||
val variableDescriptor = variableResolvedCall.resultingDescriptor as? VariableDescriptor
|
||||
if (variableDescriptor != null) {
|
||||
checkCapturingInClosure(variableDescriptor, context.trace, context.scope)
|
||||
|
||||
+1
-5
@@ -33,11 +33,7 @@ object ProtectedConstructorCallChecker : CallChecker {
|
||||
val constructorOwner = descriptor.containingDeclaration.original
|
||||
val scopeOwner = context.scope.ownerDescriptor
|
||||
|
||||
val actualConstructor =
|
||||
if (descriptor is TypeAliasConstructorDescriptor)
|
||||
descriptor.underlyingConstructorDescriptor
|
||||
else
|
||||
descriptor
|
||||
val actualConstructor = (descriptor as? TypeAliasConstructorDescriptor)?.underlyingConstructorDescriptor ?: descriptor
|
||||
|
||||
if (actualConstructor.visibility.normalize() != Visibilities.PROTECTED) return
|
||||
// Error already reported
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ class CompoundConstraintPosition(vararg positions: ConstraintPosition) : Constra
|
||||
get() = COMPOUND_CONSTRAINT_POSITION
|
||||
|
||||
val positions: Collection<ConstraintPosition> =
|
||||
positions.flatMap { if (it is CompoundConstraintPosition) it.positions else listOf(it) }.toSet()
|
||||
positions.flatMap { (it as? CompoundConstraintPosition)?.positions ?: listOf(it) }.toSet()
|
||||
|
||||
override fun isStrong() = positions.any { it.isStrong() }
|
||||
|
||||
|
||||
+1
-6
@@ -82,12 +82,7 @@ internal class DelegatingDataFlowInfo private constructor(
|
||||
key.immanentNullability
|
||||
}
|
||||
else {
|
||||
nullabilityInfo[key] ?: if (parent != null) {
|
||||
parent.getCollectedNullability(key)
|
||||
}
|
||||
else {
|
||||
key.immanentNullability
|
||||
}
|
||||
nullabilityInfo[key] ?: parent?.getCollectedNullability(key) ?: key.immanentNullability
|
||||
}
|
||||
|
||||
private fun putNullability(map: MutableMap<DataFlowValue, Nullability>, value: DataFlowValue,
|
||||
|
||||
+2
-2
@@ -134,8 +134,8 @@ open class KotlinScriptDefinitionFromAnnotatedTemplate(
|
||||
}
|
||||
|
||||
private fun getAnnotationEntriesFromPsiFile(file: PsiFile) =
|
||||
if (file is KtFile) file.annotationEntries
|
||||
else throw IllegalArgumentException("Unable to extract kotlin annotations from ${file.name} (${file.fileType})")
|
||||
(file as? KtFile)?.annotationEntries
|
||||
?: throw IllegalArgumentException("Unable to extract kotlin annotations from ${file.name} (${file.fileType})")
|
||||
|
||||
private fun getAnnotationEntriesFromVirtualFile(file: VirtualFile, project: Project): Iterable<KtAnnotationEntry> {
|
||||
val psiFile: PsiFile = PsiManager.getInstance(project).findFile(file)
|
||||
|
||||
Reference in New Issue
Block a user