Search in sources :

Example 36 with PsiFileImpl

use of com.intellij.psi.impl.source.PsiFileImpl in project smali by JesusFreke.

the class LightCodeInsightParsingTestCase method doTest.

protected void doTest(boolean checkResult) {
    String name = getTestName(false);
    try {
        String text = loadFile(name + "." + myFileExt);
        PsiFile f = createPsiFile(name, text);
        if (f instanceof PsiFileImpl) {
            // Also want to test stub serialization/deserialization
            StubTree stubTree = ((PsiFileImpl) f).calcStubTree();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            SerializationManagerImpl.getInstanceEx().serialize(stubTree.getRoot(), baos);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            SerializationManagerImpl.getInstanceEx().deserialize(bais);
        }
        ensureParsed(f);
        assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) f.getVirtualFile()).getContent().toString());
        assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(f.getVirtualFile()));
        assertEquals("doc text mismatch", text, f.getViewProvider().getDocument().getText());
        assertEquals("psi text mismatch", text, f.getText());
        if (checkResult) {
            checkResult(name, f);
        } else {
            toParseTreeText(f, skipSpaces(), includeRanges());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (SerializerNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : StubTree(com.intellij.psi.stubs.StubTree) ByteArrayInputStream(java.io.ByteArrayInputStream) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SerializerNotFoundException(com.intellij.psi.stubs.SerializerNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 37 with PsiFileImpl

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

the class PsiFileGistImpl method getPsiFile.

private static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
    PsiFile psi = PsiManager.getInstance(project).findFile(file);
    if (psi == null || !(psi instanceof PsiFileImpl) || ((PsiFileImpl) psi).isContentsLoaded()) {
        return psi;
    }
    FileType fileType = file.getFileType();
    if (!(fileType instanceof LanguageFileType))
        return null;
    return FileContentImpl.createFileFromText(project, psi.getViewProvider().getContents(), (LanguageFileType) fileType, file, file.getName());
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) PsiFile(com.intellij.psi.PsiFile)

Example 38 with PsiFileImpl

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

the class SrcRepositoryUseTest method testCopyableUserDataChild.

public void testCopyableUserDataChild() throws Exception {
    final PsiClass aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
    assertNotNull(aClass);
    final PsiFile containingFile = aClass.getContainingFile();
    final CompositeElement element = ((PsiFileImpl) containingFile).calcTreeElement();
    aClass.putCopyableUserData(TEST_KEY, "TEST");
    final PsiJavaFile fileCopy = (PsiJavaFile) containingFile.copy();
    final PsiClass[] classesCopy = fileCopy.getClasses();
    assertEquals(1, classesCopy.length);
    assertNotNull(element);
    assertEquals("TEST", classesCopy[0].getCopyableUserData(TEST_KEY));
}
Also used : PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 39 with PsiFileImpl

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

the class StubTreeBuilder method getStubbedRoots.

/** Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()} */
@NotNull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@NotNull FileViewProvider viewProvider) {
    final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>();
    final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
    for (Language language : viewProvider.getLanguages()) {
        final PsiFile file = viewProvider.getPsi(language);
        if (file instanceof PsiFileImpl) {
            final IElementType type = ((PsiFileImpl) file).getElementTypeForStubBuilder();
            if (type != null) {
                roots.add(Trinity.create(language, (IStubFileElementType) type, file));
            }
        }
    }
    ContainerUtil.sort(roots, (o1, o2) -> {
        if (o1.third == stubBindingRoot)
            return o2.third == stubBindingRoot ? 0 : -1;
        else if (o2.third == stubBindingRoot)
            return 1;
        else
            return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
    });
    return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Trinity(com.intellij.openapi.util.Trinity) Language(com.intellij.lang.Language) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with PsiFileImpl

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

the class BlockSupportImpl method reparseRange.

@Override
public void reparseRange(@NotNull PsiFile file, int startOffset, int endOffset, @NotNull CharSequence newText) throws IncorrectOperationException {
    LOG.assertTrue(file.isValid());
    final PsiFileImpl psiFile = (PsiFileImpl) file;
    final Document document = psiFile.getViewProvider().getDocument();
    assert document != null;
    document.replaceString(startOffset, endOffset, newText);
    PsiDocumentManager.getInstance(psiFile.getProject()).commitDocument(document);
}
Also used : PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document)

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