mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
IJPL-159596 refactor XmlSchemaProvider
GitOrigin-RevId: d859bb645f949a0b494371d7b1b58c92087f1455
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ba2718bc8b
commit
18f024e481
@@ -1,78 +1,66 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.xml
|
||||
|
||||
package com.intellij.xml;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleUtilCore
|
||||
import com.intellij.openapi.project.DumbService.Companion.getInstance
|
||||
import com.intellij.openapi.project.PossiblyDumbAware
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.xml.XmlFile
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.PossiblyDumbAware;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
abstract class XmlSchemaProvider : PossiblyDumbAware {
|
||||
companion object {
|
||||
@JvmField
|
||||
val EP_NAME: ExtensionPointName<XmlSchemaProvider> = ExtensionPointName<XmlSchemaProvider>("com.intellij.xml.schemaProvider")
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public abstract class XmlSchemaProvider implements PossiblyDumbAware {
|
||||
public static final ExtensionPointName<XmlSchemaProvider> EP_NAME = new ExtensionPointName<>("com.intellij.xml.schemaProvider");
|
||||
|
||||
public abstract @Nullable XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, final @NotNull PsiFile baseFile);
|
||||
|
||||
public boolean isAvailable(final @NotNull XmlFile file) {
|
||||
return false;
|
||||
@JvmStatic
|
||||
fun getAvailableProviders(file: XmlFile): List<XmlSchemaProvider> {
|
||||
return EP_NAME.extensionList.filter { it.isAvailable(file) }
|
||||
}
|
||||
|
||||
public static @NotNull List<XmlSchemaProvider> getAvailableProviders(@NotNull XmlFile file) {
|
||||
return ContainerUtil.findAll(EP_NAME.getExtensionList(), xmlSchemaProvider -> xmlSchemaProvider.isAvailable(file));
|
||||
@JvmStatic
|
||||
fun findSchema(namespace: @NonNls String, module: Module?, file: PsiFile): XmlFile? {
|
||||
if (file.getProject().isDefault()) {
|
||||
return null
|
||||
}
|
||||
|
||||
for (provider in EP_NAME.extensionList) {
|
||||
if (!getInstance(file.getProject()).isUsableInCurrentContext(provider)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (file is XmlFile && !provider.isAvailable(file)) {
|
||||
continue
|
||||
}
|
||||
provider.getSchema(namespace, module, file)?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findSchema(namespace: @NonNls String, baseFile: PsiFile): XmlFile? {
|
||||
return findSchema(namespace = namespace, module = ModuleUtilCore.findModuleForPsiElement(baseFile), file = baseFile)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun getSchema(url: @NonNls String, module: Module?, baseFile: PsiFile): XmlFile?
|
||||
|
||||
open fun isAvailable(file: XmlFile): Boolean = false
|
||||
|
||||
/**
|
||||
* Provides specific namespaces for given XML file.
|
||||
*
|
||||
* @param file XML or JSP file.
|
||||
* @param tagName optional
|
||||
* @return available namespace uris, or {@code null} if the provider did not recognize the file.
|
||||
* @return available namespace uris, or `null` if the provider did not recognize the file.
|
||||
*/
|
||||
public @NotNull Set<String> getAvailableNamespaces(final @NotNull XmlFile file, final @Nullable String tagName) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
open fun getAvailableNamespaces(file: XmlFile, tagName: String?): Set<String> = emptySet()
|
||||
|
||||
public @Nullable String getDefaultPrefix(@NotNull @NonNls String namespace, final @NotNull XmlFile context) {
|
||||
return null;
|
||||
}
|
||||
open fun getDefaultPrefix(namespace: @NonNls String, context: XmlFile): String? = null
|
||||
|
||||
public @Nullable Set<String> getLocations(@NotNull @NonNls String namespace, final @NotNull XmlFile context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static @Nullable XmlFile findSchema(@NotNull @NonNls String namespace, @Nullable Module module, @NotNull PsiFile file) {
|
||||
if (file.getProject().isDefault()) return null;
|
||||
for (XmlSchemaProvider provider : EP_NAME.getExtensionList()) {
|
||||
if (!DumbService.getInstance(file.getProject()).isUsableInCurrentContext(provider)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file instanceof XmlFile && !provider.isAvailable((XmlFile)file)) {
|
||||
continue;
|
||||
}
|
||||
final XmlFile schema = provider.getSchema(namespace, module, file);
|
||||
if (schema != null) {
|
||||
return schema;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static @Nullable XmlFile findSchema(@NotNull @NonNls String namespace, @NotNull PsiFile baseFile) {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(baseFile);
|
||||
return findSchema(namespace, module, baseFile);
|
||||
}
|
||||
open fun getLocations(namespace: @NonNls String, context: XmlFile): Set<String>? = null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user