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()));
}
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);
}
}
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();
}
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;
}
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);
}
}
Aggregations