Search in sources :

Example 31 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class CompletionAssertions method assertCommitSuccessful.

static void assertCommitSuccessful(Editor editor, PsiFile psiFile) {
    Document document = editor.getDocument();
    int docLength = document.getTextLength();
    int psiLength = psiFile.getTextLength();
    PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
    boolean committed = !manager.isUncommited(document);
    if (docLength == psiLength && committed) {
        return;
    }
    FileViewProvider viewProvider = psiFile.getViewProvider();
    String message = "unsuccessful commit:";
    message += "\nmatching=" + (psiFile == manager.getPsiFile(document));
    message += "\ninjectedEditor=" + (editor instanceof EditorWindow);
    message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile);
    message += "\ncommitted=" + committed;
    message += "\nfile=" + psiFile.getName();
    message += "\nfile class=" + psiFile.getClass();
    message += "\nfile.valid=" + psiFile.isValid();
    message += "\nfile.physical=" + psiFile.isPhysical();
    message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled();
    message += "\nlanguage=" + psiFile.getLanguage();
    message += "\ndoc.length=" + docLength;
    message += "\npsiFile.length=" + psiLength;
    String fileText = psiFile.getText();
    if (fileText != null) {
        message += "\npsiFile.text.length=" + fileText.length();
    }
    FileASTNode node = psiFile.getNode();
    if (node != null) {
        message += "\nnode.length=" + node.getTextLength();
        String nodeText = node.getText();
        if (nodeText != null) {
            message += "\nnode.text.length=" + nodeText.length();
        }
    }
    VirtualFile virtualFile = viewProvider.getVirtualFile();
    message += "\nvirtualFile=" + virtualFile;
    message += "\nvirtualFile.class=" + virtualFile.getClass();
    message += "\n" + DebugUtil.currentStackTrace();
    throw new LogEventException("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", fileText), createAstAttachment(psiFile, psiFile), new Attachment("docText.txt", document.getText()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileASTNode(com.intellij.lang.FileASTNode) FileViewProvider(com.intellij.psi.FileViewProvider) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document) LogEventException(com.intellij.diagnostic.LogEventException) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 32 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class Divider method divideInsideAndOutsideAllRoots.

public static void divideInsideAndOutsideAllRoots(@NotNull PsiFile file, @NotNull TextRange restrictRange, @NotNull TextRange priorityRange, @NotNull Condition<PsiFile> rootFilter, @NotNull Processor<DividedElements> processor) {
    final FileViewProvider viewProvider = file.getViewProvider();
    for (Language language : viewProvider.getLanguages()) {
        final PsiFile root = viewProvider.getPsi(language);
        if (!rootFilter.value(root)) {
            continue;
        }
        divideInsideAndOutsideInOneRoot(root, restrictRange, priorityRange, processor);
    }
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile)

Example 33 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class InspectionProfileEntry method getSuppressors.

@NotNull
public static Set<InspectionSuppressor> getSuppressors(@NotNull PsiElement element) {
    FileViewProvider viewProvider = element.getContainingFile().getViewProvider();
    final InspectionSuppressor elementLanguageSuppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(element.getLanguage());
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
        Set<InspectionSuppressor> suppressors = new LinkedHashSet<>();
        ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(viewProvider.getBaseLanguage()));
        for (Language language : viewProvider.getLanguages()) {
            ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(language));
        }
        ContainerUtil.addIfNotNull(suppressors, elementLanguageSuppressor);
        return suppressors;
    }
    if (!element.getLanguage().isKindOf(viewProvider.getBaseLanguage())) {
        // handling embedding elements {@link EmbeddingElementType
        Set<InspectionSuppressor> suppressors = new LinkedHashSet<>();
        ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(viewProvider.getBaseLanguage()));
        ContainerUtil.addIfNotNull(suppressors, elementLanguageSuppressor);
        return suppressors;
    }
    return elementLanguageSuppressor != null ? Collections.singleton(elementLanguageSuppressor) : Collections.emptySet();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class DefaultHighlightVisitor method createErrorElementInfo.

private static HighlightInfo createErrorElementInfo(@NotNull PsiErrorElement element) {
    TextRange range = element.getTextRange();
    String errorDescription = element.getErrorDescription();
    if (!range.isEmpty()) {
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range);
        if (errorDescription != null) {
            builder.descriptionAndTooltip(errorDescription);
        }
        final HighlightInfo info = builder.create();
        if (info != null) {
            for (ErrorQuickFixProvider provider : Extensions.getExtensions(ErrorQuickFixProvider.EP_NAME)) {
                provider.registerErrorQuickFix(element, info);
            }
        }
        return info;
    }
    int offset = range.getStartOffset();
    PsiFile containingFile = element.getContainingFile();
    int fileLength = containingFile.getTextLength();
    FileViewProvider viewProvider = containingFile.getViewProvider();
    PsiElement elementAtOffset = viewProvider.findElementAt(offset, LanguageUtil.getRootLanguage(element));
    String text = elementAtOffset == null ? null : elementAtOffset.getText();
    HighlightInfo info;
    if (offset < fileLength && text != null && !StringUtil.startsWithChar(text, '\n') && !StringUtil.startsWithChar(text, '\r')) {
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(offset, offset + 1);
        if (errorDescription != null) {
            builder.descriptionAndTooltip(errorDescription);
        }
        info = builder.create();
    } else {
        int start;
        int end;
        if (offset > 0) {
            start = offset;
            end = offset;
        } else {
            start = offset;
            end = offset < fileLength ? offset + 1 : offset;
        }
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element, start, end);
        if (errorDescription != null) {
            builder.descriptionAndTooltip(errorDescription);
        }
        builder.endOfLine();
        info = builder.create();
    }
    return info;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) TextRange(com.intellij.openapi.util.TextRange) PsiFile(com.intellij.psi.PsiFile) ErrorQuickFixProvider(com.intellij.codeInsight.daemon.impl.analysis.ErrorQuickFixProvider) PsiElement(com.intellij.psi.PsiElement)

Example 35 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class ChangeTemplateDataLanguageAction method update.

@Override
public void update(final AnActionEvent e) {
    e.getPresentation().setVisible(false);
    VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (files != null && files.length > 1) {
        virtualFile = null;
    }
    if (virtualFile == null || virtualFile.isDirectory())
        return;
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null)
        return;
    final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(virtualFile);
    if (provider instanceof ConfigurableTemplateLanguageFileViewProvider) {
        final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider) provider;
        e.getPresentation().setText(LangBundle.message("quickfix.change.template.data.language.text", viewProvider.getTemplateDataLanguage().getDisplayName()));
        e.getPresentation().setEnabled(true);
        e.getPresentation().setVisible(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileViewProvider(com.intellij.psi.FileViewProvider)

Aggregations

FileViewProvider (com.intellij.psi.FileViewProvider)41 PsiFile (com.intellij.psi.PsiFile)22 Language (com.intellij.lang.Language)21 PsiElement (com.intellij.psi.PsiElement)15 NotNull (org.jetbrains.annotations.NotNull)12 TextRange (com.intellij.openapi.util.TextRange)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)5 Project (com.intellij.openapi.project.Project)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 Pair (com.intellij.openapi.util.Pair)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingLevelManager (com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager)2 FileASTNode (com.intellij.lang.FileASTNode)2 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)2 FileType (com.intellij.openapi.fileTypes.FileType)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)2