Search in sources :

Example 1 with PsiFileFactoryImpl

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

the class PyElementGeneratorImpl method createDummyFile.

public PsiFile createDummyFile(LanguageLevel langLevel, String contents, boolean physical) {
    final PsiFileFactory factory = PsiFileFactory.getInstance(myProject);
    final String name = getDummyFileName();
    final LightVirtualFile virtualFile = new LightVirtualFile(name, PythonFileType.INSTANCE, contents);
    virtualFile.putUserData(LanguageLevel.KEY, langLevel);
    final PsiFile psiFile = ((PsiFileFactoryImpl) factory).trySetupPsiForFile(virtualFile, PythonLanguage.getInstance(), physical, true);
    assert psiFile != null;
    return psiFile;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PsiFile(com.intellij.psi.PsiFile)

Example 2 with PsiFileFactoryImpl

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

the class ParsingTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    initApplication();
    ComponentAdapter component = getApplication().getPicoContainer().getComponentAdapter(ProgressManager.class.getName());
    if (component == null) {
        getApplication().getPicoContainer().registerComponent(new AbstractComponentAdapter(ProgressManager.class.getName(), Object.class) {

            @Override
            public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException {
                return new ProgressManagerImpl();
            }

            @Override
            public void verify(PicoContainer container) throws PicoIntrospectionException {
            }
        });
    }
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    myProject = new MockProjectEx(getTestRootDisposable());
    myPsiManager = new MockPsiManager(myProject);
    myFileFactory = new PsiFileFactoryImpl(myPsiManager);
    MutablePicoContainer appContainer = getApplication().getPicoContainer();
    registerComponentInstance(appContainer, MessageBus.class, getApplication().getMessageBus());
    registerComponentInstance(appContainer, SchemeManagerFactory.class, new MockSchemeManagerFactory());
    final MockEditorFactory editorFactory = new MockEditorFactory();
    registerComponentInstance(appContainer, EditorFactory.class, editorFactory);
    registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(charSequence -> editorFactory.createDocument(charSequence), FileDocumentManagerImpl.HARD_REF_TO_DOCUMENT_KEY));
    registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
    registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
    registerApplicationService(DefaultASTFactory.class, new DefaultASTFactoryImpl());
    registerApplicationService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl());
    myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager)));
    myProject.registerService(PsiManager.class, myPsiManager);
    myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject));
    registerExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
    registerExtensionPoint(MetaLanguage.EP_NAME, MetaLanguage.class);
    for (ParserDefinition definition : myDefinitions) {
        addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
    }
    if (myDefinitions.length > 0) {
        configureFromParserDefinition(myDefinitions[0], myFileExt);
    }
    // That's for reparse routines
    final PomModelImpl pomModel = new PomModelImpl(myProject);
    myProject.registerService(PomModel.class, pomModel);
    new TreeAspect(pomModel);
}
Also used : CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) NonNls(org.jetbrains.annotations.NonNls) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) org.picocontainer(org.picocontainer) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) com.intellij.lang(com.intellij.lang) StartupManager(com.intellij.openapi.startup.StartupManager) PomModel(com.intellij.pom.PomModel) Disposer(com.intellij.openapi.util.Disposer) ReferenceProvidersRegistry(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry) FileUtil(com.intellij.openapi.util.io.FileUtil) TestCase(junit.framework.TestCase) DebugUtil(com.intellij.psi.impl.DebugUtil) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) FileTypeFactory(com.intellij.openapi.fileTypes.FileTypeFactory) SchemeManagerFactory(com.intellij.openapi.options.SchemeManagerFactory) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) Set(java.util.Set) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) TextRange(com.intellij.openapi.util.TextRange) FileDocumentManagerImpl(com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl) Disposable(com.intellij.openapi.Disposable) File(java.io.File) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) EditorFactory(com.intellij.openapi.editor.EditorFactory) com.intellij.mock(com.intellij.mock) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) TreeAspect(com.intellij.pom.tree.TreeAspect) MessageBus(com.intellij.util.messages.MessageBus) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) TreeAspect(com.intellij.pom.tree.TreeAspect) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl)

Example 3 with PsiFileFactoryImpl

use of com.intellij.psi.impl.PsiFileFactoryImpl in project intellij-plugins by JetBrains.

the class DartElementGenerator method createDummyFile.

public static PsiFile createDummyFile(Project myProject, String text) {
    final PsiFileFactory factory = PsiFileFactory.getInstance(myProject);
    final String name = "dummy." + DartFileType.INSTANCE.getDefaultExtension();
    final LightVirtualFile virtualFile = new LightVirtualFile(name, DartFileType.INSTANCE, text);
    final PsiFile psiFile = ((PsiFileFactoryImpl) factory).trySetupPsiForFile(virtualFile, DartLanguage.INSTANCE, false, true);
    assert psiFile != null;
    return psiFile;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PsiFile(com.intellij.psi.PsiFile)

Example 4 with PsiFileFactoryImpl

use of com.intellij.psi.impl.PsiFileFactoryImpl in project intellij by bazelbuild.

the class BuildElementGenerator method createDummyFile.

public PsiFile createDummyFile(String contents) {
    PsiFileFactory factory = PsiFileFactory.getInstance(project);
    LightVirtualFile virtualFile = new LightVirtualFile(DUMMY_FILENAME, BuildFileType.INSTANCE, contents);
    PsiFile psiFile = ((PsiFileFactoryImpl) factory).trySetupPsiForFile(virtualFile, BuildFileLanguage.INSTANCE, false, true);
    assert psiFile != null;
    return psiFile;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PsiFile(com.intellij.psi.PsiFile)

Example 5 with PsiFileFactoryImpl

use of com.intellij.psi.impl.PsiFileFactoryImpl in project kotlin by JetBrains.

the class KotlinTestUtils method createFile.

@NotNull
public static KtFile createFile(@NotNull @NonNls final String name, @NotNull String text, @NotNull Project project) {
    String shortName = name.substring(name.lastIndexOf('/') + 1);
    shortName = shortName.substring(shortName.lastIndexOf('\\') + 1);
    LightVirtualFile virtualFile = new LightVirtualFile(shortName, KotlinLanguage.INSTANCE, text) {

        @NotNull
        @Override
        public String getPath() {
            //TODO: patch LightVirtualFile
            return "/" + name;
        }
    };
    virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
    PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
    //noinspection ConstantConditions
    return (KtFile) factory.trySetupPsiForFile(virtualFile, KotlinLanguage.INSTANCE, true, false);
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)5 PsiFile (com.intellij.psi.PsiFile)4 PsiFileFactory (com.intellij.psi.PsiFileFactory)4 PsiBuilderFactoryImpl (com.intellij.lang.impl.PsiBuilderFactoryImpl)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 PomModelImpl (com.intellij.pom.core.impl.PomModelImpl)2 TreeAspect (com.intellij.pom.tree.TreeAspect)2 PsiCachedValuesFactory (com.intellij.psi.impl.PsiCachedValuesFactory)2 ReferenceProvidersRegistryImpl (com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl)2 CachedValuesManagerImpl (com.intellij.util.CachedValuesManagerImpl)2 CoreASTFactory (com.intellij.core.CoreASTFactory)1 StartupManagerImpl (com.intellij.ide.startup.impl.StartupManagerImpl)1 com.intellij.lang (com.intellij.lang)1 com.intellij.mock (com.intellij.mock)1 MockFileDocumentManagerImpl (com.intellij.mock.MockFileDocumentManagerImpl)1 Disposable (com.intellij.openapi.Disposable)1 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 ExtensionPointName (com.intellij.openapi.extensions.ExtensionPointName)1