Search in sources :

Example 11 with FileElement

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

the class SingleRootFileViewProvider method getKnownTreeRoots.

@NotNull
public List<FileElement> getKnownTreeRoots() {
    PsiFile psiFile = getCachedPsi(myBaseLanguage);
    if (!(psiFile instanceof PsiFileImpl))
        return Collections.emptyList();
    FileElement element = ((PsiFileImpl) psiFile).getTreeElement();
    return ContainerUtil.createMaybeSingletonList(element);
}
Also used : PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) FileElement(com.intellij.psi.impl.source.tree.FileElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FileElement

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

the class SingleRootFileViewProvider method checkLengthConsistency.

private void checkLengthConsistency() {
    Document document = getCachedDocument();
    if (document instanceof DocumentWindow) {
        return;
    }
    if (document != null && ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(myManager.getProject())).getSynchronizer().isInSynchronization(document)) {
        return;
    }
    List<FileElement> knownTreeRoots = getKnownTreeRoots();
    if (knownTreeRoots.isEmpty())
        return;
    int fileLength = myContent.getTextLength();
    for (FileElement fileElement : knownTreeRoots) {
        int nodeLength = fileElement.getTextLength();
        if (nodeLength != fileLength) {
            PsiUtilCore.ensureValid(fileElement.getPsi());
            List<Attachment> attachments = ContainerUtil.newArrayList(new Attachment(myVirtualFile.getNameWithoutExtension() + ".tree.txt", fileElement.getText()), new Attachment(myVirtualFile.getNameWithoutExtension() + ".file.txt", myContent.toString()));
            if (document != null) {
                attachments.add(new Attachment(myVirtualFile.getNameWithoutExtension() + ".document.txt", document.getText()));
            }
            // exceptions here should be assigned to peter
            LOG.error("Inconsistent " + fileElement.getElementType() + " tree in " + this + "; nodeLength=" + nodeLength + "; fileLength=" + fileLength, attachments.toArray(Attachment.EMPTY_ARRAY));
        }
    }
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) FileElement(com.intellij.psi.impl.source.tree.FileElement) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document)

Example 13 with FileElement

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

the class CodeInsightTestFixtureImpl method collectAndCheckHighlighting.

private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingData data) {
    final Project project = getProject();
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    PsiFileImpl file = (PsiFileImpl) getHostFile();
    //to load text
    FileElement hardRefToFileElement = file.calcTreeElement();
    //to initialize caches
    if (!DumbService.isDumb(project)) {
        CacheManager.SERVICE.getInstance(project).getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(project), true);
    }
    final long start = System.currentTimeMillis();
    final VirtualFileFilter fileTreeAccessFilter = myVirtualFileFilter;
    Disposable disposable = Disposer.newDisposable();
    if (fileTreeAccessFilter != null) {
        PsiManagerEx.getInstanceEx(project).setAssertOnFileLoadingFilter(fileTreeAccessFilter, disposable);
    }
    //    ProfilingUtil.startCPUProfiling();
    List<HighlightInfo> infos;
    try {
        infos = doHighlighting();
        removeDuplicatedRangesForInjected(infos);
    } finally {
        Disposer.dispose(disposable);
    }
    //    ProfilingUtil.captureCPUSnapshot("testing");
    final long elapsed = System.currentTimeMillis() - start;
    data.checkResult(infos, file.getText());
    if (data.hasLineMarkers()) {
        Document document = getDocument(getFile());
        data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(document, getProject()), document.getText());
    }
    //noinspection ResultOfMethodCallIgnored
    // use it so gc won't collect it
    hardRefToFileElement.hashCode();
    return elapsed;
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) FileElement(com.intellij.psi.impl.source.tree.FileElement)

Example 14 with FileElement

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

the class GroovyCodeFragment method clone.

@Override
protected GroovyCodeFragment clone() {
    final GroovyCodeFragment clone = (GroovyCodeFragment) cloneImpl((FileElement) calcTreeElement().clone());
    clone.myOriginalFile = this;
    clone.myPseudoImports.putAll(myPseudoImports);
    FileManager fileManager = ((PsiManagerEx) getManager()).getFileManager();
    SingleRootFileViewProvider cloneViewProvider = (SingleRootFileViewProvider) fileManager.createFileViewProvider(new LightVirtualFile(getName(), getLanguage(), getText()), false);
    cloneViewProvider.forceCachedPsi(clone);
    clone.myViewProvider = cloneViewProvider;
    return clone;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 15 with FileElement

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

the class PsiCodeFragmentImpl method clone.

@Override
protected PsiCodeFragmentImpl clone() {
    final PsiCodeFragmentImpl clone = (PsiCodeFragmentImpl) cloneImpl((FileElement) calcTreeElement().clone());
    clone.myPhysical = false;
    clone.myOriginalFile = this;
    clone.myPseudoImports = new LinkedHashMap<>(myPseudoImports);
    FileManager fileManager = ((PsiManagerEx) getManager()).getFileManager();
    SingleRootFileViewProvider cloneViewProvider = (SingleRootFileViewProvider) fileManager.createFileViewProvider(new LightVirtualFile(getName(), getLanguage(), getText()), false);
    cloneViewProvider.forceCachedPsi(clone);
    clone.myViewProvider = cloneViewProvider;
    return clone;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Aggregations

FileElement (com.intellij.psi.impl.source.tree.FileElement)33 NotNull (org.jetbrains.annotations.NotNull)10 ASTNode (com.intellij.lang.ASTNode)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)6 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)5 FileManager (com.intellij.psi.impl.file.impl.FileManager)5 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)4 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)3 Nullable (org.jetbrains.annotations.Nullable)3 Lexer (com.intellij.lexer.Lexer)2 Disposable (com.intellij.openapi.Disposable)2 Document (com.intellij.openapi.editor.Document)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PomModel (com.intellij.pom.PomModel)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 GeneratedMarkerVisitor (com.intellij.psi.impl.GeneratedMarkerVisitor)2 DummyHolder (com.intellij.psi.impl.source.DummyHolder)2 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)2