[Workspace Model] Add inspection to report usages of maps with primitive values in intellij.platform.workspace.storage module

GitOrigin-RevId: 0b53878cf55919714135485f551a84ddd3d9f25c
This commit is contained in:
Alex Plate
2023-11-21 18:10:51 +02:00
committed by intellij-monorepo-bot
parent 4340daf8b1
commit e76bd36be0
4 changed files with 31 additions and 1 deletions

View File

@@ -1140,6 +1140,26 @@
<replaceConfiguration name="Disposable instance by lambda" description="It's not safe to instantiate Disposable via lambda because lambdas does not guarantee their identity." text="Disposable { }" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.openapi.util.Disposer.newDisposable()">
<constraint name="__context__" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Do not use maps with primitive value" description="It's very easy to forget to set the default return value&#10;Use the map that guarantee the default map like Int2IntWithDefaultMap&#10;See IDEA-338250 as issue example" suppressId="NoMapsWithPrimitiveValue" text="Int2IntMap" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.platform.workspace.storage.impl.containers.Int2IntWithDefaultMap">
<constraint name="__context__" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Do not use maps with primitive value" text="Int2IntOpenHashMap()" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.platform.workspace.storage.impl.containers.Int2IntWithDefaultMap()">
<constraint name="__context__" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Do not use maps with primitive value" text="Int2IntOpenHashMap($source$)" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.platform.workspace.storage.impl.containers.Int2IntWithDefaultMap.from($source$)">
<constraint name="__context__" within="" contains="" />
<constraint name="source" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Do not use maps with primitive value" text="Object2IntOpenHashMap($source$)" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.platform.workspace.storage.impl.containers.Object2IntWithDefaultMap.from($source$)">
<constraint name="__context__" within="" contains="" />
<constraint name="source" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Do not use maps with primitive value" text="Object2IntOpenHashMap()" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.platform.workspace.storage.impl.containers.Object2IntWithDefaultMap()">
<constraint name="__context__" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Do not use maps with primitive value" text="Object2IntMap" recursive="false" caseInsensitive="false" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.platform.workspace.storage.impl.containers.Object2IntWithDefaultMap">
<constraint name="__context__" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Don't read channels with for, use consume/consumeEach" suppressId="CHAN_WITH_FOR" text="for ($Item$ in $Collection$) {&#10; $Statement$&#10;}" recursive="false" caseInsensitive="true" type="Kotlin" pattern_context="default" reformatAccordingToStyle="true" shortenFQN="false" replacement="$Collection$.consumeEach { $Item$ -&gt;&#10; $Statement$&#10;}">
<constraint name="__context__" within="" contains="" />
<constraint name="Item" within="" contains="" />
@@ -2539,6 +2559,9 @@
<inspection_tool class="XsltTemplateInvocation" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="XsltUnusedDeclaration" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="XsltVariableShadowing" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="acb41802-9e8a-3e32-8b29-0e1d0a2aa770" enabled="true" level="WARNING" enabled_by_default="false">
<scope name="EntityStorage" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="osmorcClassInDefaultPackage" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="osmorcNonOsgiMavenDependency" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="osmorcUnknownManifestPackage" enabled="false" level="ERROR" enabled_by_default="false" />

3
.idea/scopes/EntityStorage.xml generated Normal file
View File

@@ -0,0 +1,3 @@
<component name="DependencyValidationManager">
<scope name="EntityStorage" pattern="file[intellij.platform.workspace.storage]:*/||file[intellij.platform.workspace.storage.testEntities]:*/||file[intellij.platform.workspace.storage.tests]:*/" />
</component>

View File

@@ -1,4 +1,6 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("NoMapsWithPrimitiveValue")
package com.intellij.platform.workspace.storage.impl.containers
import com.intellij.platform.workspace.storage.impl.containers.Int2IntWithDefaultMap.Companion.DEFAULT_VALUE

View File

@@ -1,10 +1,12 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("NoMapsWithPrimitiveValue")
package com.intellij.platform.workspace.storage.impl.containers
import com.intellij.platform.workspace.storage.impl.containers.Int2IntWithDefaultMap.Companion.DEFAULT_VALUE
import com.intellij.platform.workspace.storage.impl.containers.Object2IntWithDefaultMap.Companion.DEFAULT_VALUE
import it.unimi.dsi.fastutil.ints.IntCollection
import it.unimi.dsi.fastutil.objects.Object2IntMap
import it.unimi.dsi.fastutil.ints.IntCollection
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
import java.util.function.BiConsumer
import java.util.function.ToIntFunction