Search in sources :

Example 1 with JsonSchemaFileProvider

use of com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider in project intellij-community by JetBrains.

the class JsonSchemaServiceImpl method ensureSchemaFiles.

private void ensureSchemaFiles() {
    synchronized (myLock) {
        if (!initialized) {
            for (JsonSchemaFileProvider provider : getProviders()) {
                final VirtualFile schemaFile = provider.getSchemaFile();
                if (schemaFile != null) {
                    mySchemaFiles.add(schemaFile);
                    // this will make it refresh
                    myDefinitions.dropKey(schemaFile);
                    myWrappers.remove(schemaFile);
                }
            }
            initialized = true;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JsonSchemaFileProvider(com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider)

Example 2 with JsonSchemaFileProvider

use of com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider in project intellij-community by JetBrains.

the class JsonSchemaServiceImpl method getProviders.

private List<JsonSchemaFileProvider> getProviders() {
    final List<JsonSchemaFileProvider> providers = new ArrayList<>();
    for (JsonSchemaProviderFactory factory : getProviderFactories()) {
        providers.addAll(factory.getProviders(myProject));
    }
    Collections.sort(providers, FILE_PROVIDER_COMPARATOR);
    return providers;
}
Also used : JsonSchemaFileProvider(com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider) JsonSchemaProviderFactory(com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory)

Example 3 with JsonSchemaFileProvider

use of com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider in project intellij-community by JetBrains.

the class JsonSchemaServiceImpl method getWrapperSkeletonMethod.

private void getWrapperSkeletonMethod(@NotNull final Processor<JsonSchemaFileProvider> processor, @NotNull final Consumer<CodeInsightProviders> consumer, final boolean multiple) {
    final List<JsonSchemaFileProvider> filtered = getProviders().stream().filter(processor::process).collect(Collectors.toList());
    if (filtered.isEmpty())
        return;
    final List<JsonSchemaFileProvider> matchingProviders = new SmartList<>();
    synchronized (myLock) {
        for (JsonSchemaFileProvider provider : filtered) {
            final CodeInsightProviders wrapper = myWrappers.get(provider.getSchemaFile());
            if (wrapper != null) {
                consumer.consume(wrapper);
                if (!multiple)
                    return;
            } else {
                matchingProviders.add(provider);
                if (!multiple)
                    break;
            }
        }
    }
    if (matchingProviders.isEmpty())
        return;
    final Map<VirtualFile, Pair<CodeInsightProviders, JsonSchemaFileProvider>> created = new HashMap<>();
    for (JsonSchemaFileProvider provider : matchingProviders) {
        // read action taken here => without wrapping lock
        final CodeInsightProviders wrapper = createWrapper(provider);
        if (wrapper != null)
            created.put(provider.getSchemaFile(), Pair.create(wrapper, provider));
    }
    final List<JsonSchemaFileProvider> providers = getProviders();
    synchronized (myLock) {
        created.forEach((file, pair) -> {
            final CodeInsightProviders wrapper = pair.getFirst();
            final JsonSchemaFileProvider provider = pair.getSecond();
            // check again, providers could have changed
            if (!providers.contains(provider))
                return;
            // check again, rules could have changed
            if (processor.process(provider)) {
                myWrappers.putIfAbsent(file, wrapper);
                consumer.consume(wrapper);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeInsightProviders(com.jetbrains.jsonSchema.CodeInsightProviders) JsonSchemaFileProvider(com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider) Pair(com.intellij.openapi.util.Pair)

Aggregations

JsonSchemaFileProvider (com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Pair (com.intellij.openapi.util.Pair)1 CodeInsightProviders (com.jetbrains.jsonSchema.CodeInsightProviders)1 JsonSchemaProviderFactory (com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory)1