Search in sources :

Example 1 with PsiPlainTextFileImpl

use of com.intellij.psi.impl.source.PsiPlainTextFileImpl in project intellij-community by JetBrains.

the class PsiFileFactoryImpl method createFileFromText.

@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name, @NotNull FileType fileType, @NotNull CharSequence text, long modificationStamp, final boolean eventSystemEnabled, boolean markAsCopy) {
    final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
    if (fileType instanceof LanguageFileType) {
        final Language language = LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType) fileType).getLanguage(), virtualFile, myManager.getProject());
        final PsiFile file = trySetupPsiForFile(virtualFile, language, eventSystemEnabled, markAsCopy);
        if (file != null)
            return file;
    }
    final SingleRootFileViewProvider singleRootFileViewProvider = new SingleRootFileViewProvider(myManager, virtualFile, eventSystemEnabled);
    final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
    if (markAsCopy)
        CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
    return plainTextFile;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiPlainTextFileImpl(com.intellij.psi.impl.source.PsiPlainTextFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiPlainTextFileImpl

use of com.intellij.psi.impl.source.PsiPlainTextFileImpl in project intellij-community by JetBrains.

the class PsiFileFactoryImpl method createFileFromText.

@NotNull
public PsiFile createFileFromText(@NotNull String name, @NotNull FileType fileType, final Language language, @NotNull Language targetLanguage, @NotNull CharSequence text, long modificationStamp, final boolean physical, boolean markAsCopy) {
    final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    final FileViewProviderFactory factory = LanguageFileViewProviders.INSTANCE.forLanguage(language);
    FileViewProvider viewProvider = factory != null ? factory.createFileViewProvider(virtualFile, language, myManager, physical) : null;
    if (viewProvider == null)
        viewProvider = new SingleRootFileViewProvider(myManager, virtualFile, physical);
    if (parserDefinition != null) {
        final PsiFile psiFile = viewProvider.getPsi(targetLanguage);
        if (psiFile != null) {
            if (markAsCopy) {
                markGenerated(psiFile);
            }
            return psiFile;
        }
    }
    final SingleRootFileViewProvider singleRootFileViewProvider = new SingleRootFileViewProvider(myManager, virtualFile, physical);
    final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
    if (markAsCopy)
        CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
    return plainTextFile;
}
Also used : PsiPlainTextFileImpl(com.intellij.psi.impl.source.PsiPlainTextFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiPlainTextFileImpl (com.intellij.psi.impl.source.PsiPlainTextFileImpl)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1