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;
}
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;
}
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);
}
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();
}
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);
}
});
}
}
Aggregations