Search in sources :

Example 1 with DummyHolder

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

the class DtdParsing method parse.

public ASTNode parse() {
    final PsiBuilder.Marker root = myBuilder.mark();
    if (myRootType == XML_MARKUP_DECL) {
        parseTopLevelMarkupDecl();
        root.done(myRootType);
        return myBuilder.getTreeBuilt();
    }
    PsiBuilder.Marker document = null;
    if (myRootType == DTD_FILE) {
        document = myBuilder.mark();
        parseProlog();
    }
    switch(myContextType) {
        case GENERIC_XML:
            parseGenericXml();
            break;
        case ELEMENT_CONTENT_SPEC:
            doParseContentSpec(true);
            break;
        case ATTLIST_SPEC:
            parseAttlistContent();
            break;
        case ATTR_VALUE:
            parseAttrValue();
        case ATTRIBUTE_SPEC:
            parseAttributeContentSpec();
            break;
        case ENTITY_DECL_CONTENT:
            parseEntityDeclContent();
            break;
        case ENUMERATED_TYPE:
            parseEnumeratedTypeContent();
            break;
    }
    while (!myBuilder.eof()) myBuilder.advanceLexer();
    if (document != null)
        document.done(XML_DOCUMENT);
    root.done(myRootType);
    ASTNode astNode = myBuilder.getTreeBuilt();
    if (myRootType != DTD_FILE) {
        PsiFile file = myBuilder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
        if (file != null) {
            final DummyHolder result = DummyHolderFactory.createHolder(file.getManager(), DTDLanguage.INSTANCE, file);
            final FileElement holder = result.getTreeElement();
            holder.rawAddChildren((TreeElement) astNode);
        }
    }
    return astNode;
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) ASTNode(com.intellij.lang.ASTNode) FileElement(com.intellij.psi.impl.source.tree.FileElement) PsiFile(com.intellij.psi.PsiFile) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 2 with DummyHolder

use of com.intellij.psi.impl.source.DummyHolder 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 3 with DummyHolder

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

the class BlockSupportImpl method makeFullParse.

@NotNull
private static DiffLog makeFullParse(@NotNull PsiFileImpl fileImpl, @NotNull FileASTNode oldFileNode, @NotNull CharSequence newFileText, @NotNull ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) {
    if (fileImpl instanceof PsiCodeFragment) {
        FileElement parent = fileImpl.getTreeElement();
        final FileElement holderElement = new DummyHolder(fileImpl.getManager(), fileImpl.getContext()).getTreeElement();
        holderElement.rawAddChildren(fileImpl.createContentLeafElement(holderElement.getCharTable().intern(newFileText, 0, newFileText.length())));
        DiffLog diffLog = new DiffLog();
        diffLog.appendReplaceFileElement(parent, (FileElement) holderElement.getFirstChildNode());
        return diffLog;
    } else {
        FileViewProvider viewProvider = fileImpl.getViewProvider();
        viewProvider.getLanguages();
        FileType fileType = viewProvider.getVirtualFile().getFileType();
        String fileName = fileImpl.getName();
        final LightVirtualFile lightFile = new LightVirtualFile(fileName, fileType, newFileText, viewProvider.getVirtualFile().getCharset(), fileImpl.getViewProvider().getModificationStamp());
        lightFile.setOriginalFile(viewProvider.getVirtualFile());
        FileViewProvider copy = viewProvider.createCopy(lightFile);
        if (copy.isEventSystemEnabled()) {
            throw new AssertionError("Copied view provider must be non-physical for reparse to deliver correct events: " + viewProvider);
        }
        copy.getLanguages();
        // optimization: do not convert file contents to bytes to determine if we should codeinsight it
        SingleRootFileViewProvider.doNotCheckFileSizeLimit(lightFile);
        PsiFileImpl newFile = getFileCopy(fileImpl, copy);
        newFile.setOriginalFile(fileImpl);
        final FileElement newFileElement = (FileElement) newFile.getNode();
        final FileElement oldFileElement = (FileElement) oldFileNode;
        if (!lastCommittedText.toString().equals(oldFileElement.getText())) {
            throw new IncorrectOperationException(viewProvider.toString());
        }
        DiffLog diffLog = mergeTrees(fileImpl, oldFileElement, newFileElement, indicator, lastCommittedText);
        ((PsiManagerEx) fileImpl.getManager()).getFileManager().setViewProvider(lightFile, null);
        return diffLog;
    }
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) FileType(com.intellij.openapi.fileTypes.FileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DummyHolder

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

the class Factory method createSingleLeafElement.

@NotNull
public static LeafElement createSingleLeafElement(@NotNull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, PsiFile originalFile) {
    DummyHolder dummyHolder = DummyHolderFactory.createHolder(manager, table, type.getLanguage());
    dummyHolder.setOriginalFile(originalFile);
    FileElement holderElement = dummyHolder.getTreeElement();
    LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(buffer, startOffset, endOffset));
    holderElement.rawAddChildren(newElement);
    CodeEditUtil.setNodeGenerated(newElement, true);
    return newElement;
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with DummyHolder

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

the class PsiJavaParserFacadeImpl method createMethodFromText.

@NotNull
@Override
public PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
    final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context);
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
    if (!(element instanceof PsiMethod)) {
        throw newException("Incorrect method '" + text + "'", holder);
    }
    return (PsiMethod) element;
}
Also used : JavaDummyElement(com.intellij.psi.impl.source.JavaDummyElement) DummyHolder(com.intellij.psi.impl.source.DummyHolder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DummyHolder (com.intellij.psi.impl.source.DummyHolder)23 IncorrectOperationException (com.intellij.util.IncorrectOperationException)15 NotNull (org.jetbrains.annotations.NotNull)15 JavaDummyElement (com.intellij.psi.impl.source.JavaDummyElement)14 FileElement (com.intellij.psi.impl.source.tree.FileElement)3 ASTNode (com.intellij.lang.ASTNode)2 Project (com.intellij.openapi.project.Project)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 CharTable (com.intellij.util.CharTable)2 Nullable (org.jetbrains.annotations.Nullable)2 FileASTNode (com.intellij.lang.FileASTNode)1 Language (com.intellij.lang.Language)1 PsiBuilder (com.intellij.lang.PsiBuilder)1 Lexer (com.intellij.lexer.Lexer)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 Document (com.intellij.openapi.editor.Document)1 FileType (com.intellij.openapi.fileTypes.FileType)1 PlainTextLanguage (com.intellij.openapi.fileTypes.PlainTextLanguage)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1