Search in sources :

Example 11 with PsiFileImpl

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

the class TemplateDataElementType method parseContents.

@Override
public ASTNode parseContents(ASTNode chameleon) {
    final CharTable charTable = SharedImplUtil.findCharTableByTree(chameleon);
    final FileElement fileElement = TreeUtil.getFileElement((TreeElement) chameleon);
    final PsiFile psiFile = (PsiFile) fileElement.getPsi();
    PsiFile originalPsiFile = psiFile.getOriginalFile();
    final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider) originalPsiFile.getViewProvider();
    final Language templateLanguage = getTemplateFileLanguage(viewProvider);
    final CharSequence sourceCode = chameleon.getChars();
    RangesCollector collector = new RangesCollector();
    final PsiFile templatePsiFile = createTemplateFile(psiFile, templateLanguage, sourceCode, viewProvider, collector);
    final FileElement templateFileElement = ((PsiFileImpl) templatePsiFile).calcTreeElement();
    DebugUtil.startPsiModification("template language parsing");
    try {
        prepareParsedTemplateFile(templateFileElement);
        insertOuters(templateFileElement, sourceCode, collector.myRanges, charTable);
        TreeElement childNode = templateFileElement.getFirstChildNode();
        DebugUtil.checkTreeStructure(templateFileElement);
        DebugUtil.checkTreeStructure(chameleon);
        if (fileElement != chameleon) {
            DebugUtil.checkTreeStructure(psiFile.getNode());
            DebugUtil.checkTreeStructure(originalPsiFile.getNode());
        }
        return childNode;
    } finally {
        DebugUtil.finishPsiModification();
    }
}
Also used : Language(com.intellij.lang.Language) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) PsiFile(com.intellij.psi.PsiFile) CharTable(com.intellij.util.CharTable)

Example 12 with PsiFileImpl

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

the class PomModelImpl method startTransaction.

private void startTransaction(@NotNull PomTransaction transaction) {
    final ProgressIndicator progressIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    if (progressIndicator != null)
        progressIndicator.startNonCancelableSection();
    final PsiDocumentManagerBase manager = (PsiDocumentManagerBase) PsiDocumentManager.getInstance(myProject);
    final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer();
    final PsiElement changeScope = transaction.getChangeScope();
    final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
    if (containingFileByTree != null && !(containingFileByTree instanceof DummyHolder) && !manager.isCommitInProgress()) {
        PsiUtilCore.ensureValid(containingFileByTree);
    }
    boolean physical = changeScope.isPhysical();
    if (physical && synchronizer.toProcessPsiEvent()) {
        // so it's important to throw something outside event processing
        if (isDocumentUncommitted(containingFileByTree)) {
            throw new IllegalStateException("Attempt to modify PSI for non-committed Document!");
        }
        CommandProcessor commandProcessor = CommandProcessor.getInstance();
        if (!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null) {
            throw new IncorrectOperationException("Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor");
        }
    }
    if (containingFileByTree != null) {
        ((SmartPointerManagerImpl) SmartPointerManager.getInstance(myProject)).fastenBelts(containingFileByTree.getViewProvider().getVirtualFile());
        if (containingFileByTree instanceof PsiFileImpl) {
            ((PsiFileImpl) containingFileByTree).beforeAstChange();
        }
    }
    BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl) PsiManager.getInstance(myProject), changeScope, true);
    Document document = containingFileByTree == null ? null : physical ? manager.getDocument(containingFileByTree) : manager.getCachedDocument(containingFileByTree);
    if (document != null) {
        synchronizer.startTransaction(myProject, document, changeScope);
    }
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CommandProcessor(com.intellij.openapi.command.CommandProcessor) IncorrectOperationException(com.intellij.util.IncorrectOperationException) SmartPointerManagerImpl(com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl)

Example 13 with PsiFileImpl

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

the class StubBasedPsiElementBase method getNode.

/**
   * Ensures this element is AST-based. This is an expensive operation that might take significant time and allocate lots of objects,
   * so it should be to be avoided if possible.
   *
   * @return an AST node corresponding to this element. If the element is currently operating via stubs,
   * this causes AST to be loaded for the whole file and all stub-based PSI elements in this file (including the current one)
   * to be switched from stub to AST. So, after this call {@link #getStub()} will return null.
   */
@Override
@NotNull
public ASTNode getNode() {
    if (mySubstrateRef instanceof SubstrateRef.StubRef) {
        ApplicationManager.getApplication().assertReadAccessAllowed();
        PsiFileImpl file = (PsiFileImpl) getContainingFile();
        if (!file.isValid())
            throw new PsiInvalidElementAccessException(this);
        FileElement treeElement = file.getTreeElement();
        if (treeElement != null && mySubstrateRef instanceof SubstrateRef.StubRef) {
            return notBoundInExistingAst(file, treeElement);
        }
        treeElement = file.calcTreeElement();
        if (mySubstrateRef instanceof SubstrateRef.StubRef) {
            return failedToBindStubToAst(file, treeElement);
        }
    }
    return mySubstrateRef.getNode();
}
Also used : PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) SubstrateRef(com.intellij.psi.impl.source.SubstrateRef) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) FileElement(com.intellij.psi.impl.source.tree.FileElement) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with PsiFileImpl

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

the class SmartPsiElementPointersTest method testCreatePointerDoesNotLoadPsiTree.

public void testCreatePointerDoesNotLoadPsiTree() throws IOException {
    VirtualFile vfile = createChildData(myRoot, "X.java");
    setFileText(vfile, "public class X { public int X; }");
    PsiClass aClass = myJavaFacade.findClass("X", GlobalSearchScope.allScope(getProject()));
    assertNotNull(aClass);
    assertTrue(aClass.isValid());
    PsiFileImpl file = (PsiFileImpl) aClass.getContainingFile();
    assertTreeLoaded(file, false);
    SmartPsiElementPointer p = createPointer(aClass);
    assertNotNull(p);
    assertTreeLoaded(file, false);
    assertInstanceOf(p.getElement(), PsiClass.class);
    assertTreeLoaded(file, false);
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
    Document document = documentManager.getDocument(file);
    insertString(document, 0, "/** asdasd */");
    documentManager.commitAllDocuments();
    // loaded tree
    assertTreeLoaded(file, true);
    assertInstanceOf(p.getElement(), PsiClass.class);
    assertTreeLoaded(file, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document)

Example 15 with PsiFileImpl

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

the class LightStubBuilder method buildStubTree.

@Override
public StubElement buildStubTree(@NotNull PsiFile file) {
    LighterAST tree = FORCED_AST.get();
    if (tree == null) {
        FileType fileType = file.getFileType();
        if (!(fileType instanceof LanguageFileType)) {
            LOG.error("File is not of LanguageFileType: " + fileType + ", " + file);
            return null;
        }
        assert file instanceof PsiFileImpl;
        final IFileElementType contentType = ((PsiFileImpl) file).getElementTypeForStubBuilder();
        if (contentType == null) {
            LOG.error("File is not of IStubFileElementType: " + file);
            return null;
        }
        final FileASTNode node = file.getNode();
        if (node.getElementType() instanceof ILightStubFileElementType) {
            tree = node.getLighterAST();
        } else {
            tree = new TreeBackedLighterAST(node);
        }
    } else {
        FORCED_AST.set(null);
    }
    if (tree == null)
        return null;
    final StubElement rootStub = createStubForFile(file, tree);
    buildStubTree(tree, tree.getRoot(), rootStub);
    return rootStub;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) 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) ILightStubFileElementType(com.intellij.psi.tree.ILightStubFileElementType)

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