Search in sources :

Example 1 with CodeInsightProviders

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

the class JsonSchemaServiceImpl method getWrappers.

@NotNull
private List<CodeInsightProviders> getWrappers(@Nullable VirtualFile file) {
    if (file == null)
        return Collections.emptyList();
    final FileType type = file.getFileType();
    final boolean isJson = type instanceof LanguageFileType && ((LanguageFileType) type).getLanguage().isKindOf(JsonLanguage.INSTANCE);
    final List<CodeInsightProviders> wrappers = new SmartList<>();
    getWrapperSkeletonMethod(provider -> (isJson || !SchemaType.userSchema.equals(provider.getSchemaType())) && provider.isAvailable(myProject, file), wrapper -> wrappers.add(wrapper), true);
    return wrappers;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) CodeInsightProviders(com.jetbrains.jsonSchema.CodeInsightProviders) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CodeInsightProviders

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

the class JsonSchemaServiceImpl method getSchemaFilesByFile.

@Override
@Nullable
public Collection<Pair<VirtualFile, String>> getSchemaFilesByFile(@NotNull final VirtualFile file) {
    final CodeInsightProviders wrapper = getWrapper(file);
    if (wrapper != null) {
        final List<Pair<VirtualFile, String>> result = new SmartList<>();
        wrapper.iterateSchemaFiles((schemaFile, schemaId) -> result.add(Pair.create(schemaFile, schemaId)));
        return result;
    }
    return null;
}
Also used : CodeInsightProviders(com.jetbrains.jsonSchema.CodeInsightProviders) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CodeInsightProviders

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

the class JsonSchemaServiceImpl method visitSchemaObject.

@Override
public void visitSchemaObject(@NotNull final VirtualFile schemaFile, @NotNull Processor<JsonSchemaObject> consumer) {
    final CodeInsightProviders wrapper = getWrapperBySchemaFile(schemaFile);
    if (wrapper == null)
        return;
    wrapper.iterateSchemaObjects(consumer);
}
Also used : CodeInsightProviders(com.jetbrains.jsonSchema.CodeInsightProviders)

Example 4 with CodeInsightProviders

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

the class JsonSchemaServiceImpl method getWrapperBySchemaFile.

@Nullable
private CodeInsightProviders getWrapperBySchemaFile(@NotNull final VirtualFile schemaFile) {
    synchronized (myLock) {
        CodeInsightProviders wrapper = myWrappers.get(schemaFile);
        if (wrapper != null)
            return wrapper;
    }
    final Ref<CodeInsightProviders> ref = new Ref<>();
    getWrapperSkeletonMethod(provider -> schemaFile.equals(provider.getSchemaFile()), wrapper -> ref.set(wrapper), false);
    return ref.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) CodeInsightProviders(com.jetbrains.jsonSchema.CodeInsightProviders) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CodeInsightProviders

use of com.jetbrains.jsonSchema.CodeInsightProviders 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

CodeInsightProviders (com.jetbrains.jsonSchema.CodeInsightProviders)5 Pair (com.intellij.openapi.util.Pair)2 Nullable (org.jetbrains.annotations.Nullable)2 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JsonSchemaFileProvider (com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider)1 NotNull (org.jetbrains.annotations.NotNull)1