diff --git a/platform/core-api/src/com/intellij/psi/PsiFileFactory.java b/platform/core-api/src/com/intellij/psi/PsiFileFactory.java index 67ae990016d1..9ca7aac37892 100644 --- a/platform/core-api/src/com/intellij/psi/PsiFileFactory.java +++ b/platform/core-api/src/com/intellij/psi/PsiFileFactory.java @@ -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); diff --git a/xml/impl/src/com/intellij/psi/XmlElementFactoryImpl.java b/xml/impl/src/com/intellij/psi/XmlElementFactoryImpl.java index 0c524e199067..851d23c37cfb 100644 --- a/xml/impl/src/com/intellij/psi/XmlElementFactoryImpl.java +++ b/xml/impl/src/com/intellij/psi/XmlElementFactoryImpl.java @@ -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("", "dummy.xml"); + final XmlDocument document = createXmlDocument("", "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; }