use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class DomManagerImpl method createMockElement.
@Override
public final <T extends DomElement> T createMockElement(final Class<T> aClass, final Module module, final boolean physical) {
final XmlFile file = (XmlFile) PsiFileFactory.getInstance(myProject).createFileFromText("a.xml", StdFileTypes.XML, "", (long) 0, physical);
file.putUserData(MOCK_ELEMENT_MODULE, module);
file.putUserData(MOCK, new Object());
return getFileElement(file, aClass, "I_sincerely_hope_that_nobody_will_have_such_a_root_tag_name").getRootElement();
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class DomRootInvocationHandler method setEmptyXmlTag.
@Override
protected XmlTag setEmptyXmlTag() {
final XmlTag[] result = new XmlTag[] { null };
getManager().runChange(() -> {
try {
final String namespace = getXmlElementNamespace();
@NonNls final String nsDecl = StringUtil.isEmpty(namespace) ? "" : " xmlns=\"" + namespace + "\"";
final XmlFile xmlFile = getFile();
final XmlTag tag = XmlElementFactory.getInstance(xmlFile.getProject()).createTagFromText("<" + getXmlElementName() + nsDecl + "/>");
result[0] = ((XmlDocument) xmlFile.getDocument().replace(((XmlFile) tag.getContainingFile()).getDocument())).getRootTag();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
return result[0];
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class IndexedElementInvocationHandler method setEmptyXmlTag.
@Override
protected XmlTag setEmptyXmlTag() {
final DomInvocationHandler parent = getParentHandler();
assert parent != null : "write operations should be performed on the DOM having a parent, your DOM may be not very fresh";
final FixedChildDescriptionImpl description = getChildDescription();
final XmlFile xmlFile = getFile();
parent.createFixedChildrenTags(getXmlName(), description, myIndex);
final List<XmlTag> tags = DomImplUtil.findSubTags(parent.getXmlTag(), getXmlName(), xmlFile);
if (tags.size() > myIndex) {
return tags.get(myIndex);
}
final XmlTag[] newTag = new XmlTag[1];
getManager().runChange(() -> {
try {
final XmlTag parentTag = parent.getXmlTag();
newTag[0] = (XmlTag) parentTag.add(parent.createChildTag(getXmlName()));
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
return newTag[0];
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlNamespaceIndex method guessDtd.
@Nullable
public static XmlFile guessDtd(String dtdUri, @NotNull PsiFile baseFile) {
if (!dtdUri.endsWith(".dtd") || DumbService.isDumb(baseFile.getProject()) || XmlUtil.isStubBuilding())
return null;
String dtdFileName = new File(dtdUri).getName();
List<IndexedRelevantResource<String, XsdNamespaceBuilder>> list = getResourcesByNamespace(dtdFileName, baseFile.getProject(), ModuleUtilCore.findModuleForPsiElement(baseFile));
if (list.isEmpty()) {
return null;
}
IndexedRelevantResource<String, XsdNamespaceBuilder> resource;
if (list.size() > 1) {
final String[] split = dtdUri.split("/");
resource = Collections.max(list, new Comparator<IndexedRelevantResource<String, XsdNamespaceBuilder>>() {
@Override
public int compare(IndexedRelevantResource<String, XsdNamespaceBuilder> o1, IndexedRelevantResource<String, XsdNamespaceBuilder> o2) {
return weight(o1) - weight(o2);
}
int weight(IndexedRelevantResource<String, XsdNamespaceBuilder> o1) {
VirtualFile file = o1.getFile();
for (int i = split.length - 1; i >= 0 && file != null; i--) {
String s = split[i];
if (!s.equals(file.getName())) {
return split.length - i;
}
file = file.getParent();
}
return 0;
}
});
} else {
resource = list.get(0);
}
return findSchemaFile(resource.getFile(), baseFile);
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class HtmlPsiUtil method getRealXmlDocument.
@Nullable
public static XmlDocument getRealXmlDocument(@Nullable XmlDocument doc) {
if (doc == null)
return null;
final PsiFile containingFile = doc.getContainingFile();
final PsiFile templateFile = TemplateLanguageUtil.getTemplateFile(containingFile);
if (templateFile instanceof XmlFile) {
return ((XmlFile) templateFile).getDocument();
}
return doc;
}
Aggregations