mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
IJPL-159596 better "resource not found" error handling
GitOrigin-RevId: fbe4d2023505b2090cfd3a1935899904ece6e347
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4da400b597
commit
3d0f2a0265
@@ -197,7 +197,7 @@ open class ExternalResourceManagerExImpl : ExternalResourceManagerEx(), Persiste
|
|||||||
if (XmlUtil.XML_SCHEMA_URI == url) {
|
if (XmlUtil.XML_SCHEMA_URI == url) {
|
||||||
return XSD_1_1
|
return XSD_1_1
|
||||||
}
|
}
|
||||||
if ((XmlUtil.XML_SCHEMA_URI + ".xsd") == url) {
|
if ("${XmlUtil.XML_SCHEMA_URI}.xsd" == url) {
|
||||||
return XSD_1_1
|
return XSD_1_1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,13 +205,12 @@ open class ExternalResourceManagerExImpl : ExternalResourceManagerEx(), Persiste
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getResourceLocation(url: @NonNls String, baseFile: PsiFile, version: String?): PsiFile? {
|
override fun getResourceLocation(url: @NonNls String, baseFile: PsiFile, version: String?): PsiFile? {
|
||||||
val schema = XmlSchemaProvider.findSchema(url, baseFile)
|
XmlSchemaProvider.findSchema(url, baseFile)?.let {
|
||||||
if (schema != null) {
|
return it
|
||||||
return schema
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val location = getResourceLocation(url, version, baseFile.getProject())
|
val location = getResourceLocation(url, version, baseFile.getProject())!!
|
||||||
return XmlUtil.findXmlFile(baseFile, location!!)
|
return XmlUtil.findXmlFile(baseFile, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getResourceUrls(fileType: FileType?, includeStandard: Boolean): Array<String?> {
|
override fun getResourceUrls(fileType: FileType?, includeStandard: Boolean): Array<String?> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
// 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.psi.impl.source.xml;
|
package com.intellij.psi.impl.source.xml;
|
||||||
|
|
||||||
import com.intellij.javaee.ExternalResourceManager;
|
import com.intellij.javaee.ExternalResourceManager;
|
||||||
@@ -307,17 +307,17 @@ public abstract class XmlTagDelegate {
|
|||||||
return map == null ? Collections.emptyMap() : map;
|
return map == null ? Collections.emptyMap() : map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NotNull Map<String, NullableLazyValue<XmlNSDescriptor>> initializeSchema(final @NotNull XmlTag tag,
|
private static @NotNull Map<String, NullableLazyValue<XmlNSDescriptor>> initializeSchema(@NotNull XmlTag tag,
|
||||||
final @Nullable String namespace,
|
@Nullable String namespace,
|
||||||
final @Nullable String version,
|
@Nullable String version,
|
||||||
final @NotNull Set<String> fileLocations,
|
@NotNull Set<String> fileLocations,
|
||||||
@Nullable Map<String, NullableLazyValue<XmlNSDescriptor>> map,
|
@Nullable Map<String, NullableLazyValue<XmlNSDescriptor>> map,
|
||||||
final boolean nsDecl) {
|
boolean nsDecl) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
map = new HashMap<>();
|
map = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We put cached value in any case to cause its value update on e.g. mapping change
|
// we put cached value in any case to cause its value update on e.g., mapping change
|
||||||
map.put(namespace, lazyNullable(() -> {
|
map.put(namespace, lazyNullable(() -> {
|
||||||
List<XmlNSDescriptor> descriptors =
|
List<XmlNSDescriptor> descriptors =
|
||||||
ContainerUtil.mapNotNull(fileLocations, s -> getDescriptor(tag, retrieveFile(tag, s, version, namespace, nsDecl), s, namespace));
|
ContainerUtil.mapNotNull(fileLocations, s -> getDescriptor(tag, retrieveFile(tag, s, version, namespace, nsDecl), s, namespace));
|
||||||
@@ -614,17 +614,17 @@ public abstract class XmlTagDelegate {
|
|||||||
return findSubTags(name, namespace, myTag.getSubTags());
|
return findSubTags(name, namespace, myTag.getSubTags());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull XmlTag[] findSubTags(@NotNull String name, @Nullable String namespace, XmlTag[] subTags) {
|
private @NotNull Boolean calculateHasNamespaceDeclarations() {
|
||||||
final List<XmlTag> result = new ArrayList<>();
|
Ref<Boolean> result = new Ref<>(Boolean.FALSE);
|
||||||
for (final XmlTag subTag : subTags) {
|
processChildren(element -> {
|
||||||
if (namespace == null) {
|
if (element instanceof XmlAttribute
|
||||||
if (name.equals(subTag.getName())) result.add(subTag);
|
&& ((XmlAttribute)element).isNamespaceDeclaration()) {
|
||||||
|
result.set(Boolean.TRUE);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if (name.equals(subTag.getLocalName()) && namespace.equals(subTag.getNamespace())) {
|
return !(element instanceof XmlToken) || ((XmlToken)element).getTokenType() != XmlTokenType.XML_TAG_END;
|
||||||
result.add(subTag);
|
});
|
||||||
}
|
return result.get();
|
||||||
}
|
|
||||||
return result.toArray(XmlTag.EMPTY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -834,32 +834,33 @@ public abstract class XmlTagDelegate {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NotNull Boolean calculateHasNamespaceDeclarations() {
|
|
||||||
final Ref<Boolean> result = new Ref<>(Boolean.FALSE);
|
|
||||||
processChildren(element -> {
|
|
||||||
if (element instanceof XmlAttribute
|
|
||||||
&& ((XmlAttribute)element).isNamespaceDeclaration()) {
|
|
||||||
result.set(Boolean.TRUE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !(element instanceof XmlToken)
|
|
||||||
|| ((XmlToken)element).getTokenType() != XmlTokenType.XML_TAG_END;
|
|
||||||
});
|
|
||||||
return result.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Map<String, String> getLocalNamespaceDeclarations() {
|
Map<String, String> getLocalNamespaceDeclarations() {
|
||||||
Map<String, String> namespaces = new HashMap<>();
|
Map<String, String> namespaces = new HashMap<>();
|
||||||
for (final XmlAttribute attribute : myTag.getAttributes()) {
|
for (XmlAttribute attribute : myTag.getAttributes()) {
|
||||||
if (!attribute.isNamespaceDeclaration() || attribute.getValue() == null) continue;
|
if (!attribute.isNamespaceDeclaration() || attribute.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// xmlns -> "", xmlns:a -> a
|
// xmlns -> "", xmlns:a -> a
|
||||||
final String localName = attribute.getLocalName();
|
String localName = attribute.getLocalName();
|
||||||
namespaces.put(localName.equals(attribute.getName()) ? "" : localName, attribute.getValue());
|
namespaces.put(localName.equals(attribute.getName()) ? "" : localName, attribute.getValue());
|
||||||
}
|
}
|
||||||
return namespaces;
|
return namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NotNull XmlTag @NotNull [] findSubTags(@NotNull String name, @Nullable String namespace, XmlTag[] subTags) {
|
||||||
|
final List<XmlTag> result = new ArrayList<>();
|
||||||
|
for (final XmlTag subTag : subTags) {
|
||||||
|
if (namespace == null) {
|
||||||
|
if (name.equals(subTag.getName())) result.add(subTag);
|
||||||
|
}
|
||||||
|
else if (name.equals(subTag.getLocalName()) && namespace.equals(subTag.getNamespace())) {
|
||||||
|
result.add(subTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toArray(XmlTag.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
XmlAttribute setAttribute(String qname, @Nullable String value) throws IncorrectOperationException {
|
XmlAttribute setAttribute(String qname, @Nullable String value) throws IncorrectOperationException {
|
||||||
final XmlAttribute attribute = myTag.getAttribute(qname);
|
final XmlAttribute attribute = myTag.getAttribute(qname);
|
||||||
|
|||||||
Reference in New Issue
Block a user