IJPL-159596 better "resource not found" error handling

GitOrigin-RevId: fbe4d2023505b2090cfd3a1935899904ece6e347
This commit is contained in:
Vladimir Krivosheev
2024-08-05 10:41:18 +02:00
committed by intellij-monorepo-bot
parent 4da400b597
commit 3d0f2a0265
2 changed files with 40 additions and 40 deletions

View File

@@ -197,7 +197,7 @@ open class ExternalResourceManagerExImpl : ExternalResourceManagerEx(), Persiste
if (XmlUtil.XML_SCHEMA_URI == url) {
return XSD_1_1
}
if ((XmlUtil.XML_SCHEMA_URI + ".xsd") == url) {
if ("${XmlUtil.XML_SCHEMA_URI}.xsd" == url) {
return XSD_1_1
}
}
@@ -205,13 +205,12 @@ open class ExternalResourceManagerExImpl : ExternalResourceManagerEx(), Persiste
}
override fun getResourceLocation(url: @NonNls String, baseFile: PsiFile, version: String?): PsiFile? {
val schema = XmlSchemaProvider.findSchema(url, baseFile)
if (schema != null) {
return schema
XmlSchemaProvider.findSchema(url, baseFile)?.let {
return it
}
val location = getResourceLocation(url, version, baseFile.getProject())
return XmlUtil.findXmlFile(baseFile, location!!)
val location = getResourceLocation(url, version, baseFile.getProject())!!
return XmlUtil.findXmlFile(baseFile, location)
}
override fun getResourceUrls(fileType: FileType?, includeStandard: Boolean): Array<String?> {

View File

@@ -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;
import com.intellij.javaee.ExternalResourceManager;
@@ -307,17 +307,17 @@ public abstract class XmlTagDelegate {
return map == null ? Collections.emptyMap() : map;
}
private static @NotNull Map<String, NullableLazyValue<XmlNSDescriptor>> initializeSchema(final @NotNull XmlTag tag,
final @Nullable String namespace,
final @Nullable String version,
final @NotNull Set<String> fileLocations,
private static @NotNull Map<String, NullableLazyValue<XmlNSDescriptor>> initializeSchema(@NotNull XmlTag tag,
@Nullable String namespace,
@Nullable String version,
@NotNull Set<String> fileLocations,
@Nullable Map<String, NullableLazyValue<XmlNSDescriptor>> map,
final boolean nsDecl) {
boolean nsDecl) {
if (map == null) {
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(() -> {
List<XmlNSDescriptor> descriptors =
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());
}
public static @NotNull XmlTag[] 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);
private @NotNull Boolean calculateHasNamespaceDeclarations() {
Ref<Boolean> result = new Ref<>(Boolean.FALSE);
processChildren(element -> {
if (element instanceof XmlAttribute
&& ((XmlAttribute)element).isNamespaceDeclaration()) {
result.set(Boolean.TRUE);
return false;
}
else if (name.equals(subTag.getLocalName()) && namespace.equals(subTag.getNamespace())) {
result.add(subTag);
}
}
return result.toArray(XmlTag.EMPTY);
return !(element instanceof XmlToken) || ((XmlToken)element).getTokenType() != XmlTokenType.XML_TAG_END;
});
return result.get();
}
@Nullable
@@ -834,32 +834,33 @@ public abstract class XmlTagDelegate {
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
Map<String, String> getLocalNamespaceDeclarations() {
Map<String, String> namespaces = new HashMap<>();
for (final XmlAttribute attribute : myTag.getAttributes()) {
if (!attribute.isNamespaceDeclaration() || attribute.getValue() == null) continue;
for (XmlAttribute attribute : myTag.getAttributes()) {
if (!attribute.isNamespaceDeclaration() || attribute.getValue() == null) {
continue;
}
// xmlns -> "", xmlns:a -> a
final String localName = attribute.getLocalName();
String localName = attribute.getLocalName();
namespaces.put(localName.equals(attribute.getName()) ? "" : localName, attribute.getValue());
}
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
XmlAttribute setAttribute(String qname, @Nullable String value) throws IncorrectOperationException {
final XmlAttribute attribute = myTag.getAttribute(qname);