Search in sources :

Example 1 with PsiFileImpl

use of com.intellij.psi.impl.source.PsiFileImpl in project idea-handlebars by dmarcotte.

the class HbFileViewProvider method createFile.

@Override
protected PsiFile createFile(@NotNull Language lang) {
    ParserDefinition parserDefinition = getDefinition(lang);
    if (parserDefinition == null) {
        return null;
    }
    if (lang.is(getTemplateDataLanguage())) {
        PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
        file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
        return file;
    } else if (lang.isKindOf(getBaseLanguage())) {
        return parserDefinition.createFile(this);
    } else {
        return null;
    }
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Example 2 with PsiFileImpl

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

the class XmlEventsTest method testDocumentChange.

public void testDocumentChange() throws Exception {
    final String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_height=\"fill_parent\">\n" + "    <include layout=\"@layout/colorstrip\" />\n" + "\n" + "\n" + "    <LinearLayout\n" + "        android:id=\"@+id/noteArea\"\n" + "        android:layout_width=\"fill_parent\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:layout_weight=\"1\"\n" + "        android:layout_margin=\"5dip\">\n" + "    </LinearLayout>\n" + "\n" + "</LinearLayout>\n";
    PsiFile file = createFile("file.xml", xml);
    assertTrue(file instanceof XmlFile);
    XmlDocument xmlDocument = ((XmlFile) file).getDocument();
    assertNotNull(xmlDocument);
    final XmlTag tagFromText = xmlDocument.getRootTag();
    assertNotNull(tagFromText);
    final PsiFileImpl containingFile = (PsiFileImpl) tagFromText.getContainingFile();
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
    final Document document = documentManager.getDocument(containingFile);
    assertNotNull(document);
    final TestListener listener = new TestListener();
    PsiManager.getInstance(getProject()).addPsiTreeChangeListener(listener);
    CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
        int positionToInsert = xml.indexOf(" <LinearLayout\n" + "        android:id=\"@+id/noteArea\"\n");
        assertFalse(positionToInsert == -1);
        String stringToInsert = "<Button android:id=\"@+id/newid\" />\n";
        document.insertString(positionToInsert, stringToInsert);
        documentManager.commitDocument(document);
    }), "", null);
    PsiManager.getInstance(getProject()).removePsiTreeChangeListener(listener);
}
Also used : PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document)

Example 3 with PsiFileImpl

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

the class XmlEventsTest method checkEventsByDocumentChange.

private void checkEventsByDocumentChange(final String rootTagText, final int positionToInsert, final String stringToInsert, String events) throws Exception {
    final Listener listener = addPomListener();
    final XmlTag tagFromText = ((XmlFile) createFile("file.xml", rootTagText)).getDocument().getRootTag();
    final PsiFileImpl containingFile = (PsiFileImpl) tagFromText.getContainingFile();
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
    final Document document = documentManager.getDocument(containingFile);
    WriteCommandAction.runWriteCommandAction(null, () -> {
        document.insertString(positionToInsert, stringToInsert);
        documentManager.commitDocument(document);
    });
    assertEquals(events, listener.getEventString());
}
Also used : PomModelListener(com.intellij.pom.event.PomModelListener) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document)

Example 4 with PsiFileImpl

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

the class PyMultiFileResolveTest method testKeywordArgument.

public void testKeywordArgument() {
    final PsiFile file = prepareFile();
    final PsiManager psiManager = myFixture.getPsiManager();
    final VirtualFile dir = myFixture.findFileInTempDir("a.py");
    final PsiFile psiFile = psiManager.findFile(dir);
    //noinspection ConstantConditions   we need to unstub a.py here
    ((PsiFileImpl) psiFile).calcTreeElement();
    final PsiElement element;
    try {
        element = doResolve(file);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertResolveResult(element, PyClass.class, "A");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Example 5 with PsiFileImpl

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

the class RestFileViewProvider method createFile.

@Override
protected PsiFile createFile(@NotNull final Language lang) {
    ParserDefinition def = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    if (def == null)
        return null;
    if (lang == getTemplateDataLanguage()) {
        PsiFileImpl file = (PsiFileImpl) def.createFile(this);
        file.setContentElementType(RestPythonElementTypes.PYTHON_BLOCK_DATA);
        return file;
    } else if (lang.getID().equals("DjangoTemplate")) {
        PsiFileImpl file = (PsiFileImpl) def.createFile(this);
        file.setContentElementType(RestPythonElementTypes.DJANGO_BLOCK_DATA);
        return file;
    } else if (lang == RestLanguage.INSTANCE) {
        return def.createFile(this);
    }
    return null;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Aggregations

PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)53 Document (com.intellij.openapi.editor.Document)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 NotNull (org.jetbrains.annotations.NotNull)8 PsiFile (com.intellij.psi.PsiFile)7 Language (com.intellij.lang.Language)6 Nullable (org.jetbrains.annotations.Nullable)6 FileType (com.intellij.openapi.fileTypes.FileType)5 StubTree (com.intellij.psi.stubs.StubTree)5 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)5 DocumentWindow (com.intellij.injected.editor.DocumentWindow)3 ASTNode (com.intellij.lang.ASTNode)3 ParserDefinition (com.intellij.lang.ParserDefinition)3 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)3 Project (com.intellij.openapi.project.Project)3 FileElement (com.intellij.psi.impl.source.tree.FileElement)3 StubElement (com.intellij.psi.stubs.StubElement)3 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 FileASTNode (com.intellij.lang.FileASTNode)2