mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[json + yaml] IJPL-163460 Implement fast exit for yaml deprecation inspection
There is no point in traversing schema if there are no deprecated nodes specified in it. So we first index the in-memory schema instance and perform fast exit in case no deprecation keywords were detected (cherry picked from commit decd0a968fa3e04326b4fdeec3cdab01563439fb) IJ-CR-147983 GitOrigin-RevId: 2f816ec1c9867bf9b81f560524917d274705fc1a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6e429ddce0
commit
4a273f51d8
@@ -16,6 +16,7 @@ import org.jetbrains.annotations.ApiStatus
|
||||
private val IDS_MAP_KEY = Key<Map<String, String>>("ids")
|
||||
private val DYNAMIC_ANCHORS_MAP_KEY = Key<Map<String, String>>("dynamicAnchors")
|
||||
private val INJECTIONS_MAP_KEY = Key<Boolean>("injections")
|
||||
private val DEPRECATIONS_MAP_KEY = Key<Boolean>("deprecations")
|
||||
|
||||
@ApiStatus.Internal
|
||||
class RootJsonSchemaObjectBackedByJackson(rootNode: JsonNode, val schemaFile: VirtualFile?)
|
||||
@@ -43,6 +44,18 @@ class RootJsonSchemaObjectBackedByJackson(rootNode: JsonNode, val schemaFile: Vi
|
||||
}
|
||||
}
|
||||
|
||||
fun checkHasDeprecations(): Boolean {
|
||||
val deprecationMarker = schemaInterpretationStrategy.deprecationKeyword ?: return false
|
||||
return getOrComputeValue(DEPRECATIONS_MAP_KEY) {
|
||||
indexSchema(rawSchemaNode) { _, parentPointer ->
|
||||
if (parentPointer.lastOrNull() == deprecationMarker)
|
||||
true
|
||||
else
|
||||
null
|
||||
}.any { it }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFileUrl(): String? {
|
||||
return schemaFile?.url
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.jetbrains.jsonSchema.extension.JsonLikePsiWalker;
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaObject;
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaResolver;
|
||||
import com.jetbrains.jsonSchema.impl.MatchResult;
|
||||
import com.jetbrains.jsonSchema.impl.light.nodes.RootJsonSchemaObjectBackedByJackson;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.yaml.YAMLBundle;
|
||||
import org.jetbrains.yaml.psi.YAMLKeyValue;
|
||||
@@ -24,9 +25,13 @@ public class YamlJsonSchemaDeprecationInspection extends YamlJsonSchemaInspectio
|
||||
@NotNull LocalInspectionToolSession session,
|
||||
Collection<PsiElement> roots,
|
||||
JsonSchemaObject schema) {
|
||||
if (schema == null || (schema instanceof RootJsonSchemaObjectBackedByJackson rootSchema && !rootSchema.checkHasDeprecations())) {
|
||||
return PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
|
||||
PsiElement sampleElement = roots.iterator().next();
|
||||
final JsonLikePsiWalker walker = JsonLikePsiWalker.getWalker(sampleElement, schema);
|
||||
if (walker == null || schema == null) {
|
||||
if (walker == null) {
|
||||
return PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
Project project = sampleElement.getProject();
|
||||
|
||||
Reference in New Issue
Block a user