EA-38086 - CCE: XmlNamespaceIndex.guessDtd

This commit is contained in:
Dmitry Avdeev
2012-09-28 11:44:25 +04:00
parent 4d79c61a90
commit 9a9d3360e5
2 changed files with 10 additions and 4 deletions
@@ -19,6 +19,7 @@ package com.intellij.xml.index;
import com.intellij.openapi.util.Comparing;
import com.intellij.util.xml.NanoXmlUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
@@ -97,7 +98,7 @@ public class XsdNamespaceBuilder extends NanoXmlUtil.IXMLBuilderAdapter implemen
return Comparing.compare(myNamespace, o.myNamespace);
}
public int getRating(String tagName, String version) {
public int getRating(@Nullable String tagName, @Nullable String version) {
int rate = 0;
if (tagName != null && myTags.contains(tagName)) {
rate |= 0x02;
@@ -142,7 +142,7 @@ public class XmlNamespaceIndex extends XmlIndex<XsdNamespaceBuilder> {
public static IndexedRelevantResource<String, XsdNamespaceBuilder> guessSchema(String namespace,
@Nullable final String tagName,
@Nullable final String version,
Module module) {
@Nullable Module module) {
if (module == null) return null;
@@ -175,7 +175,12 @@ public class XmlNamespaceIndex extends XmlIndex<XsdNamespaceBuilder> {
IndexedRelevantResource<String,XsdNamespaceBuilder> resource =
guessSchema(namespace, tagName, version, ModuleUtilCore.findModuleForPsiElement(file));
if (resource == null) return null;
PsiFile psiFile = file.getManager().findFile(resource.getFile());
return findSchemaFile(resource.getFile(), file);
}
@Nullable
private static XmlFile findSchemaFile(VirtualFile resourceFile, PsiFile baseFile) {
PsiFile psiFile = baseFile.getManager().findFile(resourceFile);
return psiFile instanceof XmlFile ? (XmlFile)psiFile : null;
}
@@ -189,6 +194,6 @@ public class XmlNamespaceIndex extends XmlIndex<XsdNamespaceBuilder> {
String dtdFileName = new File(dtdUri).getName();
List<IndexedRelevantResource<String, XsdNamespaceBuilder>>
list = getResourcesByNamespace(dtdFileName, baseFile.getProject(), ModuleUtilCore.findModuleForPsiElement(baseFile));
return list.isEmpty() ? null : (XmlFile)baseFile.getManager().findFile(list.get(0).getFile());
return list.isEmpty() ? null : findSchemaFile(list.get(0).getFile(), baseFile);
}
}