mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-92208 Zen Coding does not work when the .xml extension does not map to XML file type
This commit is contained in:
@@ -35,6 +35,9 @@ public abstract class PsiFileFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Please use {@link #createFileFromText(String, com.intellij.openapi.fileTypes.FileType, CharSequence)},
|
||||
* since file type detecting by file extension becomes vulnerable when file type mappings are changed.
|
||||
*
|
||||
* Creates a file from the specified text.
|
||||
*
|
||||
* @param name the name of the file to create (the extension of the name determines the file type).
|
||||
@@ -42,6 +45,7 @@ public abstract class PsiFileFactory {
|
||||
* @return the created file.
|
||||
* @throws com.intellij.util.IncorrectOperationException if the file type with specified extension is binary.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public abstract PsiFile createFileFromText(@NotNull @NonNls String name, @NotNull @NonNls String text);
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.ide.highlighter.XHtmlFileType;
|
||||
import com.intellij.ide.highlighter.XmlFileType;
|
||||
import com.intellij.lang.ASTFactory;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.xml.XMLLanguage;
|
||||
@@ -44,7 +46,7 @@ public class XmlElementFactoryImpl extends XmlElementFactory {
|
||||
assert language instanceof XMLLanguage:"Tag can be created only for xml language";
|
||||
FileType type = language.getAssociatedFileType();
|
||||
if (type == null) type = StdFileTypes.XML;
|
||||
final XmlDocument document = createXmlDocument(text, "dummy."+ type.getDefaultExtension());
|
||||
final XmlDocument document = createXmlDocument(text, "dummy."+ type.getDefaultExtension(), type);
|
||||
final XmlTag tag = document.getRootTag();
|
||||
if (tag == null) throw new IncorrectOperationException("Incorrect tag text");
|
||||
return tag;
|
||||
@@ -66,7 +68,8 @@ public class XmlElementFactoryImpl extends XmlElementFactory {
|
||||
quoteChar = '"';
|
||||
value = StringUtil.replace(value, "\"", """);
|
||||
}
|
||||
final XmlDocument document = createXmlDocument("<tag " + name + "=" + quoteChar + value + quoteChar + "/>", "dummy.xml");
|
||||
final XmlDocument document = createXmlDocument("<tag " + name + "=" + quoteChar + value + quoteChar + "/>", "dummy.xml",
|
||||
XmlFileType.INSTANCE);
|
||||
XmlTag tag = document.getRootTag();
|
||||
assert tag != null;
|
||||
return tag.getAttributes()[0];
|
||||
@@ -82,14 +85,14 @@ public class XmlElementFactoryImpl extends XmlElementFactory {
|
||||
|
||||
@NotNull
|
||||
public XmlTag createXHTMLTagFromText(@NotNull String text) throws IncorrectOperationException {
|
||||
final XmlDocument document = createXmlDocument(text, "dummy.xhtml");
|
||||
final XmlDocument document = createXmlDocument(text, "dummy.xhtml", XHtmlFileType.INSTANCE);
|
||||
final XmlTag tag = document.getRootTag();
|
||||
assert tag != null;
|
||||
return tag;
|
||||
}
|
||||
|
||||
private XmlDocument createXmlDocument(@NonNls final String text, @NonNls final String fileName) {
|
||||
final XmlDocument document = ((XmlFile)PsiFileFactory.getInstance(myProject).createFileFromText(fileName, text)).getDocument();
|
||||
private XmlDocument createXmlDocument(@NonNls final String text, @NonNls final String fileName, FileType fileType) {
|
||||
final XmlDocument document = ((XmlFile)PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, text)).getDocument();
|
||||
assert document != null;
|
||||
return document;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user