Search in sources :

Example 1 with JsonSchemaObject

use of com.jetbrains.jsonSchema.impl.JsonSchemaObject in project intellij-community by JetBrains.

the class JsonSchemaInsideSchemaResolver method resolveInSchemaRecursively.

public PsiElement resolveInSchemaRecursively() {
    final Ref<PsiElement> ref = new Ref<>();
    final JsonSchemaWalker.CompletionSchemesConsumer consumer = new JsonSchemaWalker.CompletionSchemesConsumer() {

        @Override
        public void consume(boolean isName, @NotNull JsonSchemaObject schema, @NotNull VirtualFile schemaFile, @NotNull List<JsonSchemaWalker.Step> steps) {
            if (!ref.isNull())
                return;
            final PsiFile file = PsiManager.getInstance(myProject).findFile(mySchemaFile);
            if (file == null)
                return;
            final JsonObject jsonObject = schema.getPeerPointer().getElement();
            if (jsonObject != null && jsonObject.isValid()) {
                if (jsonObject.getParent() instanceof JsonProperty)
                    ref.set(((JsonProperty) jsonObject.getParent()).getNameElement());
                else
                    ref.set(jsonObject);
            }
        }

        @Override
        public void oneOf(boolean isName, @NotNull List<JsonSchemaObject> list, @NotNull VirtualFile schemaFile, @NotNull List<JsonSchemaWalker.Step> steps) {
            list.stream().findFirst().ifPresent(object -> consume(isName, object, schemaFile, steps));
        }

        @Override
        public void anyOf(boolean isName, @NotNull List<JsonSchemaObject> list, @NotNull VirtualFile schemaFile, @NotNull List<JsonSchemaWalker.Step> steps) {
            list.stream().findFirst().ifPresent(object -> consume(isName, object, schemaFile, steps));
        }
    };
    JsonSchemaService.Impl.getEx(myProject).visitSchemaObject(mySchemaFile, object -> {
        JsonSchemaWalker.extractSchemaVariants(myProject, consumer, mySchemaFile, object, true, mySteps, false);
        return true;
    });
    return ref.get();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JsonProperty(com.intellij.json.psi.JsonProperty) JsonObject(com.intellij.json.psi.JsonObject) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) JsonSchemaWalker(com.jetbrains.jsonSchema.impl.JsonSchemaWalker) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) JsonSchemaObject(com.jetbrains.jsonSchema.impl.JsonSchemaObject) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JsonObject (com.intellij.json.psi.JsonObject)1 JsonProperty (com.intellij.json.psi.JsonProperty)1 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 JsonSchemaObject (com.jetbrains.jsonSchema.impl.JsonSchemaObject)1 JsonSchemaWalker (com.jetbrains.jsonSchema.impl.JsonSchemaWalker)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1