Search in sources :

Example 6 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.

the class LongLineInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final Project project = manager.getProject();
    final int codeStyleRightMargin = CodeStyleSettingsManager.getSettings(project).getRightMargin(file.getLanguage());
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile instanceof VirtualFileWindow) {
        return null;
    }
    final Document document = FileDocumentManager.getInstance().getDocument(vFile);
    if (document == null) {
        return null;
    }
    final List<ProblemDescriptor> descriptors = new SmartList<>();
    for (int idx = 0; idx < document.getLineCount(); idx++) {
        final int startOffset = document.getLineStartOffset(idx);
        final int endOffset = document.getLineEndOffset(idx);
        if (endOffset - startOffset > codeStyleRightMargin) {
            final int maxOffset = startOffset + codeStyleRightMargin;
            descriptors.add(manager.createProblemDescriptor(file, new TextRange(maxOffset, endOffset), String.format("Line is longer than allowed by code style (> %s columns)", codeStyleRightMargin), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
        }
    }
    return descriptors.isEmpty() ? null : descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) SmartList(com.intellij.util.SmartList) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.

the class InjectedFileViewProvider method clone.

@Override
public FileViewProvider clone() {
    final DocumentWindow oldDocumentWindow = ((VirtualFileWindow) getVirtualFile()).getDocumentWindow();
    Document hostDocument = oldDocumentWindow.getDelegate();
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getManager().getProject());
    PsiFile hostFile = documentManager.getPsiFile(hostDocument);
    Language language = getBaseLanguage();
    PsiFile file = getPsi(language);
    final Language hostFileLanguage = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file).getLanguage();
    PsiFile hostPsiFileCopy = (PsiFile) hostFile.copy();
    Segment firstTextRange = oldDocumentWindow.getHostRanges()[0];
    PsiElement hostElementCopy = hostPsiFileCopy.getViewProvider().findElementAt(firstTextRange.getStartOffset(), hostFileLanguage);
    assert hostElementCopy != null;
    final Ref<FileViewProvider> provider = new Ref<>();
    PsiLanguageInjectionHost.InjectedPsiVisitor visitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {

        @Override
        public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
            Document document = documentManager.getCachedDocument(injectedPsi);
            if (document instanceof DocumentWindowImpl && oldDocumentWindow.areRangesEqual((DocumentWindowImpl) document)) {
                provider.set(injectedPsi.getViewProvider());
            }
        }
    };
    for (PsiElement current = hostElementCopy; current != null && current != hostPsiFileCopy; current = current.getParent()) {
        current.putUserData(LANGUAGE_FOR_INJECTED_COPY_KEY, language);
        try {
            InjectedLanguageUtil.enumerate(current, hostPsiFileCopy, false, visitor);
        } finally {
            current.putUserData(LANGUAGE_FOR_INJECTED_COPY_KEY, null);
        }
        if (provider.get() != null)
            break;
    }
    return provider.get();
}
Also used : VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Segment(com.intellij.openapi.util.Segment) DocumentWindow(com.intellij.injected.editor.DocumentWindow) Ref(com.intellij.openapi.util.Ref) Language(com.intellij.lang.Language) FreeThreadedFileViewProvider(com.intellij.psi.impl.FreeThreadedFileViewProvider) DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) List(java.util.List)

Example 8 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.

the class InjectedLanguageManagerImpl method getInjectionHost.

@Override
public PsiLanguageInjectionHost getInjectionHost(@NotNull PsiElement element) {
    final PsiFile file = element.getContainingFile();
    final VirtualFile virtualFile = file == null ? null : file.getVirtualFile();
    if (virtualFile instanceof VirtualFileWindow) {
        // use utility method in case the file's overridden getContext()
        PsiElement host = FileContextUtil.getFileContext(file);
        if (host instanceof PsiLanguageInjectionHost) {
            return (PsiLanguageInjectionHost) host;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow)

Example 9 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.

the class PerFileConfigurableBase method selectFile.

public void selectFile(@NotNull VirtualFile virtualFile, boolean addIfMissing) {
    VirtualFile file = virtualFile instanceof VirtualFileWindow ? ((VirtualFileWindow) virtualFile).getDelegate() : virtualFile;
    int[] rows = findRow(file, addIfMissing, false);
    if (rows.length == 0 && addIfMissing) {
        doAddFiles(Collections.singletonList(virtualFile));
    } else {
        selectRows(rows, true);
    }
    myFileToSelect = file;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow)

Example 10 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-plugins by JetBrains.

the class IncrementalDocumentSynchronizer method styleChanged.

private void styleChanged() {
    // BE AWARE!!! INJECTION BEHAVIOR IS NOT PREDICTABLE, file may be injected.
    //noinspection ConstantConditions
    VirtualFile file = event.getFile().getViewProvider().getVirtualFile();
    if (file instanceof VirtualFileWindow) {
        file = ((VirtualFileWindow) file).getDelegate();
    }
    DesignerApplicationManager.getInstance().renderDocumentsAndCheckLocalStyleModification(new Document[] { FileDocumentManager.getInstance().getCachedDocument(file) }, true, false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow)

Aggregations

VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)7 NotNull (org.jetbrains.annotations.NotNull)5 DocumentWindow (com.intellij.injected.editor.DocumentWindow)4 Project (com.intellij.openapi.project.Project)4 Document (com.intellij.openapi.editor.Document)3 Module (com.intellij.openapi.module.Module)3 TextRange (com.intellij.openapi.util.TextRange)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Language (com.intellij.lang.Language)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 SmartList (com.intellij.util.SmartList)2 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 ASTNode (com.intellij.lang.ASTNode)1 Editor (com.intellij.openapi.editor.Editor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Pair (com.intellij.openapi.util.Pair)1